lib/sup/modes/thread-view-mode.rb in sup-0.0.7 vs lib/sup/modes/thread-view-mode.rb in sup-0.0.8

- old
+ new

@@ -1,11 +1,11 @@ module Redwood class ThreadViewMode < LineCursorMode ## this holds all info we need to lay out a message class Layout - attr_accessor :top, :bot, :prev, :next, :depth, :width, :state, :color + attr_accessor :top, :bot, :prev, :next, :depth, :width, :state, :color, :star_color, :orig_new end DATE_FORMAT = "%B %e %Y %l:%M%P" INDENT_SPACES = 2 # how many spaces to indent child messages @@ -24,10 +24,11 @@ k.add :forward, "Forward a message", 'f' k.add :alias, "Edit alias/nickname for a person", 'a' k.add :edit_as_new, "Edit message as new", 'D' k.add :save_to_disk, "Save message/attachment to disk", 's' k.add :search, "Search for messages from particular people", 'S' + k.add :compose, "Compose message to person", 'm' k.add :archive_and_kill, "Archive thread and kill buffer", 'A' end ## there are a couple important instance variables we hold to lay ## out the thread and to provide line-based functionality. @layout @@ -50,10 +51,12 @@ next unless m earliest ||= m @layout[m] = Layout.new @layout[m].state = initial_state_for m @layout[m].color = altcolor ? :alternate_patina_color : :message_patina_color + @layout[m].star_color = altcolor ? :alternate_starred_patina_color : :starred_patina_color + @layout[m].orig_new = m.has_label? :unread altcolor = !altcolor if latest_date.nil? || m.date > latest_date latest_date = m.date latest = m end @@ -109,14 +112,26 @@ end def search p = @person_lines[curpos] or return mode = PersonSearchResultsMode.new [p] - BufferManager.spawn "search for #{p.name}", mode + BufferManager.spawn "Search for #{p.name}", mode mode.load_threads :num => mode.buffer.content_height end + def compose + p = @person_lines[curpos] + mode = + if p + ComposeMode.new :to => [p] + else + ComposeMode.new + end + BufferManager.spawn "Compose message", mode + mode.edit + end + def toggle_starred m = @message_lines[curpos] or return if m.has_label? :starred m.remove_label :starred else @@ -229,11 +244,11 @@ @layout.each { |m, l| l.state = @global_message_state if m.is_a? Message } update end def collapse_non_new_messages - @layout.each { |m, l| l.state = m.has_label?(:unread) ? :open : :closed } + @layout.each { |m, l| l.state = l.orig_new ? :open : :closed if m.is_a? Message } update end def expand_all_quotes if(m = @message_lines[curpos]) @@ -244,13 +259,11 @@ update end end def cleanup - @thread.remove_label :unread - UpdateManager.relay self, :read, @thread - @layout = @text = nil + @layout = @text = nil # for good luck end def archive_and_kill @thread.remove_label :inbox UpdateManager.relay self, :archived, @thread @@ -288,11 +301,11 @@ next end l = @layout[m] or next # TODO: figure out why this is nil sometimes ## build the patina - text = chunk_to_lines m, l.state, @text.length, depth, parent, @layout[m].color + text = chunk_to_lines m, l.state, @text.length, depth, parent, @layout[m].color, @layout[m].star_color l.top = @text.length l.bot = @text.length + text.length # updated below l.prev = prevm l.next = nil @@ -325,22 +338,22 @@ @layout[m].bot = @text.length end end end - def message_patina_lines m, state, start, parent, prefix, color + def message_patina_lines m, state, start, parent, prefix, color, star_color prefix_widget = [color, prefix] widget = case state when :closed [color, "+ "] when :open, :detailed [color, "- "] end imp_widget = if m.has_label?(:starred) - [:starred_patina_color, "* "] + [star_color, "* "] else [color, " "] end case state @@ -396,18 +409,18 @@ def format_person p p.longname + (ContactManager.is_contact?(p) ? " (#{ContactManager.alias_for p})" : "") end - def chunk_to_lines chunk, state, start, depth, parent=nil, color=nil + def chunk_to_lines chunk, state, start, depth, parent=nil, color=nil, star_color=nil prefix = " " * INDENT_SPACES * depth case chunk when :fake_root [[[:missing_message_color, "#{prefix}<one or more unreceived messages>"]]] when nil [[[:missing_message_color, "#{prefix}<an unreceived message>"]]] when Message - message_patina_lines(chunk, state, start, parent, prefix, color) + + message_patina_lines(chunk, state, start, parent, prefix, color, star_color) + (chunk.is_draft? ? [[[:draft_notification_color, prefix + " >>> This message is a draft. To edit, hit 'e'. <<<"]]] : []) when Message::Attachment [[[:mime_color, "#{prefix}+ MIME attachment #{chunk.content_type}#{chunk.desc ? ' (' + chunk.desc + ')': ''}"]]] when Message::Text t = chunk.lines