lib/sup/modes/thread-view-mode.rb in sup-0.12.1 vs lib/sup/modes/thread-view-mode.rb in sup-0.13.0

- old
+ new

@@ -144,13 +144,10 @@ @wrap = true @layout[latest].state = :open if @layout[latest].state == :closed @layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1 - - @thread.remove_label :unread - Index.save_thread @thread end def toggle_wrap @wrap = !@wrap regen_text @@ -266,25 +263,25 @@ def search p = @person_lines[curpos] or return mode = PersonSearchResultsMode.new [p] BufferManager.spawn "Search for #{p.name}", mode mode.load_threads :num => mode.buffer.content_height - end + end def compose p = @person_lines[curpos] if p ComposeMode.spawn_nicely :to_default => p else ComposeMode.spawn_nicely end - end + end def edit_labels old_labels = @thread.labels reserved_labels = old_labels.select { |l| LabelManager::RESERVED_LABELS.include? l } - new_labels = BufferManager.ask_for_labels :label, "Labels for thread: ", @thread.labels + new_labels = BufferManager.ask_for_labels :label, "Labels for thread: ", @thread.labels.sort_by {|x| x.to_s} return unless new_labels @thread.labels = Set.new(reserved_labels) + new_labels new_labels.each { |l| LabelManager << l } update @@ -505,11 +502,11 @@ def jump_to_prev_open m = (0 .. curpos).to_a.reverse.argfind { |i| @message_lines[i] } # bah, .to_a return unless m ## jump to the top of the current message if we're in the body; ## otherwise, to the previous message - + top = @layout[m].top if curpos == top while(prevm = @layout[m].prev) break if @layout[prevm].state != :closed m = prevm @@ -720,11 +717,11 @@ ## is this still necessary? next unless @layout[m].state # skip discarded drafts ## build the patina text = chunk_to_lines m, l.state, @text.length, depth, parent, l.color, l.star_color - + l.top = @text.length l.bot = @text.length + text.length # updated below l.prev = prevm l.next = nil l.depth = depth @@ -737,11 +734,11 @@ @message_lines[@text.length + i] = m lw = text[i].flatten.select { |x| x.is_a? String }.map { |x| x.display_length }.sum end @text += text - prevm = m + prevm = m if l.state != :closed m.chunks.each do |c| cl = @chunk_layout[c] ## set the default state for chunks @@ -780,17 +777,17 @@ case state when :open @person_lines[start] = m.from [[prefix_widget, open_widget, new_widget, attach_widget, starred_widget, - [color, + [color, "#{m.from ? m.from.mediumname : '?'} to #{m.recipients.map { |l| l.shortname }.join(', ')} #{m.date.to_nice_s} (#{m.date.to_nice_distance_s})"]]] when :closed @person_lines[start] = m.from [[prefix_widget, open_widget, new_widget, attach_widget, starred_widget, - [color, + [color, "#{m.from ? m.from.mediumname : '?'}, #{m.date.to_nice_s} (#{m.date.to_nice_distance_s}) #{m.snippet}"]]] when :detailed @person_lines[start] = m.from from_line = [[prefix_widget, open_widget, new_widget, attach_widget, starred_widget, @@ -821,28 +818,41 @@ if parent headers["In reply to"] = "#{parent.from.mediumname}'s message of #{parent.date.strftime DATE_FORMAT}" end HookManager.run "detailed-headers", :message => m, :headers => headers - + from_line + (addressee_lines + headers.map { |k, v| " #{k}: #{v}" }).map { |l| [[color, prefix + " " + l]] } end end def format_person_list prefix, people ptext = people.map { |p| format_person p } pad = " " * prefix.display_length - [prefix + ptext.first + (ptext.length > 1 ? "," : "")] + + [prefix + ptext.first + (ptext.length > 1 ? "," : "")] + ptext[1 .. -1].map_with_index do |e, i| pad + e + (i == ptext.length - 1 ? "" : ",") end end def format_person p p.longname + (ContactManager.is_aliased_contact?(p) ? " (#{ContactManager.alias_for p})" : "") end + def maybe_wrap_text lines + if @wrap + config_width = $config[:wrap_width] + if config_width and config_width != 0 + width = [config_width, buffer.content_width].min + else + width = buffer.content_width + end + lines = lines.map { |l| l.chomp.wrap width if l }.flatten + end + return lines + end + ## todo: check arguments on this overly complex function def chunk_to_lines chunk, state, start, depth, parent=nil, color=nil, star_color=nil prefix = " " * INDENT_SPACES * depth case chunk when :fake_root @@ -854,26 +864,18 @@ (chunk.is_draft? ? [[[:draft_notification_color, prefix + " >>> This message is a draft. Hit 'e' to edit, 'y' to send. <<<"]]] : []) else raise "Bad chunk: #{chunk.inspect}" unless chunk.respond_to?(:inlineable?) ## debugging if chunk.inlineable? - lines = chunk.lines - if @wrap - config_width = $config[:wrap_width] - if config_width and config_width != 0 - width = [config_width, buffer.content_width].min - else - width = buffer.content_width - end - lines = lines.map { |l| l.chomp.wrap width }.flatten - end + lines = maybe_wrap_text(chunk.lines) lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] } elsif chunk.expandable? case state when :closed [[[chunk.patina_color, "#{prefix}+ #{chunk.patina_text}"]]] when :open - [[[chunk.patina_color, "#{prefix}- #{chunk.patina_text}"]]] + chunk.lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] } + lines = maybe_wrap_text(chunk.lines) + [[[chunk.patina_color, "#{prefix}- #{chunk.patina_text}"]]] + lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] } end else [[[chunk.patina_color, "#{prefix}x #{chunk.patina_text}"]]] end end