]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/thread-view-mode.rb
'A' archives and kills buffer in thread-view-mode (required significant updatedes...
[sup] / lib / sup / modes / thread-view-mode.rb
index 2549a1fe09c3a01f348e7c831628a181c008b872..eeef330b4adb7ebf673f6dff08b54b8828a88ccd 100644 (file)
@@ -26,6 +26,7 @@ class ThreadViewMode < LineCursorMode
     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 :archive_and_kill, "Archive thread and kill buffer", 'A'
   end
 
   ## there are a couple important instance variables we hold to lay
@@ -61,7 +62,7 @@ class ThreadViewMode < LineCursorMode
     @layout[latest].state = :open if @layout[latest].state == :closed
     @layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1
 
-    BufferManager.say("Loading message bodies...") { update }
+    regen_text
   end
 
   def draw_line ln, opts={}
@@ -124,7 +125,7 @@ class ThreadViewMode < LineCursorMode
     ## TODO: don't recalculate EVERYTHING just to add a stupid little
     ## star to the display
     update
-    UpdateManager.relay :starred, m
+    UpdateManager.relay self, :starred, m
   end
 
   def toggle_expanded
@@ -244,19 +245,18 @@ class ThreadViewMode < LineCursorMode
     end
   end
 
-  ## kinda slow for large threads. TODO: fasterify
   def cleanup
-    BufferManager.say "Marking messages as read..." do
-      @thread.each do |m, d, p|
-        if m && m.has_label?(:unread)
-          m.remove_label :unread 
-          UpdateManager.relay :read, m
-        end
-      end
-    end
+    @thread.remove_label :unread
+    UpdateManager.relay self, :read, @thread
     @layout = @text = nil
   end
 
+  def archive_and_kill
+    @thread.remove_label :inbox
+    UpdateManager.relay self, :archived, @thread
+    BufferManager.kill_buffer_safely buffer
+  end
+
 private 
 
   def initial_state_for m
@@ -287,24 +287,7 @@ private
         @text += chunk_to_lines m, nil, @text.length, depth, parent
         next
       end
-
-      ## we're occasionally called on @threads that have had messages
-      ## added to them since initialization. luckily we regen_text on
-      ## the entire thread every time the user does anything besides
-      ## scrolling (basically), so we can just slap this on here.
-      ##
-      ## to pick nits, the niceness that i do in the constructor with
-      ## 'latest' etc. (for automatically opening just the latest
-      ## message if everything's been read) will not be valid, but
-      ## that's just a nicety and hopefully this won't happen too
-      ## often.
-
-      unless @layout.member? m
-        l = @layout[m] = Layout.new
-        l.state = initial_state_for m
-        l.color = prevm && @layout[prevm].color == :message_patina_color ? :alternate_patina_color : :message_patina_color
-      end
-      l = @layout[m]
+      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
@@ -456,9 +439,10 @@ private
 
   def view_attachment a
     BufferManager.flash "viewing #{a.content_type} attachment..."
-    a.view!
+    success = a.view!
     BufferManager.erase_flash
     BufferManager.completely_redraw_screen
+    BufferManager.flash "Couldn't execute view command." unless success
   end
 
 end