Changeset 12393


Ignore:
Timestamp:
08/29/10 11:31:52 (18 months ago)
Author:
zenogantner
Message:

more changes to the key bindings dialog

Location:
trunk/Padre/lib/Padre/Wx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Wx/Action.pm

    r12391 r12393  
    7070    my $self     = bless { id => -1, @_ }, $class; 
    7171    my $name     = $self->{name}; 
    72     my $shortcut = $self->{shortcut}; 
     72    my $shortcut = defined $self->{shortcut} ? $self->{shortcut} : ''; 
    7373 
    7474    # Check the name 
     
    104104            type    => Padre::Constant::ASCII, 
    105105            store   => Padre::Constant::HUMAN, 
    106             default => '', 
     106            default => $shortcut, 
    107107        ); 
    108108    } 
  • trunk/Padre/lib/Padre/Wx/Dialog/KeyBindings.pm

    r12391 r12393  
    1212our @ISA     = qw{ 
    1313    Padre::Wx::Role::Main 
     14    Padre::Wx::Role::Dialog 
    1415    Wx::Dialog 
    1516}; 
     
    107108    $self->{button_set}->Enable(1); 
    108109 
    109     # Reset to default key binding button 
    110     $self->{button_reset} = Wx::Button->new( 
    111         $self, -1, Wx::gettext('&Reset'), 
    112     ); 
    113     $self->{button_reset}->Enable(0); 
     110    # Delete button 
     111    $self->{button_delete} = Wx::Button->new( 
     112        $self, -1, Wx::gettext('&Delete'), 
     113    ); 
     114    $self->{button_delete}->Enable(1); 
    114115 
    115116    # Close button 
     
    147148    $value_sizer->Add( $self->{key}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
    148149    $value_sizer->AddStretchSpacer; 
    149     $value_sizer->Add( $self->{button_set},   0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
    150     $value_sizer->Add( $self->{button_reset}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
     150    $value_sizer->Add( $self->{button_set},    0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
     151    $value_sizer->Add( $self->{button_delete}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
    151152 
    152153    # Button sizer 
     
    216217    ); 
    217218 
    218     # Reset button 
     219    # Delete button 
    219220    Wx::Event::EVT_BUTTON( 
    220221        $self, 
    221         $self->{button_reset}, 
     222        $self->{button_delete}, 
    222223        sub { 
    223             shift->_on_reset_button; 
     224            shift->_on_delete_button; 
    224225        } 
    225226    ); 
     
    307308    my $self = shift; 
    308309 
    309     my $list  = $self->{list}; 
    310     my $index = $list->GetFirstSelected; 
    311     my $name  = $list->GetItemText($index); 
     310    my $index       = $self->{list}->GetFirstSelected; 
     311    my $action_name = $self->{list}->GetItemText($index); 
    312312 
    313313    my @key_list = (); 
     
    319319    my $shortcut = join '-', @key_list; 
    320320 
    321     return if $shortcut eq ''; 
     321    my $other_action = Padre->ide->shortcuts->{$shortcut}; 
     322    if ( defined $other_action && $other_action->name ne $action_name ) { 
     323        my $answer = $self->yes_no( 
     324            sprintf( 
     325                Wx::gettext("The shortcut '%s' is already used by the action '%s'.\n"), 
     326                $shortcut, $other_action->label_text 
     327                ) 
     328                . Wx::gettext('Do you want to override it with the selected action?'), 
     329            Wx::gettext('Override Shortcut') 
     330        ); 
     331        if ($answer) { 
     332            $self->set_binding( $other_action->name, '' ); 
     333        } else { 
     334            return; 
     335        } 
     336    } 
     337 
     338    $self->set_binding( $action_name, $shortcut ); 
     339    $self->_update_list; 
     340 
     341    return; 
     342} 
     343 
     344sub set_binding { 
     345    my ( $self, $action_name, $shortcut ) = @_; 
    322346 
    323347    my $shortcuts = Padre->ide->shortcuts; 
    324     if ( exists $shortcuts->{$shortcut} ) { 
    325         warn "Found a duplicate shortcut: '$shortcut' for " . $shortcuts->{$shortcut}->name . "\n"; 
    326  
    327         # TODO instead of a warning, offer to overwrite the old shortcut. 
    328     } else { 
    329         $shortcuts->{$shortcut} = Padre->ide->actions->{$name}; 
    330         warn "Set shortcut '$shortcut' for action '$name'\n"; 
    331  
    332         Padre->ide->actions->{$name}->shortcut($shortcut); 
    333  
    334         my $setting = "keyboard_shortcut_$name"; 
    335         $setting =~ s/\W/_/g; # setting names must be valid subroutine names 
    336         $self->config->set( $setting, $shortcut ); 
    337         $self->config->write; 
    338  
    339         $self->_update_list; 
    340     } 
    341  
    342     return; 
    343 } 
    344  
    345 # Private method to handle the pressing of the reset to default button 
    346 sub _on_reset_button { 
     348    my $action    = Padre->ide->actions->{$action_name}; 
     349 
     350    # modify shortcut registry 
     351    my $old_shortcut = $action->shortcut; 
     352    delete $shortcuts->{$old_shortcut}; 
     353    $shortcuts->{$shortcut} = $action; 
     354 
     355    # set the action's shortcut 
     356    $action->shortcut( $shortcut eq '' ? undef : $shortcut ); 
     357 
     358    # modify the configuration database 
     359    my $setting = "keyboard_shortcut_$action_name"; 
     360    $setting =~ s/\W/_/g; # setting names must be valid subroutine names 
     361    $self->config->set( $setting, $shortcut ); 
     362    $self->config->write; 
     363 
     364    return; 
     365} 
     366 
     367# Private method to handle the pressing of the delete button 
     368sub _on_delete_button { 
    347369    my $self = shift; 
    348370 
    349371    # Prepare the key binding 
    350     my $list  = $self->{list}; 
    351     my $index = $list->GetFirstSelected; 
    352     my $name  = $list->GetItemText($index); 
    353  
    354     my $action = Padre->ide->actions->{$name}; 
    355  
    356     ## TODO 
    357     # restore default or previous value? 
    358     # ensure that list contains right value ... 
     372    my $index       = $self->{list}->GetFirstSelected; 
     373    my $action_name = $self->{list}->GetItemText($index); 
     374 
     375    $self->set_binding( $action_name, '' ); 
     376    $self->_update_list; 
    359377 
    360378    return; 
     
    385403    $list->DeleteAllItems; 
    386404 
    387     my $index               = -1; 
    388     my $actions             = Padre->ide->actions; 
    389     my $alternate_color     = Wx::Colour->new( 0xED, 0xF5, 0xFF ); 
    390     my @sorted_action_names = sort { $a cmp $b } keys %$actions; 
    391     for ( my $i = 0; $i < scalar @sorted_action_names; $i++ ) { 
    392         my $action_name = $sorted_action_names[$i]; 
    393         my $action      = $actions->{$action_name}; 
    394         my $shortcut    = defined $action->shortcut ? $action->shortcut : ''; 
    395  
    396         # Ignore the key binding if it does not match the filter 
    397         next if $action->label_text !~ /$filter/i; 
     405    my $actions         = Padre->ide->actions; 
     406    my $alternate_color = Wx::Colour->new( 0xED, 0xF5, 0xFF ); 
     407    my $index           = 0; 
     408    foreach my $action_name ( sort { $a cmp $b } keys %$actions ) { 
     409        my $action = $actions->{$action_name}; 
     410        my $shortcut = defined $action->shortcut ? $action->shortcut : ''; 
     411 
     412        # Ignore key binding if it does not match the filter 
     413        next 
     414            if $action->label_text !~ /$filter/i 
     415                and $action_name !~ /$filter/i; 
    398416 
    399417        # Add the key binding to the list control 
    400         $list->InsertStringItem( $i, $action_name ); 
    401         $list->SetItem( $i, 1, $action->label_text ); 
    402         $list->SetItem( $i, 2, $shortcut ); 
     418        $list->InsertStringItem( $index, $action_name ); 
     419        $list->SetItem( $index, 1, $action->label_text ); 
     420        $list->SetItem( $index, 2, $shortcut ); 
    403421 
    404422        # Alternating table colors 
    405         $list->SetItemBackgroundColour( $i, $alternate_color ) unless $i % 2; 
     423        $list->SetItemBackgroundColour( $index, $alternate_color ) unless $index % 2; 
     424        $index++; 
    406425    } 
    407426 
Note: See TracChangeset for help on using the changeset viewer.