Module: Rum::Commands
- Defined in:
- lib/rum/barrel.rb
Defined Under Namespace
Classes: Command
Constant Summary collapse
- TIMER_DURATION =
10
Class Attribute Summary collapse
-
.commands ⇒ Object
Returns the value of attribute commands.
-
.default_tag ⇒ Object
Returns the value of attribute default_tag.
Class Method Summary collapse
- .[](tag = nil) ⇒ Object
- .command(name, *args, &block) ⇒ Object
- .for_active_window ⇒ Object
- .select(tag = nil) ⇒ Object
- .select_command(commands) ⇒ Object
- .visit_next_command ⇒ Object
Class Attribute Details
.commands ⇒ Object
Returns the value of attribute commands.
104 105 106 |
# File 'lib/rum/barrel.rb', line 104 def commands @commands end |
.default_tag ⇒ Object
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 = [] << tag if tag << default_tag .uniq! location = FileLocation.from_stack_frame(caller.first) if args and (hotkey = args[:hotkey]) apps = .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) .each do |tag| commands_for_tag = (@commands[tag] ||= {}) commands_for_tag[name] = cmd end end |
.for_active_window ⇒ Object
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_command ⇒ Object
157 158 159 |
# File 'lib/rum/barrel.rb', line 157 def visit_next_command @visit_timer = Time.now end |