Changeset 12395


Ignore:
Timestamp:
08/29/10 12:23:01 (18 months ago)
Author:
zenogantner
Message:

code clean-up, nicer UI behaviour

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

Legend:

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

    r12393 r12395  
    9797    # Create shortcut setting for the action 
    9898    my $config  = Padre->ide->config; 
    99     my $setting = "keyboard_shortcut_$name"; 
    100     $setting =~ s/\W/_/g; # setting names must be valid subroutine names 
     99    my $setting = $self->shortcut_setting; 
    101100    if ( not $config->can($setting) ) { 
    102101        $config->setting( 
     
    179178} 
    180179 
     180sub shortcut_setting { 
     181    my $self = shift; 
     182 
     183    my $setting = 'keyboard_shortcut_' . $self->name; 
     184    $setting =~ s/\W/_/g; # setting names must be valid subroutine names 
     185 
     186    return $setting; 
     187} 
     188 
    181189# Add an event to an action: 
    182190sub add_event { 
  • trunk/Padre/lib/Padre/Wx/Dialog/KeyBindings.pm

    r12393 r12395  
    113113    ); 
    114114    $self->{button_delete}->Enable(1); 
     115 
     116    # Reset button 
     117    $self->{button_reset} = Wx::Button->new( 
     118        $self, -1, Wx::gettext('&Reset'), 
     119    ); 
     120    $self->{button_reset}->SetToolTip( Wx::gettext('Reset to default shortcut') ); 
     121    $self->{button_reset}->Enable(1); 
    115122 
    116123    # Close button 
     
    150157    $value_sizer->Add( $self->{button_set},    0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
    151158    $value_sizer->Add( $self->{button_delete}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
     159    $value_sizer->Add( $self->{button_reset},  0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 
    152160 
    153161    # Button sizer 
     
    226234    ); 
    227235 
     236    # Reset button 
     237    Wx::Event::EVT_BUTTON( 
     238        $self, 
     239        $self->{button_reset}, 
     240        sub { 
     241            shift->_on_reset_button; 
     242        } 
     243    ); 
     244 
    228245    # Close button 
    229246    Wx::Event::EVT_BUTTON( 
     
    262279    my $index       = $list->GetFirstSelected; 
    263280    my $action_name = $list->GetItemText($index); 
     281    my $action      = Padre->ide->actions->{$action_name}; 
    264282 
    265283    my $shortcut = Padre->ide->actions->{$action_name}->shortcut; 
    266284    $shortcut = '' if not defined $shortcut; 
     285 
     286    $self->{button_reset}->Enable( $shortcut ne $self->config->default( $action->shortcut_setting ) ); 
     287 
     288    $self->{button_delete}->Enable( $shortcut ne '' ); 
    267289 
    268290    # Get the regular (i.e. non-modifier) key in the shortcut 
     
    282304    # and update the UI 
    283305    $self->{key}->SetSelection($regular_index); 
    284     $self->{ctrl}->SetValue( $shortcut =~ /Ctrl/ ? 1 : 0 ); 
    285     $self->{alt}->SetValue( $shortcut  =~ /Alt/  ? 1 : 0 ); 
    286     $self->{shift}->SetValue( ( $shortcut =~ /Shift/ ) ? 1 : 0 ); 
     306    $self->{ctrl}->SetValue( $shortcut  =~ /Ctrl/ ? 1 : 0 ); 
     307    $self->{alt}->SetValue( $shortcut   =~ /Alt/   ? 1 : 0 ); 
     308    $self->{shift}->SetValue( $shortcut =~ /Shift/ ? 1 : 0 ); 
    287309 
    288310    # Make sure the value and info sizer are not hidden 
     
    290312    $self->{vsizer}->Show( 3, 1 ); 
    291313    $self->{vsizer}->Layout; 
    292  
    293     return; 
    294 } 
    295  
    296 # Private method to update the UI from the provided key binding 
    297 sub _update_ui { 
    298     my ( $self, $pref ) = @_; 
    299  
    300     my $list  = $self->{list}; 
    301     my $index = $list->GetFirstSelected; 
    302314 
    303315    return; 
     
    318330    push @key_list, $regular_key if not $regular_key eq 'None'; 
    319331    my $shortcut = join '-', @key_list; 
     332 
     333    $self->try_to_set_binding( $action_name, $shortcut ); 
     334 
     335    return; 
     336} 
     337 
     338sub try_to_set_binding { 
     339    my ( $self, $action_name, $shortcut ) = @_; 
    320340 
    321341    my $other_action = Padre->ide->shortcuts->{$shortcut}; 
     
    329349            Wx::gettext('Override Shortcut') 
    330350        ); 
    331         if ($answer) { 
     351        if ( !$answer ) { 
    332352            $self->set_binding( $other_action->name, '' ); 
    333353        } else { 
     
    350370    # modify shortcut registry 
    351371    my $old_shortcut = $action->shortcut; 
    352     delete $shortcuts->{$old_shortcut}; 
     372    delete $shortcuts->{$old_shortcut} if defined $old_shortcut; 
    353373    $shortcuts->{$shortcut} = $action; 
    354374 
     
    357377 
    358378    # 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 ); 
     379    $self->config->set( $action->shortcut_setting, $shortcut ); 
    362380    $self->config->write; 
    363381 
     
    375393    $self->set_binding( $action_name, '' ); 
    376394    $self->_update_list; 
     395 
     396    return; 
     397} 
     398 
     399# Private method to handle the pressing of the reset button 
     400sub _on_reset_button { 
     401    my $self = shift; 
     402 
     403    my $index       = $self->{list}->GetFirstSelected; 
     404    my $action_name = $self->{list}->GetItemText($index); 
     405    my $action      = Padre->ide->actions($action_name); 
     406 
     407    $self->try_to_set_binding( $action_name, $self->config->default( $action->shortcut_setting ) ); 
    377408 
    378409    return; 
     
    413444        next 
    414445            if $action->label_text !~ /$filter/i 
    415                 and $action_name !~ /$filter/i; 
     446                and $action_name !~ /$filter/i 
     447                and $shortcut !~ /$filter/i; 
    416448 
    417449        # Add the key binding to the list control 
Note: See TracChangeset for help on using the changeset viewer.