From 00ddb2607c771b70156e784beb370ecfa5f0a88c Mon Sep 17 00:00:00 2001 From: wmorgan Date: Fri, 5 Jan 2007 01:54:40 +0000 Subject: [PATCH] renamed load_more_threads to load_threads and moved to thread-index-mode. also made "saving thread" message actually accurate git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@178 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- bin/sup | 6 +++--- lib/sup/modes/contact-list-mode.rb | 2 +- lib/sup/modes/inbox-mode.rb | 10 +-------- lib/sup/modes/label-list-mode.rb | 2 +- lib/sup/modes/label-search-results-mode.rb | 6 +----- lib/sup/modes/person-search-results-mode.rb | 6 +----- lib/sup/modes/search-results-mode.rb | 6 +----- lib/sup/modes/thread-index-mode.rb | 23 ++++++++++++++------- 8 files changed, 25 insertions(+), 36 deletions(-) diff --git a/bin/sup b/bin/sup index c60d990..28334b6 100644 --- a/bin/sup +++ b/bin/sup @@ -100,7 +100,7 @@ begin Logger.make_buf bm.draw_screen - imode.load_more_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread { sleep 1; PollManager.poll } } + imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread { sleep 1; PollManager.poll } } PollManager.start_thread @@ -140,7 +140,7 @@ begin log "built query from #{text.inspect}: #{qobj}" mode = SearchResultsMode.new qobj bm.spawn "search: \"#{short_text}\"", mode - mode.load_more_threads :num => mode.buffer.content_height + mode.load_threads :num => mode.buffer.content_height rescue Ferret::QueryParser::QueryParseException => e bm.flash "Couldn't parse query." end @@ -167,7 +167,7 @@ begin b = BufferManager.spawn_unless_exists(:draft) do mode = LabelSearchResultsMode.new [:draft] end - b.mode.load_more_threads :num => b.content_height + b.mode.load_threads :num => b.content_height end when :nothing when :redraw diff --git a/lib/sup/modes/contact-list-mode.rb b/lib/sup/modes/contact-list-mode.rb index ceb185a..1a51d12 100644 --- a/lib/sup/modes/contact-list-mode.rb +++ b/lib/sup/modes/contact-list-mode.rb @@ -60,7 +60,7 @@ class ContactListMode < LineCursorMode def multi_search people mode = PersonSearchResultsMode.new people BufferManager.spawn "personal search results", mode - mode.load_more_threads :num => mode.buffer.content_height + mode.load_threads :num => mode.buffer.content_height end def search diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb index b4da4f6..97b8561 100644 --- a/lib/sup/modes/inbox-mode.rb +++ b/lib/sup/modes/inbox-mode.rb @@ -6,8 +6,6 @@ class InboxMode < ThreadIndexMode register_keymap do |k| ## overwrite toggle_archived with archive k.add :archive, "Archive thread (remove from inbox)", 'a' - k.add :load_more_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M' - k.add :reload, "Discard threads and reload", 'D' end def initialize @@ -28,7 +26,7 @@ class InboxMode < ThreadIndexMode def is_relevant? m; m.has_label? :inbox; end - def load_more_threads opts={} + def load_threads opts={} n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM load_n_threads_background n, :label => :inbox, :load_killed => false, @@ -38,12 +36,6 @@ class InboxMode < ThreadIndexMode BufferManager.flash "Added #{num} threads." end) end - - def reload - drop_all_threads - BufferManager.draw_screen - load_more_threads :num => buffer.content_height - end end end diff --git a/lib/sup/modes/label-list-mode.rb b/lib/sup/modes/label-list-mode.rb index 6bd3aa7..18ce9aa 100644 --- a/lib/sup/modes/label-list-mode.rb +++ b/lib/sup/modes/label-list-mode.rb @@ -81,7 +81,7 @@ protected b = BufferManager.spawn_unless_exists(label) do mode = LabelSearchResultsMode.new [label] end - b.mode.load_more_threads :num => b.content_height + b.mode.load_threads :num => b.content_height end end end diff --git a/lib/sup/modes/label-search-results-mode.rb b/lib/sup/modes/label-search-results-mode.rb index 34a0943..1df1971 100644 --- a/lib/sup/modes/label-search-results-mode.rb +++ b/lib/sup/modes/label-search-results-mode.rb @@ -1,10 +1,6 @@ module Redwood class LabelSearchResultsMode < ThreadIndexMode - register_keymap do |k| - k.add :load_more_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M' - end - def initialize labels @labels = labels super @@ -12,7 +8,7 @@ class LabelSearchResultsMode < ThreadIndexMode def is_relevant? m; @labels.all? { |l| m.has_label? l }; end - def load_more_threads opts={} + def load_threads opts={} n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM load_n_threads_background n, :labels => @labels, :load_killed => true, diff --git a/lib/sup/modes/person-search-results-mode.rb b/lib/sup/modes/person-search-results-mode.rb index d2de8d3..71505e3 100644 --- a/lib/sup/modes/person-search-results-mode.rb +++ b/lib/sup/modes/person-search-results-mode.rb @@ -1,10 +1,6 @@ module Redwood class PersonSearchResultsMode < ThreadIndexMode - register_keymap do |k| - k.add :load_more_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M' - end - def initialize people @people = people super @@ -12,7 +8,7 @@ class PersonSearchResultsMode < ThreadIndexMode def is_relevant? m; @people.any? { |p| m.from == p }; end - def load_more_threads opts={} + def load_threads opts={} n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM load_n_threads_background n, :participants => @people, :load_killed => true, diff --git a/lib/sup/modes/search-results-mode.rb b/lib/sup/modes/search-results-mode.rb index 1dbbadf..5502b3c 100644 --- a/lib/sup/modes/search-results-mode.rb +++ b/lib/sup/modes/search-results-mode.rb @@ -1,10 +1,6 @@ module Redwood class SearchResultsMode < ThreadIndexMode - register_keymap do |k| - k.add :load_more_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M' - end - def initialize qobj @qobj = qobj super @@ -13,7 +9,7 @@ class SearchResultsMode < ThreadIndexMode ## TODO: think about this def is_relevant? m; super; end - def load_more_threads opts={} + def load_threads opts={} n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM load_n_threads_background n, :qobj => @qobj, :load_killed => true, diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 864d347..0ebc349 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -1,11 +1,15 @@ module Redwood +## subclasses should implement load_threads + class ThreadIndexMode < LineCursorMode DATE_WIDTH = Time::TO_NICE_S_MAX_LEN FROM_WIDTH = 15 LOAD_MORE_THREAD_NUM = 20 register_keymap do |k| + k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M' + k.add :reload, "Discard threads and reload", 'D' k.add :toggle_archived, "Toggle archived status", 'a' k.add :toggle_starred, "Star or unstar all messages in thread", '*' k.add :toggle_new, "Toggle new/read status of all messages in thread", 'N' @@ -41,6 +45,12 @@ class ThreadIndexMode < LineCursorMode def lines; @text.length; end def [] i; @text[i]; end + def reload + drop_all_threads + BufferManager.draw_screen + load_threads :num => buffer.content_height + end + ## open up a thread view window def select t=nil t ||= @threads[curpos] @@ -185,15 +195,14 @@ class ThreadIndexMode < LineCursorMode def save threads = @threads + @hidden_threads.keys - mbid = BufferManager.say "Saving threads..." - threads.each_with_index do |t, i| - if i % 5 == 0 - BufferManager.say "Saving thread #{i + 1} of #{threads.length}...", - mbid + + BufferManager.say("Saving threads...") do |say_id| + threads.each_with_index do |t, i| + next unless t.dirty? + BufferManager.say "Saving thread #{i +1} of #{threads.length}...", say_id + t.save Index end - t.save Index end - BufferManager.clear mbid end def cleanup -- 2.45.2