… | |
… | |
157 | $window->grab_focus; |
157 | $window->grab_focus; |
158 | $window->show; |
158 | $window->show; |
159 | } |
159 | } |
160 | |
160 | |
161 | # find macro by event |
161 | # find macro by event |
162 | # maybe return multiple results? |
|
|
163 | sub match_event($) { |
162 | sub match_event($) { |
164 | my ($ev) = @_; |
163 | my ($ev) = @_; |
165 | |
164 | |
166 | for my $macro (@{ $::PROFILE->{macro} || [] }) { |
165 | grep { |
167 | my $key = $macro->{accelkey} |
166 | if (my $key = $_->{accelkey}) { |
168 | or next; |
|
|
169 | |
|
|
170 | $key->[1] == $ev->{sym} |
167 | $key->[1] == $ev->{sym} |
171 | && $key->[0] == ($ev->{mod} & $MODIFIER_MASK) |
168 | && $key->[0] == ($ev->{mod} & $MODIFIER_MASK) |
172 | && return $macro; |
169 | } else { |
173 | } |
170 | 0 |
174 | |
171 | } |
175 | () |
172 | } @{ $::PROFILE->{macro} || [] } |
176 | } |
173 | } |
177 | |
174 | |
178 | sub keyboard_setup { |
175 | sub keyboard_setup { |
179 | my $kbd_setup = new CFPlus::UI::VBox; |
176 | my $kbd_setup = new CFPlus::UI::VBox; |
180 | |
177 | |
… | |
… | |
338 | can_events => 1, |
335 | can_events => 1, |
339 | on_button_down => $macro_cb, |
336 | on_button_down => $macro_cb, |
340 | ); |
337 | ); |
341 | |
338 | |
342 | $macros->add (1, $y, new CFPlus::UI::Label |
339 | $macros->add (1, $y, new CFPlus::UI::Label |
343 | text => (join "; ", @{ $macro->{action} }), |
340 | text => (join "; ", @{ $macro->{action} || [] }), |
344 | tooltip => $tooltip_commands . $tooltip_common, |
341 | tooltip => $tooltip_commands . $tooltip_common, |
345 | expand => 1, |
342 | expand => 1, |
346 | ellipsise => 3, |
343 | ellipsise => 3, |
347 | can_hover => 1, |
344 | can_hover => 1, |
348 | can_events => 1, |
345 | can_events => 1, |
… | |
… | |
357 | } |
354 | } |
358 | |
355 | |
359 | # this is a shortcut method that asks for a binding |
356 | # this is a shortcut method that asks for a binding |
360 | # and then just binds it. |
357 | # and then just binds it. |
361 | sub quick_macro { |
358 | sub quick_macro { |
362 | my ($self, $cmds, $end_cb) = @_; |
359 | my ($cmds, $end_cb) = @_; |
363 | |
360 | |
364 | my $macro = { |
361 | my $macro = { |
365 | action => $cmds, |
362 | action => $cmds, |
366 | }; |
363 | }; |
367 | |
364 | |
368 | trigger_edit $macro, sub { |
365 | trigger_edit $macro, sub { |
369 | |
|
|
370 | if ($_[0]) { |
366 | if ($_[0]) { |
371 | push @{ $::PROFILE->{macro} }, $macro; |
367 | push @{ $::PROFILE->{macro} }, $macro; |
372 | $REFRESH_MACRO_LIST->(); |
368 | $REFRESH_MACRO_LIST->(); |
373 | } |
369 | } |
374 | |
370 | |