Changeset 12390


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

Dialog::KeyBindings?: code clean-up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Wx/Dialog/KeyBindings.pm

    r12389 r12390  
    328328    } else { 
    329329        $shortcuts->{$shortcut} = Padre->ide->actions->{$name}; 
    330         $self->{bindings}->{$name}->{shortcut} = $shortcut; 
    331330        warn "Set shortcut '$shortcut' for action '$name'\n"; 
    332331 
     
    367366    my $main = $self->GetParent; 
    368367 
     368    # re-create menu to activate shortcuts 
    369369    delete $main->{menu}; 
    370370    $main->{menu} = Padre::Wx::Menubar->new($main); 
     
    376376} 
    377377 
    378 # Private method to update the key bindings list 
     378# Private method to update the key bindings list view 
    379379sub _update_list { 
    380380    my $self   = shift; 
     
    386386 
    387387    my $index               = -1; 
    388     my $bindings            = $self->{bindings}; 
    389     my $alternateColor      = Wx::Colour->new( 0xED, 0xF5, 0xFF ); 
    390     my @sorted_binding_keys = sort { $a cmp $b } keys %$bindings; 
    391     foreach my $name (@sorted_binding_keys) { 
    392  
    393         # Fetch key binding and label 
    394         my $binding = $bindings->{$name}; 
    395         my $label   = $binding->{label}; 
     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 : ''; 
    396395 
    397396        # Ignore the key binding if it does not match the filter 
    398         next if $label !~ /$filter/i; 
     397        next if $action->label_text !~ /$filter/i; 
    399398 
    400399        # Add the key binding to the list control 
    401         $list->InsertStringItem( ++$index, $name ); 
    402         $list->SetItem( $index, 1, $binding->{label} ); 
    403         $list->SetItem( $index, 2, $binding->{shortcut} ); 
     400        $list->InsertStringItem( $i, $action_name ); 
     401        $list->SetItem( $i, 1, $action->label_text ); 
     402        $list->SetItem( $i, 2, $shortcut ); 
    404403 
    405404        # Alternating table colors 
    406         $list->SetItemBackgroundColour( $index, $alternateColor ) unless $index % 2; 
     405        $list->SetItemBackgroundColour( $i, $alternate_color ) unless $i % 2; 
    407406    } 
    408407 
     
    425424} 
    426425 
    427 # Private method to initialize a key bindings hash from Padre actions 
    428 sub _init_key_bindings { 
    429     my $self = shift; 
    430  
    431     my $bindings = {}; 
    432     my %actions  = %{ Padre::ide->actions }; 
    433     foreach my $name ( keys %actions ) { 
    434         my $action = $actions{$name}; 
    435         my $shortcut = $action->shortcut ? $action->shortcut : ''; 
    436         warn "Duplicate action name: '" . $action->label_text . "'\n" if exists $bindings->{ $action->label_text }; 
    437         $bindings->{$name} = { 
    438             label    => $action->label_text, 
    439             shortcut => $shortcut, 
    440         }; 
    441     } 
    442     $self->{bindings} = $bindings; 
    443  
    444     return; 
    445 } 
    446  
    447426# Private method to resize list columns 
    448427sub _resize_columns { 
     
    462441    my $self = shift; 
    463442 
    464     # Initialize Key Bindings 
    465     $self->_init_key_bindings; 
    466  
    467443    # Set focus on the filter text field 
    468444    $self->{filter}->SetFocus; 
Note: See TracChangeset for help on using the changeset viewer.