]> git.cworth.org Git - sup/blob - lib/sup/tagger.rb
per-source short-circuit in sup-sync-back if there are no relevant messages
[sup] / lib / sup / tagger.rb
1 module Redwood
2
3 class Tagger
4   def initialize mode
5     @mode = mode
6     @tagged = {}
7   end
8
9   def tagged? o; @tagged[o]; end
10   def toggle_tag_for o; @tagged[o] = !@tagged[o]; end
11   def drop_all_tags; @tagged.clear; end
12   def drop_tag_for o; @tagged.delete o; end
13
14   def apply_to_tagged
15     targets = @tagged.select_by_value
16     num_tagged = targets.size
17     if num_tagged == 0
18       BufferManager.flash "No tagged threads!"
19       return
20     end
21
22     noun = num_tagged == 1 ? "thread" : "threads"
23     c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
24     return if c.nil? # user cancelled
25
26     if(action = @mode.resolve_input(c))
27       tagged_sym = "multi_#{action}".intern
28       if @mode.respond_to? tagged_sym
29         @mode.send tagged_sym, targets
30       else
31         BufferManager.flash "That command cannot be applied to multiple threads."
32       end
33     else
34       BufferManager.flash "Unknown command #{c.to_character}."
35     end
36   end
37
38 end
39
40 end