Ticket #1239: PerlTidy.pm.patch
| File PerlTidy.pm.patch, 4.8 KB (added by bowtie, 23 months ago) |
|---|
-
lib/Padre/Plugin/PerlTidy.pm
23 23 use Padre::Plugin (); 24 24 use base 'Padre::Plugin'; 25 25 26 our $VERSION = 0.17; 27 26 our $VERSION = 0.18; 27 use File::Spec::Functions; 28 use FindBin qw($Bin); 29 use Perl::Tidy; 28 30 29 31 # This constant is used when storing 30 32 # and restoring the cursor position. 31 33 # Keep it small to limit resource use. 32 use constant { 33 SELECTIONSIZE => 40, 34 }; 34 use constant { SELECTIONSIZE => 40, }; 35 35 36 36 sub padre_interfaces { 37 'Padre::Plugin' => '0.43', 'Padre::Config' => '0.54'; 37 return ( 38 'Padre::Plugin' => '0.43', 39 'Padre::Config' => '0.54', 40 'Padre::Wx::Main' => '0.86', 41 ); 38 42 } 39 43 40 44 sub plugin_name { 41 Wx::gettext('Perl Tidy');45 return Wx::gettext('Perl Tidy'); 42 46 } 43 47 44 48 sub menu_plugins_simple { … … 52 56 \&export_document, 53 57 Wx::gettext('Export selected text to HTML file') => 54 58 \&export_selection, 55 '---' => undef, 56 Wx::gettext('Configure tidy') => 57 \&configure_tidy, 59 '---' => undef, 60 Wx::gettext('Configure tidy') => \&configure_tidy, 58 61 ]; 59 62 } 60 63 64 my $over_ride; 65 61 66 sub _tidy { 62 67 my $main = shift; 63 68 my $current = shift; … … 82 87 destination => \$destination, 83 88 errorfile => \$errorfile, 84 89 ); 90 if ($over_ride) { 91 $tidyargs{'perltidyrc'} = $perltidyrc; 92 } 85 93 86 #Make sure output is visible... 87 $main->show_output(1); 88 my $output = $main->output; 94 my $output; 95 if ( $main->config->info_on_statusbar ) { 96 97 # print "info_on_statusbar: " . $main->config->info_on_statusbar . "\n"; 98 $main->info( Wx::gettext("Running Tidy, don't forget to save changes.") ); 99 } else { 100 101 #Make sure output is visible... 102 $main->show_output(1); 103 $output = $main->output; 104 } 89 105 90 106 # CLAUDIO: This code breaks the plugin, temporary disabled. 91 107 # Have a look at Perl::Tidy line 126 for details: expecting a reference related to a file and not Wx::CommandEvent). … … 101 117 # } 102 118 103 119 # TODO: suppress the senseless warning from PerlTidy 104 require Perl::Tidy;120 # require Perl::Tidy; 105 121 eval { Perl::Tidy::perltidy(%tidyargs); }; 106 122 107 123 if ($@) { … … 110 126 } 111 127 112 128 if ( defined $errorfile ) { 113 my $filename = $document->filename ? $document->filename : $document->get_title; 129 $main->show_output(1); 130 $output = $main->output; 131 my $filename = 132 $document->filename 133 ? $document->filename 134 : $document->get_title; 114 135 my $width = length($filename) + 2; 115 136 $output->AppendText( "\n\n" . "-" x $width . "\n" . $filename . "\n" . "-" x $width . "\n" ); 116 137 $output->AppendText("$errorfile\n"); … … 126 147 # Tidy the current selected text 127 148 my $current = $main->current; 128 149 my $text = $current->text; 129 my $tidy = _tidy( $main, $current, $text, $perltidyrc ); 150 $over_ride = 0; 151 $perltidyrc = _which_tidyrc( $main, $perltidyrc ); 152 my $tidy = _tidy( $main, $current, $text, $perltidyrc ); 130 153 unless ( defined Params::Util::_STRING($tidy) ) { 131 154 return; 132 155 } … … 155 178 my $current = $main->current; 156 179 my $document = $current->document; 157 180 my $text = $document->text_get; 158 my $tidy = _tidy( $main, $current, $text, $perltidyrc ); 181 $over_ride = 0; 182 $perltidyrc = _which_tidyrc( $main, $perltidyrc ); 183 my $tidy = _tidy( $main, $current, $text, $perltidyrc ); 159 184 unless ( defined Params::Util::_STRING($tidy) ) { 160 185 return; 161 186 } … … 193 218 $default_dir = $dialog->GetDirectory; 194 219 my $path = File::Spec->catfile( $default_dir, $filename ); 195 220 if ( -e $path ) { 196 return $path if $main->yes_no( Wx::gettext("File already exists. Overwrite it?"), Wx::gettext("Exist") ); 221 return $path 222 if $main->yes_no( 223 Wx::gettext("File already exists. Overwrite it?"), 224 Wx::gettext("Exist") 225 ); 197 226 } else { 198 227 return $path; 199 228 } … … 266 295 267 296 sub export_document { 268 297 269 270 298 my $main = shift; 271 299 my $text = $main->current->document->text_get; 272 300 _export( $main, $text ); … … 341 369 return; 342 370 } 343 371 372 ####### 373 # method _which_tidyrc 374 # Pick the revelant tidyrc file 375 ####### 376 sub _which_tidyrc { 377 my $main = shift; 378 my $perltidyrc = shift; 379 380 # perl tidy Padre/tools 381 if ( $ENV{'PADRE_DEV'} ) { 382 eval { $perltidyrc = catfile( $Bin, '../../tools/perltidyrc' ); }; 383 if ( -e $perltidyrc ) { 384 $over_ride = 1; 385 return $perltidyrc; 386 } else { 387 388 # $main->info_on_statusbar(0); 389 $main->info( Wx::gettext("You need to install from SVN Padre/tools.") ); 390 391 # $main->info_on_statusbar(1); 392 } 393 394 } 395 396 # perl tidy, PBP 397 elsif ( $main->config->lang_perl5_beginner ) { 398 my $pbprc = $INC{'Padre/Plugin/PerlTidy.pm'}; 399 $pbprc =~ s/\.pm//; 400 401 eval { $perltidyrc = catfile( $pbprc, 'pbptidyrc' ); }; 402 if ( -e $perltidyrc ) { 403 $over_ride = 1; 404 return $perltidyrc; 405 } 406 } 407 return; 408 } 409 344 410 1; 345 411 346 412 =pod
