… | |
… | |
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 | |
… | |
… | |
195 | 0 |
192 | 0 |
196 | }, |
193 | }, |
197 | ); |
194 | ); |
198 | |
195 | |
199 | $list->add (new CFPlus::UI::FancyFrame |
196 | $list->add (new CFPlus::UI::FancyFrame |
200 | label => "Bindings", |
197 | label => "Macros", |
201 | child => (my $macros = new CFPlus::UI::Table), |
198 | child => (my $macros = new CFPlus::UI::VBox), |
202 | ); |
199 | ); |
203 | |
200 | |
204 | my $refresh; |
201 | my $refresh; |
205 | |
202 | |
206 | my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; |
203 | my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; |
… | |
… | |
285 | } |
282 | } |
286 | }, |
283 | }, |
287 | ); |
284 | ); |
288 | }; |
285 | }; |
289 | |
286 | |
|
|
287 | $macros->add (new CFPlus::UI::Button |
|
|
288 | text => "New Macro", |
|
|
289 | tooltip => "Creates a new, empty, macro you can edit.", |
|
|
290 | on_activate => sub { |
|
|
291 | my $macro = { }; |
|
|
292 | push @{ $::PROFILE->{macro} }, $macro; |
|
|
293 | $edit_macro->($macro); |
|
|
294 | }, |
|
|
295 | ); |
|
|
296 | |
|
|
297 | $macros->add (my $macrolist = new CFPlus::UI::Table col_expand => [0, 1]); |
|
|
298 | |
290 | $REFRESH_MACRO_LIST = $refresh = sub { |
299 | $REFRESH_MACRO_LIST = $refresh = sub { |
291 | $macros->clear; |
300 | $macrolist->clear; |
292 | |
301 | |
293 | $macros->add (0, 0, new CFPlus::UI::Label |
302 | $macrolist->add (0, 1, new CFPlus::UI::Label |
294 | text => "Trigger", |
303 | text => "Trigger", |
295 | align => 0, |
304 | align => 0, |
296 | tooltip => $tooltip_trigger . $tooltip_common, |
305 | tooltip => $tooltip_trigger . $tooltip_common, |
297 | ); |
306 | ); |
298 | $macros->add (1, 0, new CFPlus::UI::Label |
307 | $macrolist->add (1, 1, new CFPlus::UI::Label |
299 | text => "Commands", |
308 | text => "Commands", |
300 | tooltip => $tooltip_commands . $tooltip_common, |
309 | tooltip => $tooltip_commands . $tooltip_common, |
301 | ); |
310 | ); |
302 | |
311 | |
303 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
312 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
304 | my $macro = $::PROFILE->{macro}[$idx]; |
313 | my $macro = $::PROFILE->{macro}[$idx]; |
305 | my $y = $idx + 1; |
314 | my $y = $idx + 2; |
306 | |
315 | |
307 | my $macro_cb = sub { |
316 | my $macro_cb = sub { |
308 | my ($widget, $ev) = @_; |
317 | my ($widget, $ev) = @_; |
309 | |
318 | |
310 | if ($ev->{button} == 1) { |
319 | if ($ev->{button} == 1) { |
… | |
… | |
328 | } |
337 | } |
329 | |
338 | |
330 | 1 |
339 | 1 |
331 | }; |
340 | }; |
332 | |
341 | |
333 | $macros->add (0, $y, new CFPlus::UI::Label |
342 | $macrolist->add (0, $y, new CFPlus::UI::Label |
334 | text => trigger_to_string $macro, |
343 | text => trigger_to_string $macro, |
335 | tooltip => $tooltip_trigger . $tooltip_common, |
344 | tooltip => $tooltip_trigger . $tooltip_common, |
336 | align => 0, |
345 | align => 0, |
337 | can_hover => 1, |
346 | can_hover => 1, |
338 | can_events => 1, |
347 | can_events => 1, |
339 | on_button_down => $macro_cb, |
348 | on_button_down => $macro_cb, |
340 | ); |
349 | ); |
341 | |
350 | |
342 | $macros->add (1, $y, new CFPlus::UI::Label |
351 | $macrolist->add (1, $y, new CFPlus::UI::Label |
343 | text => (join "; ", @{ $macro->{action} }), |
352 | text => (join "; ", @{ $macro->{action} || [] }), |
344 | tooltip => $tooltip_commands . $tooltip_common, |
353 | tooltip => $tooltip_commands . $tooltip_common, |
345 | expand => 1, |
354 | expand => 1, |
346 | ellipsise => 3, |
355 | ellipsise => 3, |
347 | can_hover => 1, |
356 | can_hover => 1, |
348 | can_events => 1, |
357 | can_events => 1, |
… | |
… | |
357 | } |
366 | } |
358 | |
367 | |
359 | # this is a shortcut method that asks for a binding |
368 | # this is a shortcut method that asks for a binding |
360 | # and then just binds it. |
369 | # and then just binds it. |
361 | sub quick_macro { |
370 | sub quick_macro { |
362 | my ($self, $cmds, $end_cb) = @_; |
371 | my ($cmds, $end_cb) = @_; |
363 | |
372 | |
364 | my $macro = { |
373 | my $macro = { |
365 | action => $cmds, |
374 | action => $cmds, |
366 | }; |
375 | }; |
367 | |
376 | |
368 | trigger_edit $macro, sub { |
377 | trigger_edit $macro, sub { |
369 | |
|
|
370 | if ($_[0]) { |
378 | if ($_[0]) { |
371 | push @{ $::PROFILE->{macro} }, $macro; |
379 | push @{ $::PROFILE->{macro} }, $macro; |
372 | $REFRESH_MACRO_LIST->(); |
380 | $REFRESH_MACRO_LIST->(); |
373 | } |
381 | } |
374 | |
382 | |