Changeset 12395
- Timestamp:
- 08/29/10 12:23:01 (18 months ago)
- Location:
- trunk/Padre/lib/Padre/Wx
- Files:
-
- 2 edited
-
Action.pm (modified) (2 diffs)
-
Dialog/KeyBindings.pm (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/Wx/Action.pm
r12393 r12395 97 97 # Create shortcut setting for the action 98 98 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; 101 100 if ( not $config->can($setting) ) { 102 101 $config->setting( … … 179 178 } 180 179 180 sub 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 181 189 # Add an event to an action: 182 190 sub add_event { -
trunk/Padre/lib/Padre/Wx/Dialog/KeyBindings.pm
r12393 r12395 113 113 ); 114 114 $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); 115 122 116 123 # Close button … … 150 157 $value_sizer->Add( $self->{button_set}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 ); 151 158 $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 ); 152 160 153 161 # Button sizer … … 226 234 ); 227 235 236 # Reset button 237 Wx::Event::EVT_BUTTON( 238 $self, 239 $self->{button_reset}, 240 sub { 241 shift->_on_reset_button; 242 } 243 ); 244 228 245 # Close button 229 246 Wx::Event::EVT_BUTTON( … … 262 279 my $index = $list->GetFirstSelected; 263 280 my $action_name = $list->GetItemText($index); 281 my $action = Padre->ide->actions->{$action_name}; 264 282 265 283 my $shortcut = Padre->ide->actions->{$action_name}->shortcut; 266 284 $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 '' ); 267 289 268 290 # Get the regular (i.e. non-modifier) key in the shortcut … … 282 304 # and update the UI 283 305 $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 ); 287 309 288 310 # Make sure the value and info sizer are not hidden … … 290 312 $self->{vsizer}->Show( 3, 1 ); 291 313 $self->{vsizer}->Layout; 292 293 return;294 }295 296 # Private method to update the UI from the provided key binding297 sub _update_ui {298 my ( $self, $pref ) = @_;299 300 my $list = $self->{list};301 my $index = $list->GetFirstSelected;302 314 303 315 return; … … 318 330 push @key_list, $regular_key if not $regular_key eq 'None'; 319 331 my $shortcut = join '-', @key_list; 332 333 $self->try_to_set_binding( $action_name, $shortcut ); 334 335 return; 336 } 337 338 sub try_to_set_binding { 339 my ( $self, $action_name, $shortcut ) = @_; 320 340 321 341 my $other_action = Padre->ide->shortcuts->{$shortcut}; … … 329 349 Wx::gettext('Override Shortcut') 330 350 ); 331 if ( $answer) {351 if ( !$answer ) { 332 352 $self->set_binding( $other_action->name, '' ); 333 353 } else { … … 350 370 # modify shortcut registry 351 371 my $old_shortcut = $action->shortcut; 352 delete $shortcuts->{$old_shortcut} ;372 delete $shortcuts->{$old_shortcut} if defined $old_shortcut; 353 373 $shortcuts->{$shortcut} = $action; 354 374 … … 357 377 358 378 # 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 ); 362 380 $self->config->write; 363 381 … … 375 393 $self->set_binding( $action_name, '' ); 376 394 $self->_update_list; 395 396 return; 397 } 398 399 # Private method to handle the pressing of the reset button 400 sub _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 ) ); 377 408 378 409 return; … … 413 444 next 414 445 if $action->label_text !~ /$filter/i 415 and $action_name !~ /$filter/i; 446 and $action_name !~ /$filter/i 447 and $shortcut !~ /$filter/i; 416 448 417 449 # Add the key binding to the list control
Note: See TracChangeset
for help on using the changeset viewer.
