]> git.cworth.org Git - sup/blobdiff - lib/sup/tagger.rb
Merge branch 'master' into next
[sup] / lib / sup / tagger.rb
index 424dac26409c7e45dc45029997e61b9b69374997..d62f3404557d637af7c70631e780ad0c63b1df02 100644 (file)
@@ -1,34 +1,42 @@
 module Redwood
 
 class Tagger
-  def initialize mode
+  def initialize mode, noun="thread", plural_noun=nil
     @mode = mode
     @tagged = {}
+    @noun = noun
+    @plural_noun = plural_noun || (@noun + "s")
   end
 
   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
 
-  def apply_to_tagged
-    num_tagged = @tagged.map { |t| t ? 1 : 0 }.sum
+  def apply_to_tagged action=nil
+    targets = @tagged.select_by_value
+    num_tagged = targets.size
     if num_tagged == 0
-      BufferManager.flash "No tagged messages!"
+      BufferManager.flash "No tagged threads!"
       return
     end
 
-    noun = num_tagged == 1 ? "message" : "messages"
-    c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
-    return if c.nil? # user cancelled
+    noun = num_tagged == 1 ? @noun : @plural_noun
 
-    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
-        targets = @tagged.select_by_value
         @mode.send tagged_sym, targets
       else
-        BufferManager.flash "That command cannot be applied to multiple messages."
+        BufferManager.flash "That command cannot be applied to multiple threads."
       end
     else
       BufferManager.flash "Unknown command #{c.to_character}."