]> git.notmuchmail.org Git - sup/commitdiff
add tag by match to thread-index-mode
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 9 Dec 2007 19:12:19 +0000 (19:12 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 9 Dec 2007 19:12:19 +0000 (19:12 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@752 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/modes/thread-index-mode.rb
lib/sup/tagger.rb

index 8dec42d1e842b41e217d6bafcf422eb3b1ae3198..8727e2428f0fd0e99f2fd9aa8ddf3412e8527a89 100644 (file)
@@ -31,6 +31,7 @@ EOS
     k.add :forward, "Forward latest message in a thread", 'f'
     k.add :toggle_tagged, "Tag/untag selected thread", 't'
     k.add :toggle_tagged_all, "Tag/untag all threads", 'T'
+    k.add :tag_matching, "Tag/untag all threads", 'g'
     k.add :apply_to_tagged, "Apply next command to all tagged threads", ';'
   end
 
@@ -351,6 +352,14 @@ EOS
     regen_text
   end
 
+  def tag_matching
+    query = BufferManager.ask :search, "tag threads matching: "
+    return if query.nil? || query.empty?
+    query = /#{query}/i
+    @mutex.synchronize { @threads.each { |t| @tags.tag t if thread_match?(t, query) } }
+    regen_text
+  end
+
   def apply_to_tagged; @tags.apply_to_tagged; end
 
   def edit_labels
@@ -465,6 +474,12 @@ EOS
 
 protected
 
+  ## used to tag threads by query. this can be made a lot more sophisticated,
+  ## but for right now we'll do the obvious this.
+  def thread_match? t, query
+    t.snippet =~ query || t.participants.any? { |x| x.longname =~ query }
+  end
+
   def size_widget_for_thread t
     HookManager.run("index-mode-size-widget", :thread => t) || default_size_widget_for(t)
   end
index 464f1ac4d49fe0a8fdcf783aca0e9c38f3e3318d..6e4bab3c67cc4f8beb49a3f4552f7752c6a9b132 100644 (file)
@@ -8,6 +8,8 @@ class Tagger
 
   def tagged? o; @tagged[o]; end
   def toggle_tag_for o; @tagged[o] = !@tagged[o]; end
+  def tag o; @tagged[o] = true; end
+  def untag o; @tagged[o] = false; end
   def drop_all_tags; @tagged.clear; end
   def drop_tag_for o; @tagged.delete o; end