… | |
… | |
156 | |
156 | |
157 | $window->grab_focus; |
157 | $window->grab_focus; |
158 | $window->show; |
158 | $window->show; |
159 | } |
159 | } |
160 | |
160 | |
|
|
161 | # find macro by event |
|
|
162 | sub match_event($) { |
|
|
163 | my ($ev) = @_; |
|
|
164 | |
|
|
165 | grep { |
|
|
166 | if (my $key = $_->{accelkey}) { |
|
|
167 | $key->[1] == $ev->{sym} |
|
|
168 | && $key->[0] == ($ev->{mod} & $MODIFIER_MASK) |
|
|
169 | } else { |
|
|
170 | 0 |
|
|
171 | } |
|
|
172 | } @{ $::PROFILE->{macro} || [] } |
|
|
173 | } |
|
|
174 | |
161 | sub keyboard_setup { |
175 | sub keyboard_setup { |
162 | my $kbd_setup = new CFPlus::UI::VBox; |
176 | my $kbd_setup = new CFPlus::UI::VBox; |
163 | |
177 | |
164 | $kbd_setup->add (my $list = new CFPlus::UI::VBox); |
178 | $kbd_setup->add (my $list = new CFPlus::UI::VBox); |
165 | |
179 | |
… | |
… | |
178 | 0 |
192 | 0 |
179 | }, |
193 | }, |
180 | ); |
194 | ); |
181 | |
195 | |
182 | $list->add (new CFPlus::UI::FancyFrame |
196 | $list->add (new CFPlus::UI::FancyFrame |
183 | label => "Bindings", |
197 | label => "Macros", |
184 | child => (my $macros = new CFPlus::UI::Table), |
198 | child => (my $macros = new CFPlus::UI::VBox), |
185 | ); |
199 | ); |
186 | |
200 | |
187 | my $refresh; |
201 | my $refresh; |
188 | |
202 | |
189 | 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>"; |
… | |
… | |
207 | $kbd_setup->add (new CFPlus::UI::FancyFrame |
221 | $kbd_setup->add (new CFPlus::UI::FancyFrame |
208 | label => "Edit Macro", |
222 | label => "Edit Macro", |
209 | child => (my $editor = new CFPlus::UI::Table col_expand => [0, 1]), |
223 | child => (my $editor = new CFPlus::UI::Table col_expand => [0, 1]), |
210 | ); |
224 | ); |
211 | |
225 | |
212 | $editor->add (0, 1, new CFPlus::UI::Label |
226 | $editor->add_at (0, 1, new CFPlus::UI::Label |
213 | text => "Trigger", |
227 | text => "Trigger", |
214 | tooltip => $tooltip_trigger, |
228 | tooltip => $tooltip_trigger, |
215 | can_hover => 1, |
229 | can_hover => 1, |
216 | can_events => 1, |
230 | can_events => 1, |
217 | ); |
231 | ); |
218 | $editor->add (0, 2, new CFPlus::UI::Label |
232 | $editor->add_at (0, 2, new CFPlus::UI::Label |
219 | text => "Actions", |
233 | text => "Actions", |
220 | tooltip => $tooltip_commands, |
234 | tooltip => $tooltip_commands, |
221 | can_hover => 1, |
235 | can_hover => 1, |
222 | can_events => 1, |
236 | can_events => 1, |
223 | ); |
237 | ); |
224 | |
238 | |
225 | $editor->add (1, 2, my $textedit = new CFPlus::UI::TextEdit |
239 | $editor->add_at (1, 2, my $textedit = new CFPlus::UI::TextEdit |
226 | text => macro_to_text $macro, |
240 | text => macro_to_text $macro, |
227 | tooltip => $tooltip_commands, |
241 | tooltip => $tooltip_commands, |
228 | on_changed => sub { |
242 | on_changed => sub { |
229 | $macro->{action} = macro_from_text $macro, $_[1]; |
243 | $macro->{action} = macro_from_text $macro, $_[1]; |
230 | }, |
244 | }, |
231 | ); |
245 | ); |
232 | |
246 | |
233 | $editor->add (1, 1, my $accel = new CFPlus::UI::Button |
247 | $editor->add_at (1, 1, my $accel = new CFPlus::UI::Button |
234 | text => trigger_to_string $macro, |
248 | text => trigger_to_string $macro, |
235 | tooltip => "To change the trigger for a macro, activate this button.", |
249 | tooltip => "To change the trigger for a macro, activate this button.", |
236 | on_activate => sub { |
250 | on_activate => sub { |
237 | my ($accel) = @_; |
251 | my ($accel) = @_; |
238 | trigger_edit $macro, sub { |
252 | trigger_edit $macro, sub { |
… | |
… | |
241 | 1 |
255 | 1 |
242 | }, |
256 | }, |
243 | ); |
257 | ); |
244 | |
258 | |
245 | my $recording; |
259 | my $recording; |
246 | $editor->add (1, 3, new CFPlus::UI::Button |
260 | $editor->add_at (1, 3, new CFPlus::UI::Button |
247 | text => "Start Recording", |
261 | text => "Start Recording", |
248 | tooltip => "Start/Stop command recording: when recording, " |
262 | tooltip => "Start/Stop command recording: when recording, " |
249 | . "actions and commands you invoke are appended to this macro. " |
263 | . "actions and commands you invoke are appended to this macro. " |
250 | . "You can only record when you are logged in.", |
264 | . "You can only record when you are logged in.", |
251 | on_destroy => sub { |
265 | on_destroy => sub { |
… | |
… | |
255 | my ($widget) = @_; |
269 | my ($widget) = @_; |
256 | |
270 | |
257 | $recording = $::CONN && !$recording; |
271 | $recording = $::CONN && !$recording; |
258 | if ($recording) { |
272 | if ($recording) { |
259 | $widget->set_text ("Stop Recording"); |
273 | $widget->set_text ("Stop Recording"); |
260 | my $action = $macro->{action} ||= []; |
|
|
261 | $::CONN->record (sub { |
274 | $::CONN->record (sub { |
262 | push @$action, $_[0]; |
275 | push @{ $macro->{action} }, $_[0]; |
263 | $textedit->set_text (macro_to_text $macro); |
276 | $textedit->set_text (macro_to_text $macro); |
264 | }) if $::CONN; |
277 | }) if $::CONN; |
265 | } else { |
278 | } else { |
266 | $widget->set_text ("Start Recording"); |
279 | $widget->set_text ("Start Recording"); |
267 | $::CONN->record if $::CONN; |
280 | $::CONN->record if $::CONN; |
268 | } |
281 | } |
269 | }, |
282 | }, |
270 | ); |
283 | ); |
271 | }; |
284 | }; |
272 | |
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 | |
273 | $REFRESH_MACRO_LIST = $refresh = sub { |
298 | $REFRESH_MACRO_LIST = $refresh = sub { |
274 | $macros->clear; |
299 | $macrolist->clear; |
275 | |
300 | |
276 | $macros->add (0, 0, new CFPlus::UI::Label |
301 | $macrolist->add_at (0, 1, new CFPlus::UI::Label |
277 | text => "Trigger", |
302 | text => "Trigger", |
278 | align => 0, |
303 | align => 0, |
279 | tooltip => $tooltip_trigger . $tooltip_common, |
304 | tooltip => $tooltip_trigger . $tooltip_common, |
280 | ); |
305 | ); |
281 | $macros->add (1, 0, new CFPlus::UI::Label |
306 | $macrolist->add_at (1, 1, new CFPlus::UI::Label |
282 | text => "Commands", |
307 | text => "Commands", |
283 | tooltip => $tooltip_commands . $tooltip_common, |
308 | tooltip => $tooltip_commands . $tooltip_common, |
284 | ); |
309 | ); |
285 | |
310 | |
286 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
311 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
287 | my $macro = $::PROFILE->{macro}[$idx]; |
312 | my $macro = $::PROFILE->{macro}[$idx]; |
288 | my $y = $idx + 1; |
313 | my $y = $idx + 2; |
289 | |
314 | |
290 | my $macro_cb = sub { |
315 | my $macro_cb = sub { |
291 | my ($widget, $ev) = @_; |
316 | my ($widget, $ev) = @_; |
292 | |
317 | |
293 | if ($ev->{button} == 1) { |
318 | if ($ev->{button} == 1) { |
… | |
… | |
311 | } |
336 | } |
312 | |
337 | |
313 | 1 |
338 | 1 |
314 | }; |
339 | }; |
315 | |
340 | |
316 | $macros->add (0, $y, new CFPlus::UI::Label |
341 | $macrolist->add_at (0, $y, new CFPlus::UI::Label |
317 | text => trigger_to_string $macro, |
342 | text => trigger_to_string $macro, |
318 | tooltip => $tooltip_trigger . $tooltip_common, |
343 | tooltip => $tooltip_trigger . $tooltip_common, |
319 | align => 0, |
344 | align => 0, |
320 | can_hover => 1, |
345 | can_hover => 1, |
321 | can_events => 1, |
346 | can_events => 1, |
322 | on_button_down => $macro_cb, |
347 | on_button_down => $macro_cb, |
323 | ); |
348 | ); |
324 | |
349 | |
325 | $macros->add (1, $y, new CFPlus::UI::Label |
350 | $macrolist->add_at (1, $y, new CFPlus::UI::Label |
326 | text => (join "; ", @{ $macro->{action} }), |
351 | text => (join "; ", @{ $macro->{action} || [] }), |
327 | tooltip => $tooltip_commands . $tooltip_common, |
352 | tooltip => $tooltip_commands . $tooltip_common, |
328 | expand => 1, |
353 | expand => 1, |
329 | ellipsise => 3, |
354 | ellipsise => 3, |
330 | can_hover => 1, |
355 | can_hover => 1, |
331 | can_events => 1, |
356 | can_events => 1, |
… | |
… | |
340 | } |
365 | } |
341 | |
366 | |
342 | # this is a shortcut method that asks for a binding |
367 | # this is a shortcut method that asks for a binding |
343 | # and then just binds it. |
368 | # and then just binds it. |
344 | sub quick_macro { |
369 | sub quick_macro { |
345 | my ($self, $cmds, $end_cb) = @_; |
370 | my ($cmds, $end_cb) = @_; |
346 | |
371 | |
347 | my $macro = { |
372 | my $macro = { |
348 | action => $cmds, |
373 | action => $cmds, |
349 | }; |
374 | }; |
350 | |
375 | |
351 | trigger_edit $macro, sub { |
376 | trigger_edit $macro, sub { |
352 | |
|
|
353 | if ($_[0]) { |
377 | if ($_[0]) { |
354 | push @{ $::PROFILE->{macro} }, $macro; |
378 | push @{ $::PROFILE->{macro} }, $macro; |
355 | $REFRESH_MACRO_LIST->(); |
379 | $REFRESH_MACRO_LIST->(); |
356 | } |
380 | } |
357 | |
381 | |