Changeset 3024


Ignore:
Timestamp:
02/06/09 14:54:38 (3 years ago)
Author:
hjansen
Message:

Implemented feature request #236 (bracket autocompletion)

There might be some need for refactoring already included in this patch:
I am not overly content with the preferences option position in the
"Perl" menu and the config option might need a "perl_" prefix?

Location:
trunk/Padre/lib/Padre
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Config.pm

    r3013 r3024  
    338338); 
    339339setting( 
     340    name    => 'autocomplete_brackets', 
     341    type    => BOOLEAN, 
     342    store   => HUMAN, 
     343    default => 0, 
     344); 
     345setting( 
    340346    # By default use background threads unless profiling 
    341347    # TODO - Make the default actually change 
  • trunk/Padre/lib/Padre/Document/Perl.pm

    r3021 r3024  
    552552} 
    553553 
     554sub event_on_char { 
     555    my ( $self, $editor, $event ) = @_; 
     556 
     557    my $key = $event->GetUnicodeKey; 
     558 
     559    if ( Padre->ide->config->autocomplete_brackets ) { 
     560        my %table = ( 40 => 41, 60 => 62, 91 => 93, ); # <> would be: 123 => 125, ); 
     561        my $pos = $editor->GetCurrentPos; 
     562        foreach my $code ( keys %table ) { 
     563            if ( $key == $code ) { 
     564                my $nextChar; 
     565                if ( $editor->GetTextLength > $pos ) { 
     566                    $nextChar = $editor->GetTextRange( $pos, $pos + 1 ); 
     567                } 
     568                unless ( 
     569                    defined($nextChar) 
     570                    && ord($nextChar) == $table{$code} 
     571                ) { 
     572                    $editor->AddText( chr( $table{$code} ) ); 
     573                    $editor->CharLeft; 
     574                    last; 
     575                } 
     576            } 
     577        } 
     578    } 
     579 
     580    return; 
     581} 
     582 
    5545831; 
    555584 
  • trunk/Padre/lib/Padre/Wx/Editor.pm

    r2938 r3024  
    4646    Wx::Event::EVT_RIGHT_DOWN( $self, \&on_right_down ); 
    4747    Wx::Event::EVT_LEFT_UP(    $self, \&on_left_up    ); 
     48    Wx::Event::EVT_CHAR(       $self, \&on_char       ); 
    4849 
    4950    if ( Padre->ide->config->editor_wordwrap ) { 
     
    738739} 
    739740 
     741sub on_char { 
     742    my ( $self, $event ) = @_; 
     743 
     744    my $doc = $self->{Document}; 
     745    if ( $doc->can('event_on_char') ) { 
     746        $doc->event_on_char( $self, $event ); 
     747    } 
     748 
     749    $event->Skip; 
     750    return; 
     751} 
     752 
    740753sub on_left_up { 
    741754    my ($self, $event) = @_; 
  • trunk/Padre/lib/Padre/Wx/Menu/Perl.pm

    r3023 r3024  
    275275    ); 
    276276 
     277    $self->{autocomplete_brackets} = $self->AppendCheckItem( 
     278        -1, 
     279        Wx::gettext("Automatic bracket completion") 
     280    ); 
     281    Wx::Event::EVT_MENU( $main, $self->{autocomplete_brackets}, 
     282        sub { 
     283            # Update the saved config setting 
     284            my $config = Padre->ide->config; 
     285            $config->set( autocomplete_brackets => $_[1]->IsChecked ? 1 : 0 ); 
     286        } 
     287    ); 
     288 
    277289    return $self; 
    278290} 
     
    284296    $self->{ppi_highlight}->Check( $config->ppi_highlight ); 
    285297    $self->{run_stacktrace}->Check( $config->run_stacktrace ); 
     298    $self->{autocomplete_brackets}->Check( $config->autocomplete_brackets ); 
    286299 
    287300    no warnings 'once'; # TODO eliminate? 
Note: See TracChangeset for help on using the changeset viewer.