Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: marcus-sup@bar-coded.net (Marcus Williams)
Subject: [sup-talk] [PATCH] Add ability to interrupt current thread operation (search)
Date: Sat, 19 Jan 2008 18:59:14 +0000	[thread overview]
Message-ID: <1200769080-sup-4420@tomsk> (raw)
In-Reply-To: <1200768474-sup-7396@tomsk>

This adds the ability to stop the current threading operation. This is
usually a search, but its anything that ends up calling load_n_threads
in thread-index-view. The user can hit ctrl-g to stop the operation.
---
 lib/sup/modes/thread-index-mode.rb |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index dec3c1d..2b8cc20 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -16,6 +16,7 @@ EOS
 
   register_keymap do |k|
     k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
+    k.add :cancel_search, "Cancel current search", :ctrl_g
     k.add :reload, "Refresh view", '@'
     k.add :toggle_archived, "Toggle archived status", 'a'
     k.add :toggle_starred, "Star or unstar all messages in thread", '*'
@@ -50,6 +51,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
@@ -456,16 +459,19 @@ EOS
 
   ## TODO: figure out @ts_mutex in this method
   def load_n_threads n=LOAD_MORE_THREAD_NUM, opts={}
+    @interrupt_search = false
     @mbid = BufferManager.say "Searching for threads..."
+
     orig_size = @ts.size
     last_update = Time.now
     @ts.load_n_threads(@ts.size + n, opts) do |i|
       if (Time.now - last_update) >= 0.25
-        BufferManager.say "Loaded #{i.pluralize 'thread'}...", @mbid
+        BufferManager.say "Loaded #{i.pluralize 'thread'} (use ^G to cancel)...", @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 } }
 
@@ -485,13 +491,20 @@ EOS
     end
   end
 
+  def cancel_search
+    @interrupt_search = true
+  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]
+
+      cancelled = @interrupt_search?" (search cancelled by user)":""
+
       if num > 0
-        BufferManager.flash "Found #{num.pluralize 'thread'}."
+        BufferManager.flash "Found #{num.pluralize 'thread'}#{cancelled}."
       else
         BufferManager.flash "No matches."
       end
-- 
1.5.3.7



  reply	other threads:[~2008-01-19 18:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-19 18:42 Marcus Williams
2008-01-19 18:49 ` Marcus Williams
2008-01-19 18:59   ` Marcus Williams [this message]
2008-01-23 19:15     ` William Morgan
2008-01-23 20:14       ` Marcus Williams
2008-02-03  1:06         ` 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=1200769080-sup-4420@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