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