]> git.cworth.org Git - sup/commitdiff
bugfixes and comment improvments
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Fri, 5 Jan 2007 01:58:27 +0000 (01:58 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Fri, 5 Jan 2007 01:58:27 +0000 (01:58 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@179 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/buffer.rb
lib/sup/modes/thread-view-mode.rb
lib/sup/thread.rb

index 4a3437a046412af48a1ed99b3681f12bb9de080f..2b94d79813b299f02eb0cdbcb7621ceff2d246ba 100644 (file)
@@ -232,7 +232,6 @@ class BufferManager
   ## the mode is expensive, as it often is.
   def spawn_unless_exists title, opts={}
     if @name_map.member? title
-      Redwood::log "buffer '#{title}' already exists, raising to front"
       raise_to_front @name_map[title] unless opts[:hidden]
     else
       mode = yield
index c641292421475b030d0d683b39a96482639f96d8..37bef9f921b36531364b3e207c4ced24b345da7c 100644 (file)
@@ -25,26 +25,20 @@ class ThreadViewMode < LineCursorMode
     @state = {}
     @hidden_labels = hidden_labels
 
-    earliest = nil
-    latest = nil
+    earliest, latest = nil, nil
     latest_date = nil
     @thread.each do |m, d, p|
       next unless m
       earliest ||= m
-      @state[m] = 
-        if m.has_label?(:unread) && m == earliest
-          :detailed
-        elsif m.has_label?(:starred) || m.has_label?(:unread)
-          :open
-        else
-          :closed
-        end
+      @state[m] = initial_state_for m
       if latest_date.nil? || m.date > latest_date
         latest_date = m.date
         latest = m
       end
     end
+
     @state[latest] = :open if @state[latest] == :closed
+    @state[earliest] = :detailed if earliest.has_label?(:unread)
 
     BufferManager.say "Loading message bodies..." do
       regen_chunks
@@ -207,12 +201,14 @@ class ThreadViewMode < LineCursorMode
     end
   end
 
-  ## not sure if this is really necessary but we might as well...
+  ## kinda slow for large threads. TODO: make faster
   def cleanup
-    @thread.each do |m, d, p|
-      if m && m.has_label?(:unread)
-        m.remove_label :unread 
-        UpdateManager.relay :read, m
+    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
     @messages = @chunks = @text = nil
@@ -220,6 +216,14 @@ class ThreadViewMode < LineCursorMode
 
 private 
 
+  def initial_state_for m
+    if m.has_label?(:starred) || m.has_label?(:unread)
+      :open
+    else
+      :closed
+    end
+  end
+
   def update
     regen_text
     buffer.mark_dirty if buffer
@@ -238,6 +242,16 @@ private
 
     prev_m = nil
     @thread.each do |m, depth, parent|
+      ## 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' might not be valid, but i don't see that as a huge
+      ## issue.
+      @state[m] ||= initial_state_for m if m
+
       text = chunk_to_lines m, @state[m], @text.length, depth, parent
       (0 ... text.length).each do |i|
         @chunk_lines[@text.length + i] = m
@@ -327,7 +341,6 @@ private
     when Message
       message_patina_lines(chunk, state, parent, prefix) +
         (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
index be3a7780c92f18b0196b731996a5a0032a16e696..4c846cff5e4865a007278028900195dfe8cc32f4 100644 (file)
@@ -7,7 +7,9 @@ class Thread
 
   attr_reader :containers
   def initialize
-    raise "wrong thread, buddy!" if block_given?
+    ## ah, the joys of a multithreaded application with a class called
+    ## "Thread". i keep instantiating the wrong one...
+    raise "wrong Thread class, buddy!" if block_given?
     @containers = []
   end
 
@@ -28,7 +30,9 @@ class Thread
     puts "=== end thread ==="
   end
 
-  ## yields each message and some stuff
+  ## yields each message, its depth, and its parent
+  ## note that the message can be a Message object, or :fake_root,
+  ## or nil.
   def each fake_root=false
     adj = 0
     root = @containers.find_all { |c| !Message.subj_is_reply?(c) }.argmin { |c| c.date }
@@ -78,6 +82,7 @@ class Thread
   def set_labels l; each { |m, *o| m && m.labels = l }; end
   
   def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end
+  def dirty?; any? { |m, *o| m && m.dirty? }; end
   def save index; each { |m, *o| m && m.save(index) }; end
 
   def direct_participants