Class: Merrol::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/merrol/lib/commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ Commands

Returns a new instance of Commands.



3
4
5
6
7
# File 'lib/merrol/lib/commands.rb', line 3

def initialize(window)
  @accel_group = Gtk::AccelGroup.new
  window.add_accel_group @accel_group
  load
end

Instance Method Details

#register(controller) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/merrol/lib/commands.rb', line 9

def register controller
  @commands[controller.name.to_s].each do |command, detail|
    if detail['key'] =~ /TAB/
      Gtk::Window.toplevels.first.signal_connect('key_press_event') do |widget, event|
        if detail['key'] == Shortcut.from(event)
          controller.send(command)
        else
          false
        end
      end
    else
      @accel_group.connect "<#{APP_NAME}>/#{controller.name}/#{command}" do
        controller.send(command)
      end
    end
  end
end