Sha256: 17c5a67d2eb762f027b3c751f528da3f745a7425263dddc8b53707004e5290a3

Contents?: true

Size: 1.17 KB

Versions: 22

Compression:

Stored size: 1.17 KB

Contents

module Redwood

class Tagger
  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 action=nil
    targets = @tagged.select_by_value
    num_tagged = targets.size
    if num_tagged == 0
      BufferManager.flash "No tagged threads!"
      return
    end

    noun = num_tagged == 1 ? @noun : @plural_noun

    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
      else
        BufferManager.flash "That command cannot be applied to multiple threads."
      end
    else
      BufferManager.flash "Unknown command #{c.to_character}."
    end
  end

end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sup-0.15.1 lib/sup/tagger.rb
sup-0.15.0 lib/sup/tagger.rb
sup-0.14.1.1 lib/sup/tagger.rb
sup-0.13.2.1 lib/sup/tagger.rb
sup-0.14.1 lib/sup/tagger.rb
sup-0.14.0 lib/sup/tagger.rb
sup-0.13.2 lib/sup/tagger.rb
sup-0.13.1 lib/sup/tagger.rb
sup-0.13.0 lib/sup/tagger.rb
sup-0.12.1 lib/sup/tagger.rb
sup-0.12 lib/sup/tagger.rb
sup-0.11 lib/sup/tagger.rb
sup-0.10.2 lib/sup/tagger.rb
sup-0.10.1 lib/sup/tagger.rb
sup-0.10 lib/sup/tagger.rb
sup-0.9.1 lib/sup/tagger.rb
sup-0.9 lib/sup/tagger.rb
sup-0.8.1 lib/sup/tagger.rb
sup-0.5 lib/sup/tagger.rb
sup-0.6 lib/sup/tagger.rb