… | |
… | |
192 | 0 |
192 | 0 |
193 | }, |
193 | }, |
194 | ); |
194 | ); |
195 | |
195 | |
196 | $list->add (new CFPlus::UI::FancyFrame |
196 | $list->add (new CFPlus::UI::FancyFrame |
197 | label => "Bindings", |
197 | label => "Macros", |
198 | child => (my $macros = new CFPlus::UI::Table), |
198 | child => (my $macros = new CFPlus::UI::VBox), |
199 | ); |
199 | ); |
200 | |
200 | |
201 | my $refresh; |
201 | my $refresh; |
202 | |
202 | |
203 | 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>"; |
… | |
… | |
269 | my ($widget) = @_; |
269 | my ($widget) = @_; |
270 | |
270 | |
271 | $recording = $::CONN && !$recording; |
271 | $recording = $::CONN && !$recording; |
272 | if ($recording) { |
272 | if ($recording) { |
273 | $widget->set_text ("Stop Recording"); |
273 | $widget->set_text ("Stop Recording"); |
274 | my $action = $macro->{action} ||= []; |
|
|
275 | $::CONN->record (sub { |
274 | $::CONN->record (sub { |
276 | push @$action, $_[0]; |
275 | push @{ $macro->{action} }, $_[0]; |
277 | $textedit->set_text (macro_to_text $macro); |
276 | $textedit->set_text (macro_to_text $macro); |
278 | }) if $::CONN; |
277 | }) if $::CONN; |
279 | } else { |
278 | } else { |
280 | $widget->set_text ("Start Recording"); |
279 | $widget->set_text ("Start Recording"); |
281 | $::CONN->record if $::CONN; |
280 | $::CONN->record if $::CONN; |
282 | } |
281 | } |
283 | }, |
282 | }, |
284 | ); |
283 | ); |
285 | }; |
284 | }; |
286 | |
285 | |
|
|
286 | $macros->add (new CFPlus::UI::Button |
|
|
287 | text => "New Macro", |
|
|
288 | tooltip => "Creates a new, empty, macro you can edit.", |
|
|
289 | on_activate => sub { |
|
|
290 | my $macro = { }; |
|
|
291 | push @{ $::PROFILE->{macro} }, $macro; |
|
|
292 | $edit_macro->($macro); |
|
|
293 | }, |
|
|
294 | ); |
|
|
295 | |
|
|
296 | $macros->add (my $macrolist = new CFPlus::UI::Table col_expand => [0, 1]); |
|
|
297 | |
287 | $REFRESH_MACRO_LIST = $refresh = sub { |
298 | $REFRESH_MACRO_LIST = $refresh = sub { |
288 | $macros->clear; |
299 | $macrolist->clear; |
289 | |
300 | |
290 | $macros->add (0, 0, new CFPlus::UI::Label |
301 | $macrolist->add_at (0, 1, new CFPlus::UI::Label |
291 | text => "Trigger", |
302 | text => "Trigger", |
292 | align => 0, |
303 | align => 0, |
293 | tooltip => $tooltip_trigger . $tooltip_common, |
304 | tooltip => $tooltip_trigger . $tooltip_common, |
294 | ); |
305 | ); |
295 | $macros->add (1, 0, new CFPlus::UI::Label |
306 | $macrolist->add_at (1, 1, new CFPlus::UI::Label |
296 | text => "Commands", |
307 | text => "Commands", |
297 | tooltip => $tooltip_commands . $tooltip_common, |
308 | tooltip => $tooltip_commands . $tooltip_common, |
298 | ); |
309 | ); |
299 | |
310 | |
300 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
311 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
301 | my $macro = $::PROFILE->{macro}[$idx]; |
312 | my $macro = $::PROFILE->{macro}[$idx]; |
302 | my $y = $idx + 1; |
313 | my $y = $idx + 2; |
303 | |
314 | |
304 | my $macro_cb = sub { |
315 | my $macro_cb = sub { |
305 | my ($widget, $ev) = @_; |
316 | my ($widget, $ev) = @_; |
306 | |
317 | |
307 | if ($ev->{button} == 1) { |
318 | if ($ev->{button} == 1) { |
… | |
… | |
325 | } |
336 | } |
326 | |
337 | |
327 | 1 |
338 | 1 |
328 | }; |
339 | }; |
329 | |
340 | |
330 | $macros->add (0, $y, new CFPlus::UI::Label |
341 | $macrolist->add_at (0, $y, new CFPlus::UI::Label |
331 | text => trigger_to_string $macro, |
342 | text => trigger_to_string $macro, |
332 | tooltip => $tooltip_trigger . $tooltip_common, |
343 | tooltip => $tooltip_trigger . $tooltip_common, |
333 | align => 0, |
344 | align => 0, |
334 | can_hover => 1, |
345 | can_hover => 1, |
335 | can_events => 1, |
346 | can_events => 1, |
336 | on_button_down => $macro_cb, |
347 | on_button_down => $macro_cb, |
337 | ); |
348 | ); |
338 | |
349 | |
339 | $macros->add (1, $y, new CFPlus::UI::Label |
350 | $macrolist->add_at (1, $y, new CFPlus::UI::Label |
340 | text => (join "; ", @{ $macro->{action} || [] }), |
351 | text => (join "; ", @{ $macro->{action} || [] }), |
341 | tooltip => $tooltip_commands . $tooltip_common, |
352 | tooltip => $tooltip_commands . $tooltip_common, |
342 | expand => 1, |
353 | expand => 1, |
343 | ellipsise => 3, |
354 | ellipsise => 3, |
344 | can_hover => 1, |
355 | can_hover => 1, |