Changeset 5531
- Timestamp:
- 06/24/09 13:45:04 (3 years ago)
- Location:
- trunk
- Files:
-
- 34 added
- 6 edited
-
PPIx-EditorTools (added)
-
PPIx-EditorTools/Build.PL (added)
-
PPIx-EditorTools/INSTALL (added)
-
PPIx-EditorTools/MANIFEST (added)
-
PPIx-EditorTools/MANIFEST.SKIP (added)
-
PPIx-EditorTools/META.yml (added)
-
PPIx-EditorTools/README (added)
-
PPIx-EditorTools/TODO (added)
-
PPIx-EditorTools/lib (added)
-
PPIx-EditorTools/lib/PPIx (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools.pm (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools/FindUnmatchedBrace.pm (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools/FindVariableDeclaration.pm (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools/IntroduceTemporaryVariable.pm (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools/RenamePackage.pm (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools/RenamePackageFromPath.pm (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools/RenameVariable.pm (added)
-
PPIx-EditorTools/lib/PPIx/EditorTools/ReturnObject.pm (added)
-
PPIx-EditorTools/t (added)
-
PPIx-EditorTools/t/00-use.t (added)
-
PPIx-EditorTools/t/10-findunmatchedbrace.t (added)
-
PPIx-EditorTools/t/10-findvariabledeclaration.t (added)
-
PPIx-EditorTools/t/10-introducetemporaryvariable.t (added)
-
PPIx-EditorTools/t/10-renamepackage.t (added)
-
PPIx-EditorTools/t/10-renamepackagefrompath.t (added)
-
PPIx-EditorTools/t/10-renamevariable.t (added)
-
PPIx-EditorTools/xt (added)
-
PPIx-EditorTools/xt/95-prereq.t (added)
-
PPIx-EditorTools/xt/96-kwalitee.t (added)
-
PPIx-EditorTools/xt/97-critic.t (added)
-
PPIx-EditorTools/xt/98-pod.t (added)
-
PPIx-EditorTools/xt/99-podcoverage.t (added)
-
PPIx-EditorTools/xt/perlcriticrc (added)
-
Padre/Makefile.PL (modified) (1 diff)
-
Padre/dev.pl (modified) (1 diff)
-
Padre/lib/Padre/Task/PPI/FindUnmatchedBrace.pm (modified) (3 diffs)
-
Padre/lib/Padre/Task/PPI/FindVariableDeclaration.pm (modified) (2 diffs)
-
Padre/lib/Padre/Task/PPI/IntroduceTemporaryVariable.pm (modified) (2 diffs)
-
Padre/lib/Padre/Task/PPI/LexicalReplaceVariable.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/Makefile.PL
r5258 r5531 77 77 requires 'POSIX' => 0; 78 78 requires 'PPI' => '1.203'; 79 requires 'PPIx::EditorTools' => 0; 79 80 requires 'Probe::Perl' => '0.01'; 80 81 requires 'Storable' => '2.15'; -
trunk/Padre/dev.pl
r5403 r5531 32 32 qq[-I$FindBin::Bin/lib], 33 33 qq[-I$FindBin::Bin/blib/lib], 34 qq[-I$FindBin::Bin/../PPIx-EditorTools/lib], 34 35 ); 35 36 if ( grep { $_ eq '-d' } @ARGV ) { -
trunk/Padre/lib/Padre/Task/PPI/FindUnmatchedBrace.pm
r4977 r5531 1 2 1 package Padre::Task::PPI::FindUnmatchedBrace; 3 2 use strict; … … 8 7 use base 'Padre::Task::PPI'; 9 8 use Padre::Wx(); 9 use PPIx::EditorTools::FindUnmatchedBrace; 10 10 11 11 =pod … … 34 34 35 35 sub prepare { 36 my $self = shift;37 $self->SUPER::prepare(@_);36 my $self = shift; 37 $self->SUPER::prepare(@_); 38 38 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 (); 49 51 } 50 52 51 53 sub process_ppi { 52 54 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 (); 67 68 } 68 69 69 70 sub finish { 70 my $self = shift;71 if ( defined $self->{bad_element} ) {71 my $self = shift; 72 if ( defined $self->{bad_element} ) { 72 73 73 # GUI update74 $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->main81 );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 (); 84 85 } 85 86 -
trunk/Padre/lib/Padre/Task/PPI/FindVariableDeclaration.pm
r5145 r5531 8 8 9 9 use base 'Padre::Task::PPI'; 10 use PPIx::EditorTools::FindVariableDeclaration; 10 11 11 12 =pod … … 34 35 35 36 sub prepare { 36 my $self = shift;37 $self->SUPER::prepare(@_);37 my $self = shift; 38 $self->SUPER::prepare(@_); 38 39 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 } 48 51 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 } 53 56 54 return ();57 return (); 55 58 } 56 59 57 60 sub 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}; 61 64 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 } 70 75 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 (); 78 78 } 79 79 80 80 sub finish { 81 my $self = shift;82 if ( defined $self->{declaration_location} ) {81 my $self = shift; 82 if ( defined $self->{declaration_location} ) { 83 83 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 (); 103 105 } 104 106 -
trunk/Padre/lib/Padre/Task/PPI/IntroduceTemporaryVariable.pm
r5246 r5531 8 8 9 9 use base 'Padre::Task::PPI'; 10 use PPIx::EditorTools::IntroduceTemporaryVariable; 10 11 11 12 =pod … … 38 39 39 40 sub prepare { 40 my $self = shift;41 $self->SUPER::prepare(@_);41 my $self = shift; 42 $self->SUPER::prepare(@_); 42 43 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 } 63 55 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 (); 65 68 } 66 69 67 70 sub 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}; 71 74 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 } 81 87 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 (); 110 92 } 111 93 112 94 sub 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} ) { 117 97 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 (); 159 118 } 160 119 -
trunk/Padre/lib/Padre/Task/PPI/LexicalReplaceVariable.pm
r5143 r5531 3 3 use warnings; 4 4 5 our $VERSION = '0.3 6';5 our $VERSION = '0.37'; 6 6 7 7 use base 'Padre::Task::PPI'; 8 8 use Padre::Wx (); 9 use PPIx::EditorTools::RenameVariable; 9 10 10 11 =pod … … 32 33 33 34 sub prepare { 34 my $self = shift;35 $self->SUPER::prepare(@_);35 my $self = shift; 36 $self->SUPER::prepare(@_); 36 37 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 } 46 49 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 } 51 54 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 } 56 59 57 return ();60 return (); 58 61 } 59 62 60 63 sub process_ppi { 61 64 62 # find bad braces63 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}; 66 69 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 } 75 82 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; 81 85 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; 86 88 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 (); 170 90 } 171 91 172 92 sub finish { 173 my $self = shift;174 if ( defined $self->{updated_document_string} ) {93 my $self = shift; 94 if ( defined $self->{updated_document_string} ) { 175 95 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 (); 197 118 } 198 119
Note: See TracChangeset
for help on using the changeset viewer.
