… | |
… | |
3310 | $rec = $::CONN->stop_record if $::CONN; |
3310 | $rec = $::CONN->stop_record if $::CONN; |
3311 | return unless ref $rec eq 'ARRAY'; |
3311 | return unless ref $rec eq 'ARRAY'; |
3312 | $self->set_command_list ($rec); |
3312 | $self->set_command_list ($rec); |
3313 | } |
3313 | } |
3314 | |
3314 | |
|
|
3315 | # if $commit is true, the binding will be set after the user entered a key combo |
3315 | sub ask_for_bind { |
3316 | sub ask_for_bind { |
3316 | my ($self, $commit) = @_; |
3317 | my ($self, $commit) = @_; |
3317 | |
3318 | |
3318 | CFClient::Binder::open_binding_dialog (sub { |
3319 | CFClient::Binder::open_binding_dialog (sub { |
3319 | my ($mod, $sym) = @_; |
3320 | my ($mod, $sym) = @_; |
… | |
… | |
3321 | $self->update_binding_widgets; |
3322 | $self->update_binding_widgets; |
3322 | $self->commit if $commit; |
3323 | $self->commit if $commit; |
3323 | }); |
3324 | }); |
3324 | } |
3325 | } |
3325 | |
3326 | |
|
|
3327 | # $mod and $sym are the modifiers and key symbol |
|
|
3328 | # $cmds is a array ref of strings (the commands) |
|
|
3329 | # $cb is the callback that is executed on OK |
|
|
3330 | # $ccb is the callback that is executed on CANCEL and |
|
|
3331 | # when the binding was unsuccessful on OK |
3326 | sub set_binding { |
3332 | sub set_binding { |
3327 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
3333 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
3328 | |
3334 | |
3329 | $self->clear_command_list; |
3335 | $self->clear_command_list; |
3330 | $self->{recording} = 0; |
3336 | $self->{recording} = 0; |
… | |
… | |
3335 | |
3341 | |
3336 | $self->{binding_change} = $cb; |
3342 | $self->{binding_change} = $cb; |
3337 | $self->{binding_cancel} = $ccb; |
3343 | $self->{binding_cancel} = $ccb; |
3338 | |
3344 | |
3339 | $self->update_binding_widgets; |
3345 | $self->update_binding_widgets; |
|
|
3346 | } |
|
|
3347 | |
|
|
3348 | # this is a shortcut method that asks for a binding |
|
|
3349 | # and then just binds it. |
|
|
3350 | sub do_quick_binding { |
|
|
3351 | my ($self, $cmds) = @_; |
|
|
3352 | $self->set_binding (undef, undef, $cmds, sub { |
|
|
3353 | $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2]; |
|
|
3354 | }); |
|
|
3355 | $self->ask_for_bind (1); |
3340 | } |
3356 | } |
3341 | |
3357 | |
3342 | sub update_binding_widgets { |
3358 | sub update_binding_widgets { |
3343 | my ($self) = @_; |
3359 | my ($self) = @_; |
3344 | my ($mod, $sym, $cmds) = $self->get_binding; |
3360 | my ($mod, $sym, $cmds) = $self->get_binding; |
… | |
… | |
3387 | } |
3403 | } |
3388 | |
3404 | |
3389 | |
3405 | |
3390 | ############################################################################# |
3406 | ############################################################################# |
3391 | |
3407 | |
|
|
3408 | package CFClient::UI::SpellList; |
|
|
3409 | |
|
|
3410 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3411 | |
|
|
3412 | sub new { |
|
|
3413 | my $class = shift; |
|
|
3414 | |
|
|
3415 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3416 | |
|
|
3417 | $self->add (new CFClient::UI::ScrolledWindow |
|
|
3418 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
|
|
3419 | |
|
|
3420 | $self; |
|
|
3421 | } |
|
|
3422 | |
|
|
3423 | # XXX: Do sorting? Argl... |
|
|
3424 | sub add_spell { |
|
|
3425 | my ($self, $spell) = @_; |
|
|
3426 | $self->{spells}->{$spell->{name}} = $spell; |
|
|
3427 | |
|
|
3428 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
|
|
3429 | face => $spell->{face}, |
|
|
3430 | can_hover => 1, |
|
|
3431 | can_events => 1, |
|
|
3432 | tooltip => $spell->{message}); |
|
|
3433 | |
|
|
3434 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3435 | text => $spell->{name}, |
|
|
3436 | can_hover => 1, |
|
|
3437 | can_events => 1, |
|
|
3438 | tooltip => $spell->{message}, |
|
|
3439 | expand => 1); |
|
|
3440 | $self->{spellbox}->add (2, $self->{tbl_idx}++, new CFClient::UI::Button |
|
|
3441 | text => "bind to key", |
|
|
3442 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
|
|
3443 | } |
|
|
3444 | |
|
|
3445 | sub rebuild_spell_list { |
|
|
3446 | my ($self) = @_; |
|
|
3447 | $self->{tbl_idx} = 0; |
|
|
3448 | $self->add_spell ($_) for values %{$self->{spells}}; |
|
|
3449 | } |
|
|
3450 | |
|
|
3451 | sub remove_spell { |
|
|
3452 | my ($self, $spell) = @_; |
|
|
3453 | delete $self->{spells}->{$spell->{name}}; |
|
|
3454 | $self->rebuild_spell_list; |
|
|
3455 | } |
|
|
3456 | |
|
|
3457 | ############################################################################# |
|
|
3458 | |
3392 | package CFClient::UI; |
3459 | package CFClient::UI; |
3393 | |
3460 | |
3394 | $ROOT = new CFClient::UI::Root; |
3461 | $ROOT = new CFClient::UI::Root; |
3395 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
3462 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
3396 | |
3463 | |