Changeset 5531


Ignore:
Timestamp:
06/24/09 13:45:04 (3 years ago)
Author:
mgrimes
Message:

Refactored the Padre::Task::PPI::* code into a standalone package

Location:
trunk
Files:
34 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/Makefile.PL

    r5258 r5531  
    7777requires       'POSIX'                    => 0; 
    7878requires       'PPI'                      => '1.203'; 
     79requires       'PPIx::EditorTools'        => 0; 
    7980requires       'Probe::Perl'              => '0.01'; 
    8081requires       'Storable'                 => '2.15'; 
  • trunk/Padre/dev.pl

    r5403 r5531  
    3232    qq[-I$FindBin::Bin/lib], 
    3333    qq[-I$FindBin::Bin/blib/lib], 
     34    qq[-I$FindBin::Bin/../PPIx-EditorTools/lib], 
    3435); 
    3536if ( grep { $_ eq '-d' } @ARGV ) { 
  • trunk/Padre/lib/Padre/Task/PPI/FindUnmatchedBrace.pm

    r4977 r5531  
    1  
    21package Padre::Task::PPI::FindUnmatchedBrace; 
    32use strict; 
     
    87use base 'Padre::Task::PPI'; 
    98use Padre::Wx(); 
     9use PPIx::EditorTools::FindUnmatchedBrace; 
    1010 
    1111=pod 
     
    3434 
    3535sub prepare { 
    36     my $self = shift; 
    37     $self->SUPER::prepare(@_); 
     36    my $self = shift; 
     37    $self->SUPER::prepare(@_); 
    3838 
    39     # move the document to the main-thread-only storage 
    40     my $mto = $self->{main_thread_only} ||= {}; 
    41     $mto->{document} = $self->{document} 
    42         if defined $self->{document}; 
    43     delete $self->{document}; 
    44     if ( not defined $mto->{document} ) { 
    45         require Carp; 
    46         Carp::croak("Missing Padre::Document::Perl object as {document} attribute of the brace-finder task"); 
    47     } 
    48     return (); 
     39    # move the document to the main-thread-only storage 
     40    my $mto = $self->{main_thread_only} ||= {}; 
     41    $mto->{document} = $self->{document} 
     42      if defined $self->{document}; 
     43    delete $self->{document}; 
     44    if ( not defined $mto->{document} ) { 
     45        require Carp; 
     46        Carp::croak( 
     47            "Missing Padre::Document::Perl object as {document} attribute of the brace-finder task" 
     48        ); 
     49    } 
     50    return (); 
    4951} 
    5052 
    5153sub process_ppi { 
    5254 
    53     # find bad braces 
    54     my $self = shift; 
    55     my $ppi = shift or return; 
    56     require Padre::PPI; 
    57     my $where = $ppi->find( \&Padre::PPI::find_unmatched_brace ); 
    58     if ($where) { 
    59         @$where = sort { 
    60                    Padre::PPI::element_depth($b) <=> Padre::PPI::element_depth($a) 
    61                 or $a->location->[0] <=> $b->location->[0] 
    62                 or $a->location->[1] <=> $b->location->[1] 
    63         } @$where; 
    64         $self->{bad_element} = $where->[0]->location;    # remember for gui update 
    65     } 
    66     return (); 
     55    # find bad braces 
     56    my $self = shift; 
     57    my $ppi = shift or return; 
     58 
     59    my $brace = 
     60      eval { PPIx::EditorTools::FindUnmatchedBrace->new->find( ppi => $ppi ); }; 
     61    if ($@) { 
     62        $self->{error} = $@; 
     63        return; 
     64    } 
     65    $self->{bad_element} = $brace->element->location;    # remember for gui update 
     66 
     67    return (); 
    6768} 
    6869 
    6970sub finish { 
    70     my $self = shift; 
    71     if ( defined $self->{bad_element} ) { 
     71    my $self = shift; 
     72    if ( defined $self->{bad_element} ) { 
    7273 
    73         # GUI update 
    74         $self->{main_thread_only}->{document}->ppi_select( $self->{bad_element} ); 
    75     } else { 
    76         Wx::MessageBox( 
    77             Wx::gettext("All braces appear to be matched"), 
    78             Wx::gettext("Check Complete"), 
    79             Wx::wxOK, 
    80             Padre->ide->wx->main 
    81         ); 
    82     } 
    83     return (); 
     74        # GUI update 
     75        $self->{main_thread_only}->{document} 
     76          ->ppi_select( $self->{bad_element} ); 
     77    } else { 
     78        Wx::MessageBox( 
     79            Wx::gettext("All braces appear to be matched"), 
     80            Wx::gettext("Check Complete"), 
     81            Wx::wxOK, Padre->ide->wx->main 
     82        ); 
     83    } 
     84    return (); 
    8485} 
    8586 
  • trunk/Padre/lib/Padre/Task/PPI/FindVariableDeclaration.pm

    r5145 r5531  
    88 
    99use base 'Padre::Task::PPI'; 
     10use PPIx::EditorTools::FindVariableDeclaration; 
    1011 
    1112=pod 
     
    3435 
    3536sub prepare { 
    36     my $self = shift; 
    37     $self->SUPER::prepare(@_); 
     37    my $self = shift; 
     38    $self->SUPER::prepare(@_); 
    3839 
    39     # move the document to the main-thread-only storage 
    40     my $mto = $self->{main_thread_only} ||= {}; 
    41     $mto->{document} = $self->{document} 
    42         if defined $self->{document}; 
    43     delete $self->{document}; 
    44     if ( not defined $mto->{document} ) { 
    45         require Carp; 
    46         Carp::croak("Missing Padre::Document::Perl object as {document} attribute of the FindVariableDeclaration task"); 
    47     } 
     40    # move the document to the main-thread-only storage 
     41    my $mto = $self->{main_thread_only} ||= {}; 
     42    $mto->{document} = $self->{document} 
     43      if defined $self->{document}; 
     44    delete $self->{document}; 
     45    if ( not defined $mto->{document} ) { 
     46        require Carp; 
     47        Carp::croak( 
     48            "Missing Padre::Document::Perl object as {document} attribute of the FindVariableDeclaration task" 
     49        ); 
     50    } 
    4851 
    49     if ( not defined $self->{location} ) { 
    50         require Carp; 
    51         Carp::croak("Need a {location}!"); 
    52     } 
     52    if ( not defined $self->{location} ) { 
     53        require Carp; 
     54        Carp::croak("Need a {location}!"); 
     55    } 
    5356 
    54     return (); 
     57    return (); 
    5558} 
    5659 
    5760sub process_ppi { 
    58     my $self     = shift; 
    59     my $ppi      = shift or return; 
    60     my $location = $self->{location}; 
     61    my $self     = shift; 
     62    my $ppi      = shift or return; 
     63    my $location = $self->{location}; 
    6164 
    62     # TODO: PPI bug? This shouldn't be necessary! 
    63     require Padre::PPI; 
    64     $ppi->flush_locations; 
    65     my $token = Padre::PPI::find_token_at_location( $ppi, $location ); 
    66     if ( not $token ) { 
    67         $self->{error} = "no token"; 
    68         return; 
    69     } 
     65    my $declaration = eval { 
     66        PPIx::EditorTools::FindVariableDeclaration->new->find( 
     67            ppi    => $ppi, 
     68            line   => $location->[0], 
     69            column => $location->[1] ); 
     70    }; 
     71    if ($@) { 
     72        $self->{error} = $@; 
     73        return; 
     74    } 
    7075 
    71     my $declaration = Padre::PPI::find_variable_declaration($token); 
    72     if ( not defined $declaration ) { 
    73         $self->{error} = "no declaration"; 
    74         return; 
    75     } 
    76     $self->{declaration_location} = $declaration->location; 
    77     return (); 
     76    $self->{declaration_location} = $declaration->element->location; 
     77    return (); 
    7878} 
    7979 
    8080sub finish { 
    81     my $self = shift; 
    82     if ( defined $self->{declaration_location} ) { 
     81    my $self = shift; 
     82    if ( defined $self->{declaration_location} ) { 
    8383 
    84         # GUI update 
    85         $self->{main_thread_only}->{document}->ppi_select( $self->{declaration_location} ); 
    86     } else { 
    87         my $text; 
    88         if ( $self->{error} eq 'no token' ) { 
    89             $text = Wx::gettext("Current cursor does not seem to point at a variable"); 
    90         } elsif ( $self->{error} eq 'no declaration' ) { 
    91             $text = Wx::gettext("No declaration could be found for the specified (lexical?) variable"); 
    92         } else { 
    93             $text = Wx::gettext("Unknown error"); 
    94         } 
    95         Wx::MessageBox( 
    96             $text, 
    97             Wx::gettext("Search Canceled"), 
    98             Wx::wxOK, 
    99             Padre->ide->wx->main 
    100         ); 
    101     } 
    102     return (); 
     84        # GUI update 
     85        $self->{main_thread_only}->{document} 
     86          ->ppi_select( $self->{declaration_location} ); 
     87    } else { 
     88        my $text; 
     89        if ( $self->{error} =~ /no token/ ) { 
     90            $text = Wx::gettext( 
     91                "Current cursor does not seem to point at a variable"); 
     92        } elsif ( $self->{error} =~ /no declaration/ ) { 
     93            $text = Wx::gettext( 
     94                "No declaration could be found for the specified (lexical?) variable" 
     95            ); 
     96        } else { 
     97            $text = Wx::gettext("Unknown error"); 
     98        } 
     99        Wx::MessageBox( 
     100            $text,    Wx::gettext("Search Canceled"), 
     101            Wx::wxOK, Padre->ide->wx->main 
     102        ); 
     103    } 
     104    return (); 
    103105} 
    104106 
  • trunk/Padre/lib/Padre/Task/PPI/IntroduceTemporaryVariable.pm

    r5246 r5531  
    88 
    99use base 'Padre::Task::PPI'; 
     10use PPIx::EditorTools::IntroduceTemporaryVariable; 
    1011 
    1112=pod 
     
    3839 
    3940sub prepare { 
    40     my $self = shift; 
    41     $self->SUPER::prepare(@_); 
     41    my $self = shift; 
     42    $self->SUPER::prepare(@_); 
    4243 
    43     # move the document to the main-thread-only storage 
    44     my $mto = $self->{main_thread_only} ||= {}; 
    45     $mto->{document} = $self->{document} 
    46         if defined $self->{document}; 
    47     delete $self->{document}; 
    48     if ( not defined $mto->{document} ) { 
    49         require Carp; 
    50         Carp::croak("Missing Padre::Document::Perl object as {document} attribute of the temporary-variable task"); 
    51     } 
    52          
    53     foreach my $key (qw(start_location end_location)) { 
    54         if ( not defined $self->{$key} ) { 
    55             require Carp; 
    56             Carp::croak("Need a {$key}!"); 
    57         } 
    58         elsif (not ref($self->{$key})) { 
    59             my $doc = $mto->{document}; 
    60             $self->{$key} = $doc->character_position_to_ppi_location($self->{$key}); 
    61         } 
    62     } 
     44    # move the document to the main-thread-only storage 
     45    my $mto = $self->{main_thread_only} ||= {}; 
     46    $mto->{document} = $self->{document} 
     47      if defined $self->{document}; 
     48    delete $self->{document}; 
     49    if ( not defined $mto->{document} ) { 
     50        require Carp; 
     51        Carp::croak( 
     52            "Missing Padre::Document::Perl object as {document} attribute of the temporary-variable task" 
     53        ); 
     54    } 
    6355 
    64     return (); 
     56    foreach my $key (qw(start_location end_location)) { 
     57        if ( not defined $self->{$key} ) { 
     58            require Carp; 
     59            Carp::croak("Need a {$key}!"); 
     60        } elsif ( not ref( $self->{$key} ) ) { 
     61            my $doc = $mto->{document}; 
     62            $self->{$key} = 
     63              $doc->character_position_to_ppi_location( $self->{$key} ); 
     64        } 
     65    } 
     66 
     67    return (); 
    6568} 
    6669 
    6770sub process_ppi { 
    68     my $self     = shift; 
    69     my $ppi      = shift or return; 
    70     my $location = $self->{start_location}; 
     71    my $self     = shift; 
     72    my $ppi      = shift or return; 
     73    my $location = $self->{start_location}; 
    7174 
    72     # TODO: PPI bug? This shouldn't be necessary! 
    73     require Padre::PPI; 
    74     $ppi->flush_locations; 
    75     my $token = Padre::PPI::find_token_at_location( $ppi, $location ); 
    76          
    77     if ( not $token ) { 
    78         $self->{error} = "no token"; 
    79         return; 
    80     } 
     75    my $munged = eval { 
     76        PPIx::EditorTools::IntroduceTemporaryVariable->new->introduce( 
     77            ppi            => $ppi, 
     78            start_location => $self->{start_location}, 
     79            end_location   => $self->{end_location}, 
     80            varname        => $self->{varname}, 
     81        ); 
     82    }; 
     83    if ($@) { 
     84        $self->{error} = $@; 
     85        return; 
     86    } 
    8187 
    82     my $statement = $token->statement(); 
    83     if ( not defined $statement ) { 
    84         $self->{error} = "no statement"; 
    85         return; 
    86     } 
    87         # walk up the PPI tree until we reach a sort of structure that's not a statement. 
    88         # FIXME: This may or may not be robust. A PPI::Statement claims to be what's 
    89         #        defined as "statements" in perlsyn, but it's not! perlsyn says all statements 
    90         #        end in a semicolon unless at the end of a block. 
    91         #        For PPI, Statements can be part of others and thus don't necessarily have 
    92         #        a semicolon. 
    93         while (1) { 
    94           my $parent = $statement->statement(); 
    95           last if not defined $parent; 
    96           if ($parent eq $statement) { # exactly the same object, ie. is a statement already 
    97             $parent = $statement->parent(); # force the parent 
    98             last if not $parent # stop if we're at a block or at the document level 
    99                  or $parent->isa('PPI::Structure::Block') 
    100                  or $parent->isa('PPI::Structure::Document'); 
    101             $parent = $parent->statement(); # force it to be a statement 
    102           } 
    103           last if not $parent # stop if the parent isn't a statement 
    104                or not $parent->isa('PPI::Statement'); 
    105           $statement = $parent; 
    106         } 
    107  
    108     $self->{statement_location} = $statement->location; 
    109     return (); 
     88    # TODO: passing this back and forth is probably hyper-inefficient, but such is life. 
     89    $self->{updated_document_string} = $munged->code; 
     90    $self->{location}                = $munged->element->location; 
     91    return (); 
    11092} 
    11193 
    11294sub finish { 
    113     my $self = shift; 
    114     if ( defined $self->{statement_location} ) { 
    115         my $doc       = $self->{main_thread_only}->{document}; 
    116         my $editor    = $doc->editor or return; 
     95    my $self = shift; 
     96    if ( defined $self->{updated_document_string} ) { 
    11797 
    118         my $state_loc = $self->{statement_location}; 
    119  
    120         my $state_line       = $state_loc->[0]-1; 
    121         my $state_line_start = $editor->PositionFromLine( $state_line ); 
    122         my $state_line_end   = $editor->GetLineEndPosition( $state_line ); 
    123         my $state_line_text  = $editor->GetTextRange($state_line_start, $state_line_end); 
    124         my $indent = ''; 
    125         $indent = $1 if $state_line_text =~ /^(\s+)/; 
    126  
    127         my $start_pos = $doc->ppi_location_to_character_position( $self->{start_location} ); 
    128         my $end_pos   = $doc->ppi_location_to_character_position( $self->{end_location} ); 
    129  
    130         my $varname = $self->{varname}; 
    131         $varname = 'tmp' if not defined $varname; 
    132                 $varname = '$'.$varname if $varname !~ /^[\$\@\%]/; 
    133                  
    134         my $text = $doc->text_get; 
    135         my $expression = substr($text, $start_pos, $end_pos-$start_pos+1, $varname); # TODO: Pad with spaces? 
    136  
    137         my $code = "${indent}my $varname = $expression;\n"; 
    138         substr($text, $state_line_start, 0, $code); 
    139         $doc->text_set($text); 
    140         $editor->SetCurrentPos($start_pos); 
    141         $editor->SetSelection( $start_pos, $start_pos ); 
    142     } else { 
    143         my $text; 
    144         if ( $self->{error} eq 'no token' ) { 
    145             $text = Wx::gettext("First character of selection does not seem to point at a token."); 
    146         } elsif ( $self->{error} eq 'no statement' ) { 
    147             $text = Wx::gettext("Selection not part of a Perl statement?"); 
    148         } else { 
    149             $text = Wx::gettext("Unknown error"); 
    150         } 
    151         Wx::MessageBox( 
    152             $text, 
    153             Wx::gettext("Replace Operation Canceled"), 
    154             Wx::wxOK, 
    155             Padre->ide->wx->main 
    156         ); 
    157     } 
    158     return (); 
     98        # GUI update 
     99        # TODO: What if the document changed? Bad luck for now. 
     100        $self->{main_thread_only}->{document} 
     101          ->editor->SetText( $self->{updated_document_string} ); 
     102        $self->{main_thread_only}->{document}->ppi_select( $self->{location} ); 
     103    } else { 
     104        my $text; 
     105        if ( $self->{error} =~ /no token/ ) { 
     106            $text = Wx::gettext( 
     107                "First character of selection does not seem to point at a token." 
     108            ); 
     109        } elsif ( $self->{error} =~ /no statement/ ) { 
     110            $text = Wx::gettext("Selection not part of a Perl statement?"); 
     111        } else { 
     112            $text = Wx::gettext("Unknown error"); 
     113        } 
     114        Wx::MessageBox( $text, Wx::gettext("Replace Operation Canceled"), 
     115            Wx::wxOK, Padre->ide->wx->main ); 
     116    } 
     117    return (); 
    159118} 
    160119 
  • trunk/Padre/lib/Padre/Task/PPI/LexicalReplaceVariable.pm

    r5143 r5531  
    33use warnings; 
    44 
    5 our $VERSION = '0.36'; 
     5our $VERSION = '0.37'; 
    66 
    77use base 'Padre::Task::PPI'; 
    88use Padre::Wx (); 
     9use PPIx::EditorTools::RenameVariable; 
    910 
    1011=pod 
     
    3233 
    3334sub prepare { 
    34     my $self = shift; 
    35     $self->SUPER::prepare(@_); 
     35    my $self = shift; 
     36    $self->SUPER::prepare(@_); 
    3637 
    37     # move the document to the main-thread-only storage 
    38     my $mto = $self->{main_thread_only} ||= {}; 
    39     $mto->{document} = $self->{document} 
    40         if defined $self->{document}; 
    41     delete $self->{document}; 
    42     if ( not defined $mto->{document} ) { 
    43         require Carp; 
    44         Carp::croak("Missing Padre::Document::Perl object as {document} attribute of the brace-finder task"); 
    45     } 
     38    # move the document to the main-thread-only storage 
     39    my $mto = $self->{main_thread_only} ||= {}; 
     40    $mto->{document} = $self->{document} 
     41      if defined $self->{document}; 
     42    delete $self->{document}; 
     43    if ( not defined $mto->{document} ) { 
     44        require Carp; 
     45        Carp::croak( 
     46            "Missing Padre::Document::Perl object as {document} attribute of the brace-finder task" 
     47        ); 
     48    } 
    4649 
    47     if ( not defined $self->{replacement} ) { 
    48         require Carp; 
    49         Carp::croak("Need a {replacement}!"); 
    50     } 
     50    if ( not defined $self->{replacement} ) { 
     51        require Carp; 
     52        Carp::croak("Need a {replacement}!"); 
     53    } 
    5154 
    52     if ( not defined $self->{location} ) { 
    53         require Carp; 
    54         Carp::croak("Need a {location}!"); 
    55     } 
     55    if ( not defined $self->{location} ) { 
     56        require Carp; 
     57        Carp::croak("Need a {location}!"); 
     58    } 
    5659 
    57     return (); 
     60    return (); 
    5861} 
    5962 
    6063sub process_ppi { 
    6164 
    62     # find bad braces 
    63     my $self     = shift; 
    64     my $ppi      = shift or return; 
    65     my $location = $self->{location}; 
     65    # find bad braces 
     66    my $self     = shift; 
     67    my $ppi      = shift or return; 
     68    my $location = $self->{location}; 
    6669 
    67     # TODO: PPI bug? This shouldn't be necessary! 
    68     require Padre::PPI; 
    69     $ppi->flush_locations; 
    70     my $token = Padre::PPI::find_token_at_location( $ppi, $location ); 
    71     if ( not $token ) { 
    72         $self->{error} = "no token"; 
    73         return; 
    74     } 
     70    my $munged = eval { 
     71        PPIx::EditorTools::RenameVariable->new->rename( 
     72            ppi         => $ppi, 
     73            line        => $location->[0], 
     74            column      => $location->[1], 
     75            replacement => $self->{replacement}, 
     76        ); 
     77    }; 
     78    if ($@) { 
     79        $self->{error} = $@; 
     80        return; 
     81    } 
    7582 
    76     my $declaration = Padre::PPI::find_variable_declaration($token); 
    77     if ( not defined $declaration ) { 
    78         $self->{error} = "no declaration"; 
    79         return; 
    80     } 
     83    # for moving the cursor after updating the text 
     84    $self->{token_location} = $munged->element->location; 
    8185 
    82     my $scope = $declaration; 
    83     while ( not $scope->isa('PPI::Document') and not $scope->isa('PPI::Structure::Block') ) { 
    84         $scope = $scope->parent; 
    85     } 
     86    # TODO: passing this back and forth is probably hyper-inefficient, but such is life. 
     87    $self->{updated_document_string} = $munged->code; 
    8688 
    87     my $token_str = $token->content; 
    88     my $varname   = $token->symbol; 
    89  
    90     #warn "VARNAME: $varname"; 
    91  
    92     # TODO: This could be part of PPI somehow? 
    93     # The following string of hacks is simply for finding symbols in quotelikes and regexes 
    94     my $type = substr( $varname, 0, 1 ); 
    95     my $brace = $type eq '@' ? '[' : ( $type eq '%' ? '{' : '' ); 
    96  
    97     my @patterns; 
    98     if ( $type eq '@' or $type eq '%' ) { 
    99         my $accessv = $varname; 
    100         $accessv =~ s/^\Q$type\E/\$/; 
    101         @patterns = ( 
    102             quotemeta( _curlify($varname) ), quotemeta($varname), 
    103             quotemeta($accessv) . '(?=' . quotemeta($brace) . ')', 
    104         ); 
    105         if ( $type eq '%' ) { 
    106             my $slicev = $varname; 
    107             $slicev =~ s/^\%/\@/; 
    108             push @patterns, quotemeta($slicev) . '(?=' . quotemeta($brace) . ')'; 
    109         } elsif ( $type eq '@' ) { 
    110             my $indexv = $varname; 
    111             $indexv =~ s/^\@/\$\#/; 
    112             push @patterns, quotemeta($indexv); 
    113         } 
    114     } else { 
    115         @patterns = ( quotemeta( _curlify($varname) ), quotemeta($varname) . "(?![\[\{])" ); 
    116     } 
    117     my %unique; 
    118     my $finder_regexp = '(?:' . join( '|', grep { !$unique{$_}++ } @patterns ) . ')'; 
    119  
    120     $finder_regexp = qr/$finder_regexp/;    # used to find symbols in quotelikes and regexes 
    121                                             #warn $finder_regexp; 
    122  
    123     my $replacement = $self->{replacement}; 
    124     $replacement =~ s/^\W+//; 
    125  
    126     $scope->find( 
    127         sub { 
    128             my $node = $_[1]; 
    129             if ( $node->isa("PPI::Token::Symbol") ) { 
    130                 return 0 unless $node->symbol eq $varname; 
    131  
    132                 # TODO do this without breaking encapsulation! 
    133                 $node->{content} = substr( $node->content(), 0, 1 ) . $replacement; 
    134             } 
    135             if ( $type eq '@' and $node->isa("PPI::Token::ArrayIndex") ) {    # $#foo 
    136                 return 0 unless substr( $node->content, 2 ) eq substr( $varname, 1 ); 
    137  
    138                 # TODO do this without breaking encapsulation! 
    139                 $node->{content} = '$#' . $replacement; 
    140             } elsif ( $node->isa("PPI::Token") ) {    # the case of potential quotelikes and regexes 
    141                 my $str = $node->content; 
    142                 if ($str =~ s{($finder_regexp)([\[\{]?)}< 
    143                         if ($1 =~ tr/{//) { substr($1, 0, ($1=~tr/#//)+1) . "{$replacement}$2" } 
    144                         else              { substr($1, 0, ($1=~tr/#//)+1) . "$replacement$2" } 
    145                     >ge 
    146                     ) 
    147                 { 
    148  
    149                     # TODO do this without breaking encapsulation! 
    150                     $node->{content} = $str; 
    151                 } 
    152             } 
    153             return 0; 
    154         }, 
    155     ); 
    156  
    157     $self->{token_location} = $token->location;    # for moving the cursor after updating the text 
    158          # TODO: passing this back and forth is probably hyper-inefficient, but such is life. 
    159     $self->{updated_document_string} = $ppi->serialize; 
    160  
    161     return (); 
    162 } 
    163  
    164 sub _curlify { 
    165     my $var = shift; 
    166     if ( $var =~ s/^([\$\@\%])(.+)$/${1}{$2}/ ) { 
    167         return ($var); 
    168     } 
    169     return (); 
     89    return (); 
    17090} 
    17191 
    17292sub finish { 
    173     my $self = shift; 
    174     if ( defined $self->{updated_document_string} ) { 
     93    my $self = shift; 
     94    if ( defined $self->{updated_document_string} ) { 
    17595 
    176         # GUI update 
    177         # TODO: What if the document changed? Bad luck for now. 
    178         $self->{main_thread_only}->{document}->editor->SetText( $self->{updated_document_string} ); 
    179         $self->{main_thread_only}->{document}->ppi_select( $self->{token_location} ); 
    180     } else { 
    181         my $text; 
    182         if ( $self->{error} eq 'no token' ) { 
    183             $text = Wx::gettext("Current cursor does not seem to point at a variable"); 
    184         } elsif ( $self->{error} eq 'no declaration' ) { 
    185             $text = Wx::gettext("No declaration could be found for the specified (lexical?) variable"); 
    186         } else { 
    187             $text = Wx::gettext("Unknown error"); 
    188         } 
    189         Wx::MessageBox( 
    190             $text, 
    191             Wx::gettext("Replace Operation Canceled"), 
    192             Wx::wxOK, 
    193             Padre->ide->wx->main 
    194         ); 
    195     } 
    196     return (); 
     96        # GUI update 
     97        # TODO: What if the document changed? Bad luck for now. 
     98        $self->{main_thread_only}->{document} 
     99          ->editor->SetText( $self->{updated_document_string} ); 
     100        $self->{main_thread_only}->{document} 
     101          ->ppi_select( $self->{token_location} ); 
     102    } else { 
     103        my $text; 
     104        if ( $self->{error} =~ /no token/ ) { 
     105            $text = Wx::gettext( 
     106                "Current cursor does not seem to point at a variable"); 
     107        } elsif ( $self->{error} =~ /no declaration/ ) { 
     108            $text = Wx::gettext( 
     109                "No declaration could be found for the specified (lexical?) variable" 
     110            ); 
     111        } else { 
     112            $text = Wx::gettext("Unknown error"); 
     113        } 
     114        Wx::MessageBox( $text, Wx::gettext("Replace Operation Canceled"), 
     115            Wx::wxOK, Padre->ide->wx->main ); 
     116    } 
     117    return (); 
    197118} 
    198119 
Note: See TracChangeset for help on using the changeset viewer.