]> git.notmuchmail.org Git - sup/commitdiff
thread-index-mode and subclass refactoring for conciseness and better thread auto...
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 3 Jun 2007 22:47:12 +0000 (22:47 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 3 Jun 2007 22:47:12 +0000 (22:47 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@429 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/modes/inbox-mode.rb
lib/sup/modes/label-search-results-mode.rb
lib/sup/modes/person-search-results-mode.rb
lib/sup/modes/search-results-mode.rb
lib/sup/modes/thread-index-mode.rb

index c72ce4cb1e1295a0e1950979fac8202238f8e2f4..23da9795b438db83912ee943ff750d7e7f992997 100644 (file)
@@ -9,10 +9,15 @@ class InboxMode < ThreadIndexMode
   end
 
   def initialize
-    super [:inbox], [:inbox]
+    super [:inbox, :sent], { :label => :inbox }
+    raise "can't have more than one!" if defined? @@instance
     @@instance = self
   end
 
+  def is_relevant? m; m.has_label? :inbox; end
+
+  ## label-list-mode wants to be able to raise us if the user selects
+  ## the "inbox" label, so we need to keep our singletonness around
   def self.instance; @@instance; end
   def killable?; false; end
 
@@ -47,17 +52,6 @@ class InboxMode < ThreadIndexMode
   def status
     super + "    #{Index.size} messages in index"
   end
-
-  def is_relevant? m; m.has_label? :inbox; end
-
-  def load_threads opts={}
-    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
-    load_n_threads_background n, :label => :inbox,
-                                 :when_done => (lambda do |num|
-      opts[:when_done].call(num) if opts[:when_done]
-      BufferManager.flash "Added #{num} threads."
-    end)
-  end
 end
 
 end
index 1d6acaf5be2c7dc095dc134443ca29e1f231e297..6c80dadbcd569de93c21b6c5f0553ed6524b10fb 100644 (file)
@@ -3,25 +3,10 @@ module Redwood
 class LabelSearchResultsMode < ThreadIndexMode
   def initialize labels
     @labels = labels
-    super
+    super [], { :labels => @labels }
   end
 
   def is_relevant? m; @labels.all? { |l| m.has_label? l }; end
-
-  def load_threads opts={}
-    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
-    load_n_threads_background n, :labels => @labels,
-                                 :load_killed => true,
-                                 :load_spam => false,
-                                 :when_done =>(lambda do |num|
-      opts[:when_done].call(num) if opts[:when_done]
-      if num > 0
-        BufferManager.flash "Found #{num} threads"
-      else
-        BufferManager.flash "No matches"
-      end
-    end)
-  end
 end
 
 end
index 89badaec01fb868938a3a72a67d1186443a5a75a..fc09126e0e6ba228d5848567bcb78f97df17819c 100644 (file)
@@ -3,25 +3,10 @@ module Redwood
 class PersonSearchResultsMode < ThreadIndexMode
   def initialize people
     @people = people
-    super
+    super [], { :participants => @people }
   end
 
   def is_relevant? m; @people.any? { |p| m.from == p }; end
-
-  def load_threads opts={}
-    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
-    load_n_threads_background n, :participants => @people,
-                                 :load_killed => true,
-                                 :load_spam => false,
-                                 :when_done =>(lambda do |num|
-      opts[:when_done].call(num) if opts[:when_done]
-      if num > 0
-        BufferManager.flash "Found #{num} threads"
-      else
-        BufferManager.flash "No matches"
-      end
-    end)
-  end
 end
 
 end
index c697289a76c8556fc30f294aa3d1b2dfeb1994af..1b0d4569b9e51ee507d8ee35f26780a162c80a29 100644 (file)
@@ -3,26 +3,15 @@ module Redwood
 class SearchResultsMode < ThreadIndexMode
   def initialize qobj
     @qobj = qobj
-    super
+    super [], { :qobj => @qobj, :load_killed => true, :load_spam => false }
   end
 
-  ## TODO: think about this
-  def is_relevant? m; super; end
+  ## a proper is_relevant? method requires some way of asking ferret
+  ## if an in-memory object satisfies a query. i'm not sure how to do
+  ## that yet. in the worst case i can make an in-memory index, add
+  ## the message, and search against it to see if i have > 0 results,
+  ## but that seems pretty insane.
 
-  def load_threads opts={}
-    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
-    load_n_threads_background n, :qobj => @qobj,
-                                 :load_killed => true,
-                                 :load_spam => false,
-                                 :when_done =>(lambda do |num|
-      opts[:when_done].call(num) if opts[:when_done]
-      if num > 0
-        BufferManager.flash "Found #{num} threads"
-      else
-        BufferManager.flash "No matches"
-      end
-    end)
-  end
 end
 
 end
index 0ee728f01d1caea2e73909d6568eb6e72da3bd16..4d7c35d99fb04a76084e33f9f1ba9b13398734dd 100644 (file)
@@ -1,7 +1,8 @@
-require 'thread'
 module Redwood
 
-## subclasses should implement load_threads
+## subclasses should implement:
+## - is_relevant?
+
 class ThreadIndexMode < LineCursorMode
   DATE_WIDTH = Time::TO_NICE_S_MAX_LEN
   FROM_WIDTH = 15
@@ -26,10 +27,10 @@ class ThreadIndexMode < LineCursorMode
     k.add :apply_to_tagged, "Apply next command to all tagged threads", ';'
   end
 
-  def initialize required_labels=[], hidden_labels=[]
+  def initialize hidden_labels=[], load_thread_opts={}
     super()
     @load_thread = nil
-    @required_labels = required_labels
+    @load_thread_opts = load_thread_opts
     @hidden_labels = hidden_labels + LabelManager::HIDDEN_LABELS
     @date_width = DATE_WIDTH
     @from_width = FROM_WIDTH
@@ -45,9 +46,9 @@ class ThreadIndexMode < LineCursorMode
 
     to_load_more do |size|
       next if @last_load_more_size == 0
-      load_threads :num => size,
+      load_threads :num => 1, :background => false
+      load_threads :num => (size - 1),
                    :when_done => lambda { |num| @last_load_more_size = num }
-      sleep 1.0 # give 'em a chance to load
     end
   end
 
@@ -374,6 +375,25 @@ class ThreadIndexMode < LineCursorMode
     end
   end
 
+  def load_threads opts={}
+    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
+
+    myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
+      opts[:when_done].call(num) if opts[:when_done]
+      if num > 0
+        BufferManager.flash "Found #{num} threads"
+      else
+        BufferManager.flash "No matches"
+      end
+    end)})
+
+    if opts[:background]
+      load_n_threads_background n, myopts
+    else
+      load_n_threads n, myopts
+    end
+  end
+
 protected
 
   def cursor_thread; @threads[curpos]; end