lib/sup/modes/thread-view-mode.rb in sup-0.7 vs lib/sup/modes/thread-view-mode.rb in sup-0.8

- old
+ new

@@ -25,10 +25,11 @@ EOS register_keymap do |k| k.add :toggle_detailed_header, "Toggle detailed header", 'h' k.add :show_header, "Show full message header", 'H' + k.add :show_message, "Show full message (raw form)", 'V' k.add :activate_chunk, "Expand/collapse or activate item", :enter k.add :expand_all_messages, "Expand/collapse all messages", 'E' k.add :edit_draft, "Edit draft", 'e' k.add :send_draft, "Send draft", 'y' k.add :edit_labels, "Edit or add labels for a thread", 'l' @@ -132,10 +133,17 @@ BufferManager.spawn_unless_exists("Full header for #{m.id}") do TextMode.new m.raw_header end end + def show_message + m = @message_lines[curpos] or return + BufferManager.spawn_unless_exists("Raw message for #{m.id}") do + TextMode.new m.raw_message + end + end + def toggle_detailed_header m = @message_lines[curpos] or return @layout[m].state = (@layout[m].state == :detailed ? :open : :detailed) update end @@ -147,20 +155,20 @@ end def subscribe_to_list m = @message_lines[curpos] or return if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/ - ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3 + ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3 else BufferManager.flash "Can't find List-Subscribe header for this message." end end def unsubscribe_from_list m = @message_lines[curpos] or return if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/ - ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3 + ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3 else BufferManager.flash "Can't find List-Unsubscribe header for this message." end end @@ -232,23 +240,31 @@ ## a chunk. for expandable chunks (including messages) we toggle ## open/closed state; for viewable chunks (like attachments) we ## view. def activate_chunk chunk = @chunk_lines[curpos] or return - layout = - if chunk.is_a?(Message) - @layout[chunk] - elsif chunk.expandable? - @chunk_layout[chunk] - end + if chunk.is_a? Chunk::Text + ## if the cursor is over a text region, expand/collapse the + ## entire message + chunk = @message_lines[curpos] + end + layout = if chunk.is_a?(Message) + @layout[chunk] + elsif chunk.expandable? + @chunk_layout[chunk] + end if layout layout.state = (layout.state != :closed ? :closed : :open) #cursor_down if layout.state == :closed # too annoying update elsif chunk.viewable? view chunk end + if chunk.is_a?(Message) + jump_to_message chunk + jump_to_next_open if layout.state == :closed + end end def edit_as_new m = @message_lines[curpos] or return mode = ComposeMode.new(:body => m.quotable_body_lines, :to => m.to, :cc => m.cc, :subj => m.subj, :bcc => m.bcc, :refs => m.refs, :replytos => m.replytos) @@ -538,11 +554,11 @@ @layout[l.prev].next = m if l.prev (0 ... text.length).each do |i| @chunk_lines[@text.length + i] = m @message_lines[@text.length + i] = m - lw = text[i].flatten.select { |x| x.is_a? String }.map { |x| x.length }.sum + lw = text[i].flatten.select { |x| x.is_a? String }.map { |x| x.display_length }.sum end @text += text prevm = m if l.state != :closed @@ -559,11 +575,11 @@ text = chunk_to_lines c, cl.state, @text.length, depth (0 ... text.length).each do |i| @chunk_lines[@text.length + i] = c @message_lines[@text.length + i] = m - lw = text[i].flatten.select { |x| x.is_a? String }.map { |x| x.length }.sum - (depth * INDENT_SPACES) + lw = text[i].flatten.select { |x| x.is_a? String }.map { |x| x.display_length }.sum - (depth * INDENT_SPACES) l.width = lw if lw > l.width end @text += text end @layout[m].bot = @text.length @@ -633,10 +649,10 @@ end end def format_person_list prefix, people ptext = people.map { |p| format_person p } - pad = " " * prefix.length + pad = " " * prefix.display_length [prefix + ptext.first + (ptext.length > 1 ? "," : "")] + ptext[1 .. -1].map_with_index do |e, i| pad + e + (i == ptext.length - 1 ? "" : ",") end end