… | |
… | |
3210 | $self->_draw; |
3210 | $self->_draw; |
3211 | } |
3211 | } |
3212 | |
3212 | |
3213 | ############################################################################# |
3213 | ############################################################################# |
3214 | |
3214 | |
|
|
3215 | package CFClient::UI::BindEditor; |
|
|
3216 | |
|
|
3217 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3218 | |
|
|
3219 | sub new { |
|
|
3220 | my $class = shift; |
|
|
3221 | |
|
|
3222 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3223 | |
|
|
3224 | $self->add (my $vb = new CFClient::UI::VBox); |
|
|
3225 | |
|
|
3226 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3227 | $hb->add (new CFClient::UI::Label text => "Key: "); |
|
|
3228 | $hb->add ($self->{keylbl} = new CFClient::UI::Label); |
|
|
3229 | $hb->add (new CFClient::UI::Button |
|
|
3230 | text => "bind", |
|
|
3231 | tooltip => "This opens a query where you have to press the key combination to bind the recorded actions", |
|
|
3232 | on_activate => sub { |
|
|
3233 | $self->ask_for_bind; |
|
|
3234 | }); |
|
|
3235 | |
|
|
3236 | $vb->add (new CFClient::UI::Label text => "Actions:"); |
|
|
3237 | $vb->add ($self->{rec_btn} = new CFClient::UI::Button |
|
|
3238 | text => "start recording", |
|
|
3239 | tooltip => "Start/Stops recording of actions." |
|
|
3240 | ."All subsequent actions after the recording started will be captured." |
|
|
3241 | ."The actions are displayed after the record was stopped." |
|
|
3242 | ."To bind the action you have to click on the 'Bind' button", |
|
|
3243 | on_activate => sub { |
|
|
3244 | unless ($self->{recording}) { |
|
|
3245 | $self->start; |
|
|
3246 | } else { |
|
|
3247 | $self->stop; |
|
|
3248 | } |
|
|
3249 | }); |
|
|
3250 | |
|
|
3251 | $vb->add ($self->{cmdbox} = new CFClient::UI::VBox); |
|
|
3252 | |
|
|
3253 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3254 | $hb->add (new CFClient::UI::Button |
|
|
3255 | text => "ok", |
|
|
3256 | tooltip => "This closes the binding editor and saves the binding", |
|
|
3257 | on_activate => sub { |
|
|
3258 | $self->hide; |
|
|
3259 | $self->commit; |
|
|
3260 | }); |
|
|
3261 | |
|
|
3262 | $hb->add (new CFClient::UI::Button |
|
|
3263 | text => "cancel", |
|
|
3264 | tooltip => "This closes the binding editor without saving", |
|
|
3265 | on_activate => sub { |
|
|
3266 | $self->hide; |
|
|
3267 | $self->{binding_cancel}->() |
|
|
3268 | if $self->{binding_cancel}; |
|
|
3269 | }); |
|
|
3270 | |
|
|
3271 | $self->update_binding_widgets; |
|
|
3272 | |
|
|
3273 | $self |
|
|
3274 | } |
|
|
3275 | |
|
|
3276 | sub commit { |
|
|
3277 | my ($self) = @_; |
|
|
3278 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3279 | if ($sym != 0 && @$cmds > 0) { |
|
|
3280 | $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym) |
|
|
3281 | ."'. Don't forget 'Save Config'!"); |
|
|
3282 | $self->{binding_change}->($mod, $sym, $cmds) |
|
|
3283 | if $self->{binding_change}; |
|
|
3284 | } else { |
|
|
3285 | $::STATUSBOX->add ("No action bound, no keys specified!"); |
|
|
3286 | $self->{binding_cancel}->() |
|
|
3287 | if $self->{binding_cancel}; |
|
|
3288 | } |
|
|
3289 | } |
|
|
3290 | |
|
|
3291 | sub start { |
|
|
3292 | my ($self) = @_; |
|
|
3293 | |
|
|
3294 | $self->{rec_btn}->set_text ("stop recording"); |
|
|
3295 | $self->{recording} = 1; |
|
|
3296 | $self->clear_command_list; |
|
|
3297 | $::CONN->start_record if $::CONN; |
|
|
3298 | } |
|
|
3299 | |
|
|
3300 | sub stop { |
|
|
3301 | my ($self) = @_; |
|
|
3302 | |
|
|
3303 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3304 | $self->{recording} = 0; |
|
|
3305 | |
|
|
3306 | my $rec; |
|
|
3307 | $rec = $::CONN->stop_record if $::CONN; |
|
|
3308 | return unless ref $rec eq 'ARRAY'; |
|
|
3309 | $self->set_command_list ($rec); |
|
|
3310 | } |
|
|
3311 | |
|
|
3312 | sub ask_for_bind { |
|
|
3313 | my ($self, $commit) = @_; |
|
|
3314 | |
|
|
3315 | CFClient::Binder::open_binding_dialog (sub { |
|
|
3316 | my ($mod, $sym) = @_; |
|
|
3317 | $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? |
|
|
3318 | $self->update_binding_widgets; |
|
|
3319 | $self->commit if $commit; |
|
|
3320 | }); |
|
|
3321 | } |
|
|
3322 | |
|
|
3323 | sub set_binding { |
|
|
3324 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
|
|
3325 | |
|
|
3326 | $self->clear_command_list; |
|
|
3327 | $self->{recording} = 0; |
|
|
3328 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3329 | |
|
|
3330 | $self->{binding} = [$mod, $sym]; |
|
|
3331 | $self->{commands} = $cmds; |
|
|
3332 | |
|
|
3333 | $self->{binding_change} = $cb; |
|
|
3334 | $self->{binding_cancel} = $ccb; |
|
|
3335 | |
|
|
3336 | $self->update_binding_widgets; |
|
|
3337 | } |
|
|
3338 | |
|
|
3339 | sub update_binding_widgets { |
|
|
3340 | my ($self) = @_; |
|
|
3341 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3342 | $self->{keylbl}->set_text (CFClient::Binder::keycombo_to_name ($mod, $sym)); |
|
|
3343 | $self->set_command_list ($cmds); |
|
|
3344 | } |
|
|
3345 | |
|
|
3346 | sub get_binding { |
|
|
3347 | my ($self) = @_; |
|
|
3348 | return ( |
|
|
3349 | $self->{binding}->[0], |
|
|
3350 | $self->{binding}->[1], |
|
|
3351 | [ grep { defined $_ } @{$self->{commands}} ] |
|
|
3352 | ); |
|
|
3353 | } |
|
|
3354 | |
|
|
3355 | sub clear_command_list { |
|
|
3356 | my ($self) = @_; |
|
|
3357 | $self->{cmdbox}->clear (); |
|
|
3358 | } |
|
|
3359 | |
|
|
3360 | sub set_command_list { |
|
|
3361 | my ($self, $cmds) = @_; |
|
|
3362 | |
|
|
3363 | $self->{cmdbox}->clear (); |
|
|
3364 | $self->{commands} = $cmds; |
|
|
3365 | |
|
|
3366 | my $idx = 0; |
|
|
3367 | |
|
|
3368 | for (@$cmds) { |
|
|
3369 | $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); |
|
|
3370 | |
|
|
3371 | my $i = $idx; |
|
|
3372 | $hb->add (new CFClient::UI::Button |
|
|
3373 | text => "delete", |
|
|
3374 | tooltip => "Deletes the action from the record", |
|
|
3375 | on_activate => sub { |
|
|
3376 | $self->{cmdbox}->remove ($hb); |
|
|
3377 | $cmds->[$i] = undef; |
|
|
3378 | }); |
|
|
3379 | |
|
|
3380 | $hb->add (new CFClient::UI::Label text => $_); |
|
|
3381 | |
|
|
3382 | $idx++ |
|
|
3383 | } |
|
|
3384 | } |
|
|
3385 | |
|
|
3386 | |
|
|
3387 | ############################################################################# |
|
|
3388 | |
3215 | package CFClient::UI; |
3389 | package CFClient::UI; |
3216 | |
3390 | |
3217 | $ROOT = new CFClient::UI::Root; |
3391 | $ROOT = new CFClient::UI::Root; |
3218 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
3392 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
3219 | |
3393 | |