Padre
view release on metacpan or search on metacpan
lib/Padre/Wx/Main.pm view on Meta::CPAN
sub show_statusbar {
my $self = shift;
my $show = $_[0] ? 1 : 0;
my $lock = $self->lock('CONFIG');
$self->config->set( main_statusbar => $show );
# Update the status bar
if ($show) {
$self->GetStatusBar->Show;
} else {
$self->GetStatusBar->Hide;
}
# Explicit refresh of the AUI manager.
$self->aui->Update;
$self->menu->view->refresh;
return;
}
=pod
=head3 C<on_toggle_lockinterface>
$main->on_toggle_lockinterface;
Toggle possibility for user to change Padre's external aspect. No
return value.
=cut
sub on_toggle_lockinterface {
my $self = shift;
my $lock = $self->lock('CONFIG');
# Update setting
$self->config->apply(
'main_lockinterface',
$self->menu->view->{lockinterface}->IsChecked ? 1 : 0,
);
return;
}
=pod
=head3 C<on_insert_from_file>
$main->on_insert_from_file;
Prompt user for a file to be inserted at current position in current
document. No return value.
=cut
sub on_insert_from_file {
my $self = shift;
my $editor = $self->current->editor or return;
# popup the window
my $last_filename = $self->current->filename;
if ($last_filename) {
$self->{cwd} = File::Basename::dirname($last_filename);
}
my $dialog = Wx::FileDialog->new(
$self, Wx::gettext('Open file'),
$self->cwd, '',
Wx::gettext('All Files') . ( Padre::Constant::WIN32 ? '|*.*' : '|*' ),
Wx::FD_OPEN,
);
if ( $dialog->ShowModal == Wx::ID_CANCEL ) {
return;
}
my $filename = $dialog->GetFilename;
$self->{cwd} = $dialog->GetDirectory;
my $file = File::Spec->catfile( $self->cwd, $filename );
$editor->insert_from_file($file);
return;
}
=pod
=head3 C<convert_to>
$main->convert_to( $eol_style );
Convert document to C<$eol_style> line endings (can be one of C<WIN>,
C<UNIX>, or C<MAC>). No return value.
=cut
sub convert_to {
my $self = shift;
my $newline = shift;
$self->current->editor->convert_eols($newline);
$self->refresh;
}
=pod
=head3 C<editor_of_file>
my $editor = $main->editor_of_file( $file );
Return the editor (a C<Padre::Wx::Editor> object) containing the wanted
C<$file>, or C<undef> if file is not opened currently.
=cut
sub editor_of_file {
require Padre::File;
my $self = shift;
my $file = Padre::File->new(shift); # This reformats our filename
my $notebook = $self->notebook;
foreach my $id ( $self->pageids ) {
my $editor = $notebook->GetPage($id) or return;
my $document = $editor->{Document} or return;
defined( $document->{file} ) or next;
lib/Padre/Wx/Main.pm view on Meta::CPAN
# Remove trailing space from selected text
$selected =~ s/([^\n\S]+)$//mg;
# Replace only if the selection is changed
unless ( $selected eq $current->text ) {
$current->editor->ReplaceSelection($selected);
}
return;
}
=pod
=head3 C<on_delete_leading_spaces>
$main->on_delete_leading_spaces;
Trim all leading spaces in current selection. No return value.
=cut
sub on_delete_leading_spaces {
my $self = shift;
my $current = $self->current;
my $document = $current->document or return;
my $selected = $current->text;
unless ( length $selected ) {
return $document->delete_leading_spaces;
}
# Remove trailing space from selected text
$selected =~ s/^[ \t]+//mg;
# Replace only if the selection is changed
unless ( $selected eq $current->text ) {
$current->editor->ReplaceSelection($selected);
}
return;
}
=pod
=head3 C<timer_check_overwrite>
$main->timer_check_overwrite;
Called every n seconds to check if file has been overwritten outside of
Padre. If that's the case, prompts the user whether s/he wants to reload
the document. No return value.
=cut
sub timer_check_overwrite {
my $self = shift;
my $doc = $self->current->document or return;
my $state = $doc->has_changed_on_disk; # 1 = updated, 0 = unchanged, -1 = deleted
return unless $state;
return if $doc->{_already_popup_file_changed};
$doc->{_already_popup_file_changed} = 1;
$self->reload_dialog( no_fresh => 1 );
return;
}
=pod
=head3 C<on_duplicate>
$main->on_duplicate;
Create a new document and copy the contents of the current file.
No return value.
=cut
sub on_duplicate {
my $self = shift;
my $document = $self->current->document or return;
return $self->new_document_from_string(
$document->text_get,
$document->mimetype,
);
}
=pod
=head2 Code Starter Methods
These methods provide skeleton generators for a variety of file types, with
the preferences of the user applied already.
=head3 C<start_perl6_script>
$main->start_perl6_script;
Create a new blank Perl 6 script, applying the user's style preferences if
possible.
=cut
# For now, we don't actually apply their style preferences
sub start_perl6_script {
my $self = shift;
# Generate the code from the script template
require Padre::Template;
my $code = Padre::Template->render('perl6/script_p6.tt');
# Show the new file in a new editor window
$self->new_document_from_string( $code, 'application/x-perl6' );
}
=pod
=head2 Auxiliary Methods
Various methods that did not fit exactly in above categories...
=head3 C<action>
( run in 0.803 second using v1.01-cache-2.11-cpan-364913b4093 )