1 | package CFPlus::Macro; |
1 | package DC::Macro; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use List::Util (); |
5 | use List::Util (); |
6 | use CFPlus::UI; |
6 | use DC::UI; |
7 | |
7 | |
8 | our $REFRESH_MACRO_LIST; |
8 | our $REFRESH_MACRO_LIST; |
9 | |
9 | |
10 | our %DEFAULT_KEYMAP = ( |
10 | our %DEFAULT_KEYMAP = ( |
11 | (map +("($_)" => "!completer $_"), "a" .. "z"), |
11 | (map +("($_)" => "!completer $_"), "a" .. "z"), |
… | |
… | |
22 | "f4" => "!toggle-spells", |
22 | "f4" => "!toggle-spells", |
23 | "f5" => "!toggle-inventory", |
23 | "f5" => "!toggle-inventory", |
24 | "f9" => "!toggle-setup", |
24 | "f9" => "!toggle-setup", |
25 | (map +("LAlt-$_" => "!switch-tab $_"), 0..9), |
25 | (map +("LAlt-$_" => "!switch-tab $_"), 0..9), |
26 | (map +("RAlt-$_" => "!switch-tab $_"), 0..9), |
26 | (map +("RAlt-$_" => "!switch-tab $_"), 0..9), |
|
|
27 | "LAlt-x" => "!close-current-tab", |
27 | "return" => "!activate-chat", |
28 | "return" => "!activate-chat", |
28 | "." => "!repeat-command", |
29 | "." => "!repeat-command", |
29 | |
30 | |
30 | "," => "take", |
31 | "," => "take", |
31 | "space" => "apply", |
32 | "space" => "apply", |
32 | "enter" => "examine", |
33 | "enter" => "examine", |
33 | "[+]" => "rotateshoottype +", |
34 | "[+]" => "rotateshoottype +", |
34 | "[-]" => "rotateshoottype -", |
35 | "[-]" => "rotateshoottype -", |
|
|
36 | "LAlt-e" => "examine", |
35 | "LAlt-s" => "ready_skill find traps", |
37 | "LAlt-s" => "ready_skill find traps", |
36 | "LAlt-d" => "ready_skill disarm traps", |
38 | "LAlt-d" => "ready_skill disarm traps", |
37 | "LAlt-p" => "ready_skill praying", |
39 | "LAlt-p" => "ready_skill praying", |
38 | ); |
40 | ); |
39 | |
41 | |
40 | # allowed modifiers |
42 | # allowed modifiers |
41 | our %MODIFIER = ( |
43 | our %MODIFIER = ( |
42 | "LShift" => CFPlus::KMOD_LSHIFT, |
44 | "LShift" => DC::KMOD_LSHIFT, |
43 | "RShift" => CFPlus::KMOD_RSHIFT, |
45 | "RShift" => DC::KMOD_RSHIFT, |
44 | # "Shift" => CFPlus::KMOD_LSHIFT | CFPlus::KMOD_RSHIFT, |
46 | # "Shift" => DC::KMOD_LSHIFT | DC::KMOD_RSHIFT, |
45 | "LCtrl" => CFPlus::KMOD_LCTRL, |
47 | "LCtrl" => DC::KMOD_LCTRL, |
46 | "RCtrl" => CFPlus::KMOD_RCTRL, |
48 | "RCtrl" => DC::KMOD_RCTRL, |
47 | # "Ctrl" => CFPlus::KMOD_LCTRL | CFPlus::KMOD_RCTRL, |
49 | # "Ctrl" => DC::KMOD_LCTRL | DC::KMOD_RCTRL, |
48 | "LAlt" => CFPlus::KMOD_LALT, |
50 | "LAlt" => DC::KMOD_LALT, |
49 | "RAlt" => CFPlus::KMOD_RALT, |
51 | "RAlt" => DC::KMOD_RALT, |
50 | # "Alt" => CFPlus::KMOD_LALT | CFPlus::KMOD_RALT, |
52 | # "Alt" => DC::KMOD_LALT | DC::KMOD_RALT, |
51 | "LMeta" => CFPlus::KMOD_LMETA, |
53 | "LMeta" => DC::KMOD_LMETA, |
52 | "RMeta" => CFPlus::KMOD_RMETA, |
54 | "RMeta" => DC::KMOD_RMETA, |
53 | # "Meta" => CFPlus::KMOD_LMETA | CFPlus::KMOD_RMETA, |
55 | # "Meta" => DC::KMOD_LMETA | DC::KMOD_RMETA, |
54 | ); |
56 | ); |
55 | |
57 | |
56 | # allowed modifiers |
58 | # allowed modifiers |
57 | our $MODIFIER_MASK |= $_ for values %MODIFIER; |
59 | our $MODIFIER_MASK |= $_ for values %MODIFIER; |
58 | |
60 | |
59 | # can bind to these without any modifier |
61 | # can bind to these without any modifier |
60 | our @DIRECT_CHARS = qw(0 1 2 3 4 5 6 7 8 9); |
62 | our @DIRECT_CHARS = qw(0 1 2 3 4 5 6 7 8 9); |
61 | |
63 | |
62 | our @DIRECT_KEYS = ( |
64 | our @DIRECT_KEYS = ( |
63 | CFPlus::SDLK_F1, |
65 | DC::SDLK_F1, |
64 | CFPlus::SDLK_F2, |
66 | DC::SDLK_F2, |
65 | CFPlus::SDLK_F3, |
67 | DC::SDLK_F3, |
66 | CFPlus::SDLK_F4, |
68 | DC::SDLK_F4, |
67 | CFPlus::SDLK_F5, |
69 | DC::SDLK_F5, |
68 | CFPlus::SDLK_F6, |
70 | DC::SDLK_F6, |
69 | CFPlus::SDLK_F7, |
71 | DC::SDLK_F7, |
70 | CFPlus::SDLK_F8, |
72 | DC::SDLK_F8, |
71 | CFPlus::SDLK_F9, |
73 | DC::SDLK_F9, |
72 | CFPlus::SDLK_F10, |
74 | DC::SDLK_F10, |
73 | CFPlus::SDLK_F11, |
75 | DC::SDLK_F11, |
74 | CFPlus::SDLK_F12, |
76 | DC::SDLK_F12, |
75 | CFPlus::SDLK_F13, |
77 | DC::SDLK_F13, |
76 | CFPlus::SDLK_F14, |
78 | DC::SDLK_F14, |
77 | CFPlus::SDLK_F15, |
79 | DC::SDLK_F15, |
78 | ); |
80 | ); |
79 | |
81 | |
80 | our %MACRO_FUNCTION = ( |
82 | our %MACRO_FUNCTION = ( |
81 | "toggle-messagewindow" => sub { $::MESSAGE_WINDOW->toggle_visibility }, |
83 | "toggle-messagewindow" => sub { $::MESSAGE_WINDOW->toggle_visibility }, |
82 | "toggle-playerbook" => sub { $::PL_WINDOW->toggle_visibility }, |
84 | "toggle-playerbook" => sub { $::PL_WINDOW->toggle_visibility }, |
… | |
… | |
87 | "toggle-inventory" => sub { ::toggle_player_page ($::INVENTORY_PAGE) }, |
89 | "toggle-inventory" => sub { ::toggle_player_page ($::INVENTORY_PAGE) }, |
88 | "toggle-pickup" => sub { ::toggle_player_page ($::PICKUP_PAGE) }, |
90 | "toggle-pickup" => sub { ::toggle_player_page ($::PICKUP_PAGE) }, |
89 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
91 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
90 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
92 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
91 | "switch-tab" => sub { $::MESSAGE_WINDOW->user_switch_to_page (0 + shift) }, |
93 | "switch-tab" => sub { $::MESSAGE_WINDOW->user_switch_to_page (0 + shift) }, |
|
|
94 | "close-current-tab" => sub { $::MESSAGE_WINDOW->close_current_tab }, |
92 | "activate-chat" => sub { $::MESSAGE_WINDOW->activate_current }, |
95 | "activate-chat" => sub { $::MESSAGE_WINDOW->activate_current }, |
93 | "repeat-command" => sub { |
96 | "repeat-command" => sub { |
94 | $::CONN->user_send ($::COMPLETER->{last_command}) |
97 | $::CONN->user_send ($::COMPLETER->{last_command}) |
95 | if $::CONN && exists $::COMPLETER->{last_command}; |
98 | if $::CONN && exists $::COMPLETER->{last_command}; |
96 | }, |
99 | }, |
… | |
… | |
104 | |
107 | |
105 | our $DEFAULT_KEYMAP; |
108 | our $DEFAULT_KEYMAP; |
106 | |
109 | |
107 | sub init { |
110 | sub init { |
108 | $DEFAULT_KEYMAP ||= do { |
111 | $DEFAULT_KEYMAP ||= do { |
109 | my %sym = map +(CFPlus::SDL_GetKeyName $_, $_), CFPlus::SDLK_FIRST .. CFPlus::SDLK_LAST; |
112 | my %sym = map +(DC::SDL_GetKeyName $_, $_), DC::SDLK_FIRST .. DC::SDLK_LAST; |
110 | my $map; |
113 | my $map; |
111 | |
114 | |
112 | while (my ($k, $v) = each %DEFAULT_KEYMAP) { |
115 | while (my ($k, $v) = each %DEFAULT_KEYMAP) { |
113 | if ($k =~ /^\((.)\)$/) { |
116 | if ($k =~ /^\((.)\)$/) { |
114 | $map->{U}{ord $1} = $v; |
117 | $map->{U}{ord $1} = $v; |
… | |
… | |
117 | my $sym = $sym{pop @mod} |
120 | my $sym = $sym{pop @mod} |
118 | or warn "unknown keysym $k\n"; |
121 | or warn "unknown keysym $k\n"; |
119 | |
122 | |
120 | my $mod = 0; $mod |= $MODIFIER{$_} for @mod; |
123 | my $mod = 0; $mod |= $MODIFIER{$_} for @mod; |
121 | |
124 | |
122 | $map->{K}[CFPlus::popcount $mod]{$mod}{$sym} = $v; |
125 | $map->{K}[DC::popcount $mod]{$mod}{$sym} = $v; |
123 | } |
126 | } |
124 | } |
127 | } |
125 | |
128 | |
126 | %DEFAULT_KEYMAP = (); |
129 | %DEFAULT_KEYMAP = (); |
127 | $map |
130 | $map |
… | |
… | |
129 | } |
132 | } |
130 | |
133 | |
131 | sub accelkey_to_string($) { |
134 | sub accelkey_to_string($) { |
132 | join "-", |
135 | join "-", |
133 | (grep $_[0][0] & $MODIFIER{$_}, keys %MODIFIER), |
136 | (grep $_[0][0] & $MODIFIER{$_}, keys %MODIFIER), |
134 | CFPlus::SDL_GetKeyName $_[0][1] |
137 | DC::SDL_GetKeyName $_[0][1] |
135 | } |
138 | } |
136 | |
139 | |
137 | sub trigger_to_string($) { |
140 | sub trigger_to_string($) { |
138 | my ($macro) = @_; |
141 | my ($macro) = @_; |
139 | |
142 | |
… | |
… | |
166 | $window->disconnect_all ("focus_out"); |
169 | $window->disconnect_all ("focus_out"); |
167 | $window->destroy; |
170 | $window->destroy; |
168 | &$end_cb; |
171 | &$end_cb; |
169 | }; |
172 | }; |
170 | |
173 | |
171 | $window = new CFPlus::UI::Toplevel |
174 | $window = new DC::UI::Toplevel |
172 | title => "Edit Macro Trigger", |
175 | title => "Edit Macro Trigger", |
173 | x => "center", |
176 | x => "center", |
174 | y => "center", |
177 | y => "center", |
175 | z => 1000, |
178 | z => 1000, |
176 | can_events => 1, |
179 | can_events => 1, |
… | |
… | |
184 | $done->(0); |
187 | $done->(0); |
185 | 1 |
188 | 1 |
186 | }, |
189 | }, |
187 | ; |
190 | ; |
188 | |
191 | |
189 | $window->add (my $vb = new CFPlus::UI::VBox); |
192 | $window->add (my $vb = new DC::UI::VBox); |
190 | |
193 | |
191 | $vb->add (new CFPlus::UI::Label |
194 | $vb->add (new DC::UI::Label |
192 | text => "To bind the macro to a key,\n" |
195 | text => "To bind the macro to a key,\n" |
193 | . "press a modifier (Ctrl, Alt\n" |
196 | . "press a modifier (Ctrl, Alt\n" |
194 | . "and/or Shift) and a key, or\n" |
197 | . "and/or Shift) and a key, or\n" |
195 | . "0-9 and F1-F15 without any modifier\n\n" |
198 | . "0-9 and F1-F15 without any modifier\n\n" |
196 | . "To cancel press Escape or close this.\n\n" |
199 | . "To cancel press Escape or close this.\n\n" |
197 | . "Accelerator key combo:", |
200 | . "Accelerator key combo:", |
198 | ellipsise => 0, |
201 | ellipsise => 0, |
199 | ); |
202 | ); |
200 | |
203 | |
201 | $vb->add (my $entry = new CFPlus::UI::Label |
204 | $vb->add (my $entry = new DC::UI::Label |
202 | fg => [0, 0, 0, 1], |
205 | fg => [0, 0, 0, 1], |
203 | bg => [1, 1, 0, 1], |
206 | bg => [1, 1, 0, 1], |
204 | ); |
207 | ); |
205 | |
208 | |
206 | my $key_cb = sub { |
209 | my $key_cb = sub { |
… | |
… | |
219 | map "$_-", |
222 | map "$_-", |
220 | grep $mod & $MODIFIER{$_}, |
223 | grep $mod & $MODIFIER{$_}, |
221 | keys %MODIFIER |
224 | keys %MODIFIER |
222 | ); |
225 | ); |
223 | |
226 | |
224 | return if $sym >= CFPlus::SDLK_MODIFIER_MIN |
227 | return if $sym >= DC::SDLK_MODIFIER_MIN |
225 | && $sym <= CFPlus::SDLK_MODIFIER_MAX; |
228 | && $sym <= DC::SDLK_MODIFIER_MAX; |
226 | |
229 | |
227 | if ($mod |
230 | if ($mod |
228 | || ((grep $_ eq chr $ev->{unicode}, @DIRECT_CHARS) |
231 | || ((grep $_ eq chr $ev->{unicode}, @DIRECT_CHARS) |
229 | || (grep $_ == $sym, @DIRECT_KEYS))) |
232 | || (grep $_ == $sym, @DIRECT_KEYS))) |
230 | { |
233 | { |
231 | $macro->{accelkey} = [$mod, $sym]; |
234 | $macro->{accelkey} = [$mod, $sym]; |
232 | $done->(1); |
235 | $done->(1); |
233 | } else { |
236 | } else { |
234 | $entry->set_text ("cannot bind " . (CFPlus::SDL_GetKeyName $sym) . " without modifier."); |
237 | $entry->set_text ("cannot bind " . (DC::SDL_GetKeyName $sym) . " without modifier."); |
235 | } |
238 | } |
236 | 1 |
239 | 1 |
237 | }; |
240 | }; |
238 | |
241 | |
239 | $window->connect (key_up => $key_cb); |
242 | $window->connect (key_up => $key_cb); |
… | |
… | |
243 | $window->show; |
246 | $window->show; |
244 | } |
247 | } |
245 | |
248 | |
246 | sub find_default($) { |
249 | sub find_default($) { |
247 | my ($ev) = @_; |
250 | my ($ev) = @_; |
248 | |
|
|
249 | if (my $cmd = $DEFAULT_KEYMAP->{U}{$ev->{unicode}}) { |
|
|
250 | return $cmd; |
|
|
251 | } |
|
|
252 | |
251 | |
253 | for my $m (reverse grep $_, @{ $DEFAULT_KEYMAP->{K} }) { |
252 | for my $m (reverse grep $_, @{ $DEFAULT_KEYMAP->{K} }) { |
254 | for (keys %$m) { |
253 | for (keys %$m) { |
255 | if ($_ == ($ev->{mod} & $_)) { |
254 | if ($_ == ($ev->{mod} & $_)) { |
256 | if (defined (my $cmd = $m->{$_}{$ev->{sym}})) { |
255 | if (defined (my $cmd = $m->{$_}{$ev->{sym}})) { |
257 | return $cmd; |
256 | return $cmd; |
258 | } |
257 | } |
259 | } |
258 | } |
260 | } |
259 | } |
|
|
260 | } |
|
|
261 | |
|
|
262 | if (my $cmd = $DEFAULT_KEYMAP->{U}{$ev->{unicode}}) { |
|
|
263 | return $cmd; |
261 | } |
264 | } |
262 | |
265 | |
263 | () |
266 | () |
264 | } |
267 | } |
265 | |
268 | |
… | |
… | |
304 | } |
307 | } |
305 | } |
308 | } |
306 | } |
309 | } |
307 | |
310 | |
308 | sub keyboard_setup { |
311 | sub keyboard_setup { |
309 | my $kbd_setup = new CFPlus::UI::VBox; |
312 | my $kbd_setup = new DC::UI::VBox; |
310 | |
313 | |
311 | $kbd_setup->add (my $list = new CFPlus::UI::VBox); |
314 | $kbd_setup->add (my $list = new DC::UI::VBox); |
312 | |
315 | |
313 | $list->add (new CFPlus::UI::FancyFrame |
316 | $list->add (new DC::UI::FancyFrame |
314 | label => "Options", |
317 | label => "Options", |
315 | child => (my $hb = new CFPlus::UI::HBox), |
318 | child => (my $hb = new DC::UI::HBox), |
316 | ); |
319 | ); |
317 | $hb->add (new CFPlus::UI::Label text => "only shift-up stops fire"); |
320 | $hb->add (new DC::UI::Label text => "only shift-up stops fire"); |
318 | $hb->add (new CFPlus::UI::CheckBox |
321 | $hb->add (new DC::UI::CheckBox |
319 | expand => 1, |
322 | expand => 1, |
320 | state => $::CFG->{shift_fire_stop}, |
323 | state => $::CFG->{shift_fire_stop}, |
321 | tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift.", |
324 | tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift.", |
322 | on_changed => sub { |
325 | on_changed => sub { |
323 | my ($cbox, $value) = @_; |
326 | my ($cbox, $value) = @_; |
324 | $::CFG->{shift_fire_stop} = $value; |
327 | $::CFG->{shift_fire_stop} = $value; |
325 | 0 |
328 | 0 |
326 | }, |
329 | }, |
327 | ); |
330 | ); |
328 | |
331 | |
329 | $list->add (new CFPlus::UI::FancyFrame |
332 | $list->add (new DC::UI::FancyFrame |
330 | label => "Macros", |
333 | label => "Macros", |
331 | child => (my $macros = new CFPlus::UI::VBox), |
334 | child => (my $macros = new DC::UI::VBox), |
332 | ); |
335 | ); |
333 | |
336 | |
334 | my $refresh; |
337 | my $refresh; |
335 | |
338 | |
336 | my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; |
339 | my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; |
… | |
… | |
339 | |
342 | |
340 | my $edit_macro = sub { |
343 | my $edit_macro = sub { |
341 | my ($macro) = @_; |
344 | my ($macro) = @_; |
342 | |
345 | |
343 | $kbd_setup->clear; |
346 | $kbd_setup->clear; |
344 | $kbd_setup->add (new CFPlus::UI::Button |
347 | $kbd_setup->add (new DC::UI::Button |
345 | text => "Return", |
348 | text => "Return", |
346 | tooltip => "Return to the macro list.", |
349 | tooltip => "Return to the macro list.", |
347 | on_activate => sub { |
350 | on_activate => sub { |
348 | $kbd_setup->clear; |
351 | $kbd_setup->clear; |
349 | $kbd_setup->add ($list); |
352 | $kbd_setup->add ($list); |
350 | $refresh->(); |
353 | $refresh->(); |
351 | 1 |
354 | 1 |
352 | }, |
355 | }, |
353 | ); |
356 | ); |
354 | $kbd_setup->add (new CFPlus::UI::FancyFrame |
357 | $kbd_setup->add (new DC::UI::FancyFrame |
355 | label => "Edit Macro", |
358 | label => "Edit Macro", |
356 | child => (my $editor = new CFPlus::UI::Table col_expand => [0, 1]), |
359 | child => (my $editor = new DC::UI::Table col_expand => [0, 1]), |
357 | ); |
360 | ); |
358 | |
361 | |
359 | $editor->add_at (0, 1, new CFPlus::UI::Label |
362 | $editor->add_at (0, 1, new DC::UI::Label |
360 | text => "Trigger", |
363 | text => "Trigger", |
361 | tooltip => $tooltip_trigger, |
364 | tooltip => $tooltip_trigger, |
362 | can_hover => 1, |
365 | can_hover => 1, |
363 | can_events => 1, |
366 | can_events => 1, |
364 | ); |
367 | ); |
365 | $editor->add_at (0, 2, new CFPlus::UI::Label |
368 | $editor->add_at (0, 2, new DC::UI::Label |
366 | text => "Actions", |
369 | text => "Actions", |
367 | tooltip => $tooltip_commands, |
370 | tooltip => $tooltip_commands, |
368 | can_hover => 1, |
371 | can_hover => 1, |
369 | can_events => 1, |
372 | can_events => 1, |
370 | ); |
373 | ); |
371 | |
374 | |
372 | $editor->add_at (1, 2, my $textedit = new CFPlus::UI::TextEdit |
375 | $editor->add_at (1, 2, my $textedit = new DC::UI::TextEdit |
373 | text => macro_to_text $macro, |
376 | text => macro_to_text $macro, |
374 | tooltip => $tooltip_commands, |
377 | tooltip => $tooltip_commands, |
375 | on_changed => sub { |
378 | on_changed => sub { |
376 | $macro->{action} = macro_from_text $macro, $_[1]; |
379 | $macro->{action} = macro_from_text $macro, $_[1]; |
377 | }, |
380 | }, |
378 | ); |
381 | ); |
379 | |
382 | |
380 | $editor->add_at (1, 1, my $accel = new CFPlus::UI::Button |
383 | $editor->add_at (1, 1, my $accel = new DC::UI::Button |
381 | text => trigger_to_string $macro, |
384 | text => trigger_to_string $macro, |
382 | tooltip => "To change the trigger for a macro, activate this button.", |
385 | tooltip => "To change the trigger for a macro, activate this button.", |
383 | on_activate => sub { |
386 | on_activate => sub { |
384 | my ($accel) = @_; |
387 | my ($accel) = @_; |
385 | trigger_edit $macro, sub { |
388 | trigger_edit $macro, sub { |
… | |
… | |
388 | 1 |
391 | 1 |
389 | }, |
392 | }, |
390 | ); |
393 | ); |
391 | |
394 | |
392 | my $recording; |
395 | my $recording; |
393 | $editor->add_at (1, 3, new CFPlus::UI::Button |
396 | $editor->add_at (1, 3, new DC::UI::Button |
394 | text => "Start Recording", |
397 | text => "Start Recording", |
395 | tooltip => "Start/Stop command recording: when recording, " |
398 | tooltip => "Start/Stop command recording: when recording, " |
396 | . "actions and commands you invoke are appended to this macro. " |
399 | . "actions and commands you invoke are appended to this macro. " |
397 | . "You can only record when you are logged in.", |
400 | . "You can only record when you are logged in.", |
398 | on_destroy => sub { |
401 | on_destroy => sub { |
… | |
… | |
414 | } |
417 | } |
415 | }, |
418 | }, |
416 | ); |
419 | ); |
417 | }; |
420 | }; |
418 | |
421 | |
419 | $macros->add (new CFPlus::UI::Button |
422 | $macros->add (new DC::UI::Button |
420 | text => "New Macro", |
423 | text => "New Macro", |
421 | tooltip => "Creates a new, empty, macro you can edit.", |
424 | tooltip => "Creates a new, empty, macro you can edit.", |
422 | on_activate => sub { |
425 | on_activate => sub { |
423 | my $macro = { }; |
426 | my $macro = { }; |
424 | push @{ $::PROFILE->{macro} }, $macro; |
427 | push @{ $::PROFILE->{macro} }, $macro; |
425 | $edit_macro->($macro); |
428 | $edit_macro->($macro); |
426 | }, |
429 | }, |
427 | ); |
430 | ); |
428 | |
431 | |
429 | $macros->add (my $macrolist = new CFPlus::UI::Table col_expand => [0, 1]); |
432 | $macros->add (my $macrolist = new DC::UI::Table col_expand => [0, 1]); |
430 | |
433 | |
431 | $REFRESH_MACRO_LIST = $refresh = sub { |
434 | $REFRESH_MACRO_LIST = $refresh = sub { |
432 | $macrolist->clear; |
435 | $macrolist->clear; |
433 | |
436 | |
434 | $macrolist->add_at (0, 1, new CFPlus::UI::Label |
437 | $macrolist->add_at (0, 1, new DC::UI::Label |
435 | text => "Trigger", |
438 | text => "Trigger", |
436 | align => 0, |
439 | align => 0, |
437 | tooltip => $tooltip_trigger . $tooltip_common, |
440 | tooltip => $tooltip_trigger . $tooltip_common, |
438 | ); |
441 | ); |
439 | $macrolist->add_at (1, 1, new CFPlus::UI::Label |
442 | $macrolist->add_at (1, 1, new DC::UI::Label |
440 | text => "Commands", |
443 | text => "Commands", |
441 | tooltip => $tooltip_commands . $tooltip_common, |
444 | tooltip => $tooltip_commands . $tooltip_common, |
442 | ); |
445 | ); |
443 | |
446 | |
444 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
447 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
… | |
… | |
451 | if ($ev->{button} == 1) { |
454 | if ($ev->{button} == 1) { |
452 | $edit_macro->($macro), |
455 | $edit_macro->($macro), |
453 | } elsif ($ev->{button} == 2) { |
456 | } elsif ($ev->{button} == 2) { |
454 | $::CONN->macro_send ($macro) if $::CONN; |
457 | $::CONN->macro_send ($macro) if $::CONN; |
455 | } elsif ($ev->{button} == 3) { |
458 | } elsif ($ev->{button} == 3) { |
456 | (new CFPlus::UI::Menu |
459 | (new DC::UI::Menu |
457 | items => [ |
460 | items => [ |
458 | ["Edit" => sub { $edit_macro->($macro) }], |
461 | ["Edit" => sub { $edit_macro->($macro) }], |
459 | ["Invoke" => sub { $::CONN->macro_send ($macro) if $::CONN }], |
462 | ["Invoke" => sub { $::CONN->macro_send ($macro) if $::CONN }], |
460 | ["Delete" => sub { |
463 | ["Delete" => sub { |
461 | # might want to use grep instead |
464 | # might want to use grep instead |
… | |
… | |
469 | } |
472 | } |
470 | |
473 | |
471 | 1 |
474 | 1 |
472 | }; |
475 | }; |
473 | |
476 | |
474 | $macrolist->add_at (0, $y, new CFPlus::UI::Label |
477 | $macrolist->add_at (0, $y, new DC::UI::Label |
475 | text => trigger_to_string $macro, |
478 | text => trigger_to_string $macro, |
476 | tooltip => $tooltip_trigger . $tooltip_common, |
479 | tooltip => $tooltip_trigger . $tooltip_common, |
477 | align => 0, |
480 | align => 0, |
478 | can_hover => 1, |
481 | can_hover => 1, |
479 | can_events => 1, |
482 | can_events => 1, |
480 | on_button_down => $macro_cb, |
483 | on_button_down => $macro_cb, |
481 | ); |
484 | ); |
482 | |
485 | |
483 | $macrolist->add_at (1, $y, new CFPlus::UI::Label |
486 | $macrolist->add_at (1, $y, new DC::UI::Label |
484 | text => (join "; ", @{ $macro->{action} || [] }), |
487 | text => (join "; ", @{ $macro->{action} || [] }), |
485 | tooltip => $tooltip_commands . $tooltip_common, |
488 | tooltip => $tooltip_commands . $tooltip_common, |
486 | expand => 1, |
489 | expand => 1, |
487 | ellipsise => 3, |
490 | ellipsise => 3, |
488 | can_hover => 1, |
491 | can_hover => 1, |