Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: marcus-sup@bar-coded.net (Marcus Williams)
Subject: [sup-talk] [PATCH] Search all threads with option to cancel
Date: Tue, 15 Jan 2008 12:29:57 +0000	[thread overview]
Message-ID: <1200400125-sup-5900@tomsk> (raw)
In-Reply-To: <1200372469-sup-1813@south>

This adds the ability to extend your search to display all threads
(which may take a _long_ time) instead of the standard maximum (usually
screen height). It is accessed via a multi-key action !C in thread index
modes. To cancel the search the user can press another multi-key action
!S
---
 lib/sup/modes/thread-index-mode.rb |   40 +++++++++++++++++++++++++++++++----
 lib/sup/thread.rb                  |    2 +-
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 0d90be4..f86a5a4 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -16,6 +16,10 @@ EOS
 
   register_keymap do |k|
     k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
+    k.add_multi "Search all threads - (C)onfirm, or (S)top current search :", '!' do |kk|
+      kk.add :load_all_threads, "Load all threads (may list a _lot_ of threads)", 'C'
+      kk.add :break_search, "Stop current search", 'S'
+    end
     k.add :reload, "Refresh view", '@'
     k.add :toggle_archived, "Toggle archived status", 'a'
     k.add :toggle_starred, "Star or unstar all messages in thread", '*'
@@ -49,6 +53,8 @@ EOS
     @load_thread_opts = load_thread_opts
     @hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS
     @date_width = DATE_WIDTH
+
+    @interrupt_search = false
     
     initialize_threads # defines @ts and @ts_mutex
     update # defines @text and @lines
@@ -444,15 +450,20 @@ EOS
   ## TODO: figure out @ts_mutex in this method
   def load_n_threads n=LOAD_MORE_THREAD_NUM, opts={}
     @mbid = BufferManager.say "Searching for threads..."
+
+    ts_to_load = n
+    ts_to_load = ts_to_load + @ts.size unless n == -1 # -1 means all threads
+
     orig_size = @ts.size
     last_update = Time.now
-    @ts.load_n_threads(@ts.size + n, opts) do |i|
+    @ts.load_n_threads(ts_to_load, opts) do |i|
       if (Time.now - last_update) >= 0.25
-        BufferManager.say "Loaded #{i.pluralize 'thread'}...", @mbid
+        BufferManager.say "Loaded #{i.pluralize 'thread'} (use !S to cancel search)...", @mbid
         update
         BufferManager.draw_screen
         last_update = Time.now
       end
+      break if @interrupt_search
     end
     @ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }
 
@@ -472,13 +483,32 @@ EOS
     end
   end
 
-  def load_threads opts={}
-    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
+  def break_search
+    @interrupt_search = true
+  end
 
+  def load_all_threads
+    load_threads :num => -1
+  end
+
+  def load_threads opts={}
+    if opts[:num].nil?
+      n = ThreadIndexMode::LOAD_MORE_THREAD_NUM
+    else
+      n = opts[:num]
+    end
+        
     myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
       opts[:when_done].call(num) if opts[:when_done]
+      
+      cancelled = ""
+      if @interrupt_search
+        cancelled = " (search cancelled by user)" 
+        @interrupt_search = false
+      end
+
       if num > 0
-        BufferManager.flash "Found #{num.pluralize 'thread'}."
+        BufferManager.flash "Found #{num.pluralize 'thread'}#{cancelled}."
       else
         BufferManager.flash "No matches."
       end
diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb
index 83f0db7..5b0a300 100644
--- a/lib/sup/thread.rb
+++ b/lib/sup/thread.rb
@@ -324,7 +324,7 @@ class ThreadSet
   ## load in (at most) num number of threads from the index
   def load_n_threads num, opts={}
     @index.each_id_by_date opts do |mid, builder|
-      break if size >= num
+      break if size >= num unless num == -1
       next if contains_id? mid
 
       m = builder.call
-- 
1.5.3.7



  reply	other threads:[~2008-01-15 12:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-11 17:20 [sup-talk] [PATCH] (Double/guarded) keypress to show all threads Marcus Williams
2008-01-13  5:30 ` William Morgan
2008-01-13 15:57   ` Nicolas Pouillard
2008-01-13 18:16   ` Marcus Williams
2008-01-14  1:06     ` William Morgan
2008-01-14 10:54       ` Marcus Williams
2008-01-15  4:49         ` William Morgan
2008-01-15 12:29           ` Marcus Williams [this message]
2008-01-16  4:30             ` [sup-talk] [PATCH] Search all threads with option to cancel William Morgan
2008-01-16 10:47               ` Marcus Williams
2008-01-16 21:09                 ` William Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1200400125-sup-5900@tomsk \
    --to=marcus-sup@bar-coded.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox