Changeset 12393
- Timestamp:
- 08/29/10 11:31:52 (18 months ago)
- Location:
- trunk/Padre/lib/Padre/Wx
- Files:
-
- 2 edited
-
Action.pm (modified) (2 diffs)
-
Dialog/KeyBindings.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/Wx/Action.pm
r12391 r12393 70 70 my $self = bless { id => -1, @_ }, $class; 71 71 my $name = $self->{name}; 72 my $shortcut = $self->{shortcut};72 my $shortcut = defined $self->{shortcut} ? $self->{shortcut} : ''; 73 73 74 74 # Check the name … … 104 104 type => Padre::Constant::ASCII, 105 105 store => Padre::Constant::HUMAN, 106 default => '',106 default => $shortcut, 107 107 ); 108 108 } -
trunk/Padre/lib/Padre/Wx/Dialog/KeyBindings.pm
r12391 r12393 12 12 our @ISA = qw{ 13 13 Padre::Wx::Role::Main 14 Padre::Wx::Role::Dialog 14 15 Wx::Dialog 15 16 }; … … 107 108 $self->{button_set}->Enable(1); 108 109 109 # Reset to default key bindingbutton110 $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); 114 115 115 116 # Close button … … 147 148 $value_sizer->Add( $self->{key}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 148 149 $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 ); 151 152 152 153 # Button sizer … … 216 217 ); 217 218 218 # Resetbutton219 # Delete button 219 220 Wx::Event::EVT_BUTTON( 220 221 $self, 221 $self->{button_ reset},222 $self->{button_delete}, 222 223 sub { 223 shift->_on_ reset_button;224 shift->_on_delete_button; 224 225 } 225 226 ); … … 307 308 my $self = shift; 308 309 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); 312 312 313 313 my @key_list = (); … … 319 319 my $shortcut = join '-', @key_list; 320 320 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 344 sub set_binding { 345 my ( $self, $action_name, $shortcut ) = @_; 322 346 323 347 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 368 sub _on_delete_button { 347 369 my $self = shift; 348 370 349 371 # 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; 359 377 360 378 return; … … 385 403 $list->DeleteAllItems; 386 404 387 my $ index = -1;388 my $a ctions = 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 filter397 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; 398 416 399 417 # 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 ); 403 421 404 422 # Alternating table colors 405 $list->SetItemBackgroundColour( $i, $alternate_color ) unless $i % 2; 423 $list->SetItemBackgroundColour( $index, $alternate_color ) unless $index % 2; 424 $index++; 406 425 } 407 426
Note: See TracChangeset
for help on using the changeset viewer.
