From: wmorgan Date: Fri, 5 Jan 2007 01:58:27 +0000 (+0000) Subject: bugfixes and comment improvments X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=10efc3ca507585ea25ff6c1d1ceacb80067a3624;p=sup bugfixes and comment improvments git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@179 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb index 4a3437a..2b94d79 100644 --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@ -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 diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb index c641292..37bef9f 100644 --- a/lib/sup/modes/thread-view-mode.rb +++ b/lib/sup/modes/thread-view-mode.rb @@ -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 diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb index be3a778..4c846cf 100644 --- a/lib/sup/thread.rb +++ b/lib/sup/thread.rb @@ -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