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