]> git.notmuchmail.org Git - sup/commitdiff
autoload more threads when you go down
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 21 May 2007 16:24:13 +0000 (16:24 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 21 May 2007 16:24:13 +0000 (16:24 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@406 5c8cc53c-5e98-4d25-b20a-d8db53a31250

doc/TODO
lib/sup/index.rb
lib/sup/modes/inbox-mode.rb
lib/sup/modes/label-search-results-mode.rb
lib/sup/modes/line-cursor-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 853abcfbf2a5b5761adc9a3dab38cd39c19f0f6d..d596648521f4c7b8db241e93305019dc4b573e00 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -11,6 +11,8 @@ _ bugfix: readlock
 _ split out threading & message chunk parsing to a separate library
 _ decode RFC 2047 ("encoded word") headers
   - see: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/101949, http://dev.rubyonrails.org/ticket/6807
+_ refactor all the *-search-results-mode classes into one.
+x autoload more threads when you go down
 x add a sync-back tool that at least works for mboxes
 x thread by subject configurable in config.yaml
 x view as text command if the mime view command fails for an attachment
index cd7c77593ea5513ca4dc300f437fa72738bbcbb4..524a1de74ea28b7c74eb6c665bc5902831f6f4fb 100644 (file)
@@ -143,8 +143,9 @@ class Index
 
   def num_results_for opts={}
     return 0 if @index.size == 0 # otherwise ferret barfs ###TODO: remove this once my ferret patch is accepted
+
     q = build_query opts
-    index.search(q).total_hits
+    index.search(q, :limit => 1).total_hits
   end
 
   ## yield all messages in the thread containing 'm' by repeatedly
index 37ed26d9665523ea95d184a8b5938ccc4bee0e3b..a69a67e2194eff93fe41481039729b567f9fea32 100644 (file)
@@ -51,7 +51,7 @@ class InboxMode < ThreadIndexMode
     n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
     load_n_threads_background n, :label => :inbox,
                                  :when_done => (lambda do |num|
-      opts[:when_done].call if opts[:when_done]
+      opts[:when_done].call(num) if opts[:when_done]
       BufferManager.flash "Added #{num} threads."
     end)
   end
index 1df1971e40c44954be8313c6522b10745fd42ee7..1d6acaf5be2c7dc095dc134443ca29e1f231e297 100644 (file)
@@ -14,7 +14,7 @@ class LabelSearchResultsMode < ThreadIndexMode
                                  :load_killed => true,
                                  :load_spam => false,
                                  :when_done =>(lambda do |num|
-      opts[:when_done].call if opts[:when_done]
+      opts[:when_done].call(num) if opts[:when_done]
       if num > 0
         BufferManager.flash "Found #{num} threads"
       else
index 1405a782f4cbeed7019018237aa4e0663ec8d18b..0288474d81bfcb14f226f94e147136533c1b877f 100644 (file)
@@ -1,5 +1,6 @@
 module Redwood
 
+## extends ScrollMode to have a line-based cursor.
 class LineCursorMode < ScrollMode
   register_keymap do |k|
     ## overwrite scrollmode binding on arrow keys for cursor movement
@@ -14,6 +15,9 @@ class LineCursorMode < ScrollMode
   def initialize cursor_top=0, opts={}
     @cursor_top = cursor_top
     @curpos = cursor_top
+    @load_more_callbacks = []
+    @load_more_callbacks_m = Mutex.new
+    @load_more_callbacks_active = false
     super opts
   end
 
@@ -24,6 +28,11 @@ class LineCursorMode < ScrollMode
 
 protected
 
+  ## callbacks when the cursor is asked to go beyond the bottom
+  def to_load_more &b
+    @load_more_callbacks << b
+  end
+
   def draw_line ln, opts={}
     if ln == @curpos
       super ln, :highlight => true, :debug => opts[:debug]
@@ -49,6 +58,7 @@ protected
 
   def line_down # overwrite scrollmode
     super
+    call_load_more_callbacks([topline + buffer.content_height - lines, 10].max) if topline + buffer.content_height > lines
     set_cursor_pos topline if @curpos < topline
   end
 
@@ -58,7 +68,9 @@ protected
   end
 
   def cursor_down
+    call_load_more_callbacks buffer.content_height if @curpos == lines - 1
     return false unless @curpos < lines - 1
+
     if @curpos >= botline - 1
       page_down
       set_cursor_pos topline
@@ -102,9 +114,21 @@ protected
     end
   end
 
+  ## more complicated than one might think. three behaviors.
   def page_down
-    if topline >= lines - buffer.content_height
+    ## if we're on the last page, and it's not a full page, just move
+    ## the cursor down to the bottom and assume we can't load anything
+    ## else via the callbacks.
+    if topline > lines - buffer.content_height
       set_cursor_pos(lines - 1)
+
+    ## if we're on the last page, and it's a full page, try and load
+    ## more lines via the callbacks and then shift the page down
+    elsif topline == lines - buffer.content_height
+      call_load_more_callbacks buffer.content_height
+      super
+
+    ## otherwise, just move down
     else
       relpos = @curpos - topline
       super
@@ -129,6 +153,22 @@ private
     @status = l > 0 ? "line #{@curpos + 1} of #{l}" : ""
   end
 
+  def call_load_more_callbacks size
+    go = 
+      @load_more_callbacks_m.synchronize do
+        if @load_more_callbacks_active
+          false
+        else
+          @load_more_callbacks_active = true
+        end
+    end
+
+    return unless go
+
+    @load_more_callbacks.each { |c| c.call size }
+    @load_more_callbacks_active = false
+  end    
+
 end
 
 end
index 71505e3742443aea1378da5f9823c341b74403f7..89badaec01fb868938a3a72a67d1186443a5a75a 100644 (file)
@@ -14,7 +14,7 @@ class PersonSearchResultsMode < ThreadIndexMode
                                  :load_killed => true,
                                  :load_spam => false,
                                  :when_done =>(lambda do |num|
-      opts[:when_done].call if opts[:when_done]
+      opts[:when_done].call(num) if opts[:when_done]
       if num > 0
         BufferManager.flash "Found #{num} threads"
       else
index 5502b3cdaff2f54a5b794b6527c76bc45228d230..c697289a76c8556fc30f294aa3d1b2dfeb1994af 100644 (file)
@@ -15,7 +15,7 @@ class SearchResultsMode < ThreadIndexMode
                                  :load_killed => true,
                                  :load_spam => false,
                                  :when_done =>(lambda do |num|
-      opts[:when_done].call if opts[:when_done]
+      opts[:when_done].call(num) if opts[:when_done]
       if num > 0
         BufferManager.flash "Found #{num} threads"
       else
index b89079b3e6ef4889dc148e49cb95015d3e55cb0a..1940e3b0c2684ae450aad4a0d9ed5575a8a35cfc 100644 (file)
@@ -2,7 +2,6 @@ require 'thread'
 module Redwood
 
 ## subclasses should implement load_threads
-
 class ThreadIndexMode < LineCursorMode
   DATE_WIDTH = Time::TO_NICE_S_MAX_LEN
   FROM_WIDTH = 15
@@ -35,13 +34,21 @@ class ThreadIndexMode < LineCursorMode
     @date_width = DATE_WIDTH
     @from_width = FROM_WIDTH
     @size_width = nil
-
+    @last_load_more_size = nil
+    
     @tags = Tagger.new self
     
     initialize_threads
     update
 
     UpdateManager.register self
+
+    to_load_more do |size|
+      next if @last_load_more_size == 0
+      load_threads :num => size,
+                   :when_done => lambda { |num| @last_load_more_size = num }
+      sleep 1.0 # give 'em a chance to load
+    end
   end
 
   def lines; @text.length; end
@@ -361,7 +368,7 @@ class ThreadIndexMode < LineCursorMode
 
   def status
     if (l = lines) == 0
-      ""
+      "line 0 of 0"
     else
       "line #{curpos + 1} of #{l} #{dirty? ? '*modified*' : ''}"
     end