]> git.notmuchmail.org Git - sup/commitdiff
Tagger#apply_to_tagged can take an arbitrary action
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 17 Jan 2008 00:47:35 +0000 (16:47 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 17 Jan 2008 00:47:35 +0000 (16:47 -0800)
With this change, applying operations to tagged objects can be
short-circuited by passing the desired action directly to #apply_to_tagged,
rather than requiring it to interactive prompt the user for a command.

This class could probably use a little restructuring to divorce it from
Mode.

lib/sup/tagger.rb

index 6e4bab3c67cc4f8beb49a3f4552f7752c6a9b132..3e72463fc0e90128c5dd39e4c3f3535d9bc2cd7f 100644 (file)
@@ -13,7 +13,7 @@ class Tagger
   def drop_all_tags; @tagged.clear; end
   def drop_tag_for o; @tagged.delete o; end
 
-  def apply_to_tagged
+  def apply_to_tagged action=nil
     targets = @tagged.select_by_value
     num_tagged = targets.size
     if num_tagged == 0
@@ -22,10 +22,14 @@ class Tagger
     end
 
     noun = num_tagged == 1 ? "thread" : "threads"
-    c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
-    return if c.nil? # user cancelled
 
-    if(action = @mode.resolve_input(c))
+    unless action
+      c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
+      return if c.nil? # user cancelled
+      action = @mode.resolve_input c
+    end
+
+    if action
       tagged_sym = "multi_#{action}".intern
       if @mode.respond_to? tagged_sym
         @mode.send tagged_sym, targets