Changeset 12427


Ignore:
Timestamp:
09/02/10 06:00:44 (18 months ago)
Author:
zenogantner
Message:

partial fix for #452: 'focus order in Replace dialog'

Location:
trunk/Padre
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/Changes

    r12424 r12427  
    2525    - Fix MIME type setting via menu (ZENOG) 
    2626    - mark nl_be as not supported (ZENOG) 
     27    - partial fix for #452: 'focus order in Replace dialog' (ZENOG) 
    2728 
    28290.69 2010.08.17 
  • trunk/Padre/lib/Padre/Wx/Dialog/Replace.pm

    r12251 r12427  
    22 
    33=pod 
    4  
    54=head1 NAME 
    6  
    75Padre::Wx::Dialog::Replace - Find and Replace Widget 
    8  
    96=head1 DESCRIPTION 
    10  
    117C<Padre::Wx:Main> implements Padre's Find and Replace dialog box. 
    12  
    138=head1 METHODS 
    14  
    159=cut 
    1610 
     
    2418use Padre::Wx::Role::Main        (); 
    2519use Padre::Wx::History::ComboBox (); 
    26  
    2720our $VERSION = '0.69'; 
    2821our @ISA     = qw{ 
     
    3225 
    3326=pod 
    34  
    3527=head2 new 
    36  
    3728  my $find = Padre::Wx::Dialog::Replace->new($main); 
    38  
    3929Create and return a C<Padre::Wx::Dialog::Replace> search and replace widget. 
    40  
    41 =cut 
     30=cut 
     31 
    4232 
    4333sub new { 
     
    149139        $self, 
    150140        Wx::wxID_FIND, 
    151         Wx::gettext("&Find"), 
     141        Wx::gettext('&Find'), 
    152142    ); 
    153143    Wx::Event::EVT_BUTTON( 
     
    158148        } 
    159149    ); 
    160     Wx::Event::EVT_CHAR( 
     150    Wx::Event::EVT_KEY_DOWN( 
    161151        $self->{find_button}, 
    162152        sub { 
    163             $self->hotkey( $_[1]->GetKeyCode ); 
     153            $self->hotkey( $_[1], $self->{find_button} ); 
    164154        } 
    165155    ); 
    166156 
    167157    # The "Replace" button 
    168     $self->{replace} = Wx::Button->new( 
     158    $self->{replace_button} = Wx::Button->new( 
    169159        $self, 
    170160        Wx::wxID_REPLACE, 
    171         Wx::gettext("&Replace"), 
     161        Wx::gettext('&Replace'), 
    172162    ); 
    173163    Wx::Event::EVT_BUTTON( 
    174164        $self, 
    175         $self->{replace}, 
     165        $self->{replace_button}, 
    176166        sub { 
    177167            $_[0]->replace_button; 
    178168        } 
    179169    ); 
    180     Wx::Event::EVT_CHAR( 
    181         $self->{replace}, 
    182         sub { 
    183             $self->hotkey( $_[1]->GetKeyCode ); 
    184         } 
    185     ); 
    186     $self->{replace}->SetDefault; 
     170    Wx::Event::EVT_KEY_DOWN( 
     171        $self->{replace_button}, 
     172        sub { 
     173            $self->hotkey( $_[1], $self->{replace_button} ); 
     174        } 
     175    ); 
     176    $self->{replace_button}->SetDefault; 
    187177 
    188178    # The "Close" button 
    189     $self->{cancel_button} = Wx::Button->new( 
     179    $self->{close_button} = Wx::Button->new( 
    190180        $self, 
    191181        Wx::wxID_CANCEL, 
    192         Wx::gettext("&Close"), 
     182        Wx::gettext('&Close'), 
    193183    ); 
    194184    Wx::Event::EVT_BUTTON( 
    195185        $self, 
    196         $self->{cancel_button}, 
    197         sub { 
    198             $_[0]->cancel_button; 
    199         } 
    200     ); 
     186        $self->{close_button}, 
     187        sub { 
     188            $_[0]->close_button; 
     189        } 
     190    ); 
     191 
     192    # Tab order 
     193    $self->{find_regex}->MoveAfterInTabOrder( $self->{find_text} ); 
     194    $self->{replace_text}->MoveAfterInTabOrder( $self->{find_regex} ); 
     195    $self->{find_case}->MoveAfterInTabOrder( $self->{replace_regex} ); 
     196    $self->{find_reverse}->MoveAfterInTabOrder( $self->{find_case} ); 
     197    $self->{find_first}->MoveAfterInTabOrder( $self->{find_reverse} ); 
     198    $self->{replace_all}->MoveAfterInTabOrder( $self->{find_first} ); 
     199    $self->{find_button}->MoveAfterInTabOrder( $self->{replace_all} ); 
     200    $self->{replace_button}->MoveAfterInTabOrder( $self->{find_button} ); 
     201    $self->{close_button}->MoveAfterInTabOrder( $self->{replace_button} ); 
    201202 
    202203    # Form Layout 
    203  
    204204    # Find sizer begins here 
    205205    my $find = Wx::StaticBoxSizer->new( 
     
    215215            $self, 
    216216            Wx::wxID_STATIC, 
    217             Wx::gettext("Find Text:"), 
     217            Wx::gettext('Find Text:'), 
    218218        ), 
    219219        0, 
     
    247247            $self, 
    248248            Wx::wxID_STATIC, 
    249             Wx::gettext("Replace Text:"), 
     249            Wx::gettext('Replace Text:'), 
    250250        ), 
    251251        0, 
     
    313313    ); 
    314314    $bottom->Add( 
    315         $self->{replace}, 
     315        $self->{replace_button}, 
    316316        0, 
    317317        Wx::wxGROW | Wx::wxLEFT | Wx::wxRIGHT, 
     
    319319    ); 
    320320    $bottom->Add( 
    321         $self->{cancel_button}, 
     321        $self->{close_button}, 
    322322        0, 
    323323        Wx::wxGROW | Wx::wxLEFT, 
     
    363363    $self->{find_first}->SetValue( $config->find_first ); 
    364364    $self->{find_reverse}->SetValue( $config->find_reverse ); 
    365  
    366365    return $self; 
    367366} 
    368367 
    369368=pod 
    370  
    371369=head2 find 
    372  
    373370  $self->find 
    374  
    375371Grab currently selected text, if any, and place it in find combo box. 
    376372Bring up the dialog or perform search for string's next occurrence 
    377373if dialog is already displayed. 
    378  
    379374TO DO: if selection is more than one line then consider it as the limit 
    380375of the search and not as the string to be used. 
    381  
    382 =cut 
     376=cut 
     377 
    383378 
    384379sub find { 
     
    396391    $self->{find_text}->refresh; 
    397392    $self->{replace_text}->refresh; 
    398  
    399393    if ( $self->IsShown ) { 
    400394        $self->find_button; 
     
    410404        $self->Show(1); 
    411405    } 
    412  
    413406    return; 
    414407} 
    415  
    416  
    417  
    418  
    419  
    420408###################################################################### 
    421409# Button Events 
    422410 
    423411=pod 
    424  
    425412=head2 find_button 
    426  
    427413  $self->find_button 
    428  
    429414Executed when Find button is clicked. 
    430  
    431415Performs search on the term specified in the dialog. 
    432  
    433416=cut 
    434417 
     
    441424    my $search = $self->as_search; 
    442425    unless ($search) { 
    443         $main->error("Not a valid search"); 
     426        $main->error('Not a valid search'); 
    444427 
    445428        # Move the focus back to the search text 
     
    456439        $self->Hide; 
    457440    } 
    458  
    459441    return; 
    460442} 
    461443 
    462444=pod 
    463  
    464 =head2 cancel_button 
    465  
    466   $self->cancel_button 
    467  
     445=head2 close_button 
     446  $self->close_button 
    468447Hide dialog when pressed cancel button. 
    469  
    470 =cut 
    471  
    472 sub cancel_button { 
     448=cut 
     449 
     450 
     451sub close_button { 
    473452    my $self = shift; 
    474453    $self->Hide; 
     
    483462        $editor->SetFocus; 
    484463    } 
    485  
    486464    return; 
    487465} 
    488466 
    489467=pod 
    490  
    491468=head2 replace_button 
    492  
    493469  $self->replace_button; 
    494  
    495470Executed when the Replace button is clicked. 
    496  
    497471Replaces one appearance of the Find Text with the Replace Text. 
    498  
    499472If search window is still open, run C<search> on the whole text, 
    500473again. 
    501  
    502 =cut 
     474=cut 
     475 
    503476 
    504477# TO DO: The change to this function that turned it into a dual-purpose function 
     
    516489    my $search = $self->as_search; 
    517490    unless ($search) { 
    518         $main->error("Not a valid search"); 
     491        $main->error('Not a valid search'); 
    519492 
    520493        # Move the focus back to the search text 
     
    541514    # so they can change it if they want. 
    542515    $self->{find_text}->SetFocus; 
    543  
    544516    return; 
    545517} 
    546518 
    547519=pod 
    548  
    549520=head2 replace_all 
    550  
    551521  $self->replace_all; 
    552  
    553522Executed when Replace All button is clicked. 
    554  
    555523Replace all appearances of given string in the current document. 
    556  
    557 =cut 
     524=cut 
     525 
    558526 
    559527sub replace_all { 
     
    565533    my $search = $self->as_search; 
    566534    unless ($search) { 
    567         $main->error("Not a valid search"); 
     535        $main->error('Not a valid search'); 
    568536        return; 
    569537    } 
     
    590558    # so they can change it if they want. 
    591559    $self->{find_text}->SetFocus; 
    592  
    593560    return; 
    594561} 
    595  
    596  
    597  
    598  
    599  
    600562##################################################################### 
    601563# Support Methods 
    602564 
    603565=pod 
    604  
    605566=head2 as_search 
    606  
    607567Integration with L<Padre::Search>. Generates a search instance for the 
    608568currently configured information in the Find dialog. 
    609  
    610569Returns a L<Padre::Search> object, or C<undef> if current state of the 
    611570dialog does not result in a valid search. 
    612  
    613571=cut 
    614572 
     
    626584# Adds Ultraedit-like hotkeys for quick find/replace triggering 
    627585sub hotkey { 
    628     my $self = shift; 
    629     my $code = shift; 
    630  
    631     # Handle the 'f' hotkey 
    632     if ( $code == 102 ) { 
     586    my ( $self, $key_event, $sender ) = @_; 
     587 
     588    if ( $key_event->GetKeyCode == ord 'F' ) { 
    633589        $self->find_button; 
    634590    } 
    635  
    636     # Handle the 'r' hotkey 
    637     if ( $code == 114 ) { 
     591    if ( $key_event->GetKeyCode == ord 'R' ) { 
    638592        $self->replace_button; 
    639593    } 
    640  
     594    if ( $key_event->GetKeyCode == Wx::WXK_TAB ) { 
     595 
     596        #$sender->Navigate( $key_event->ShiftDown ? 0 : 1 ); 
     597    } 
    641598    return; 
    642599} 
     
    648605    my $config  = $self->current->config; 
    649606    my $changed = 0; 
    650  
    651607    foreach my $name (qw{ find_case find_regex find_first find_reverse }) { 
    652608        my $value = $self->{$name}->GetValue; 
     
    655611        $changed = 1; 
    656612    } 
    657  
    658613    $config->write if $changed; 
    659  
    660614    return $config; 
    661615} 
    662  
    6636161; 
    664617 
    665618=pod 
    666  
    667619=head1 COPYRIGHT & LICENSE 
    668  
    669620Copyright 2008-2010 The Padre development team as listed in Padre.pm. 
    670  
    671621This program is free software; you can redistribute 
    672622it and/or modify it under the same terms as Perl itself. 
    673  
    674623The full text of the license can be found in the 
    675624LICENSE file included with this module. 
    676  
    677 =cut 
     625=cut 
     626 
    678627 
    679628# Copyright 2008-2010 The Padre development team as listed in Padre.pm. 
Note: See TracChangeset for help on using the changeset viewer.