Module: Rum::Commands

Defined in:
lib/rum/barrel.rb

Defined Under Namespace

Classes: Command

Constant Summary collapse

TIMER_DURATION =
10

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.commandsObject

Returns the value of attribute commands.



104
105
106
# File 'lib/rum/barrel.rb', line 104

def commands
  @commands
end

.default_tagObject

Returns the value of attribute default_tag.



103
104
105
# File 'lib/rum/barrel.rb', line 103

def default_tag
  @default_tag
end

Class Method Details

.[](tag = nil) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/rum/barrel.rb', line 132

def [] (tag=nil)
  if (cmds = @commands[tag])
    cmds.values
  else
    []
  end
end

.command(name, *args, &block) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/rum/barrel.rb', line 107

def command(name, *args, &block)
  args = args.first
  tag = args[:tag] if args
  tags = []
  tags << tag if tag
  tags << default_tag
  tags.uniq!

  location = FileLocation.from_stack_frame(caller.first)

  if args and (hotkey = args[:hotkey])
    apps = tags.select { |tag| tag.is_a? App }
    apps.each do |app|
      action = hotkey.do(app, &block)
      action.location = location
    end
  end

  cmd = Command.new(name, block, location)
  tags.each do |tag|
    commands_for_tag = (@commands[tag] ||= {})
    commands_for_tag[name] = cmd
  end
end

.for_active_windowObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/rum/barrel.rb', line 161

def for_active_window
  cmds = []
  exe = active_window.exe_name
  app = App.for_exe(exe)
  cmds.concat self[app] if app
  if (dir = AppDir.get(exe))
    cmds.concat Path.contents(dir)
  end
  if (chosen = select_command(cmds))
    case chosen
    when String
      Path.run(dir + chosen)
    else
      chosen.run
    end
  end
end

.select(tag = nil) ⇒ Object



140
141
142
143
# File 'lib/rum/barrel.rb', line 140

def select(tag=nil)
  cmd = select_command(self[tag])
  cmd.run if cmd
end

.select_command(commands) ⇒ Object



146
147
148
149
150
151
152
153
154
155
# File 'lib/rum/barrel.rb', line 146

def select_command(commands)
  cmd = Gui.choose(nil, commands)
  if @visit_timer
    timer_active = (Time.now-@visit_timer) <= TIMER_DURATION
    cmd.visit if cmd and timer_active
    @visit_timer = nil
  else
    cmd
  end
end

.visit_next_commandObject



157
158
159
# File 'lib/rum/barrel.rb', line 157

def visit_next_command
  @visit_timer = Time.now
end