Padre-Plugin-Perl6
view release on metacpan or search on metacpan
lib/Padre/Plugin/Perl6.pm view on Meta::CPAN
$self->{menu}->Append( -1, Wx::gettext("Preferences"), ),
sub { $self->plugin_preferences; },
);
# the famous about menu item...
Wx::Event::EVT_MENU(
$main,
$self->{menu}->Append( -1, Wx::gettext("About"), ),
sub { $self->show_about },
);
# Return our plugin with its label
return ( $self->plugin_name => $self->{menu} );
}
sub registered_documents {
'application/x-perl6' => 'Padre::Plugin::Perl6::Document',;
}
sub provided_highlighters {
return (
[ 'Padre::Plugin::Perl6::StdColorizer', 'STD.pm', 'Larry Wall\'s Perl 6 reference grammar' ],
);
}
sub highlighting_mime_types {
return (
'Padre::Plugin::Perl6::StdColorizer' => ['application/x-perl6'],
# 'Padre::Plugin::Perl6::Perl6PgeColorizer' => ['application/x-perl6'],
);
}
# create a Perl 6 file from the template
sub _create_from_template {
my ( $self, $template, $extension ) = @_;
$self->main->on_new;
my $editor = $self->current->editor or return;
my $file = File::Spec->catdir( $self->_sharedir, "templates", "$template.$extension" );
if ( $editor->insert_from_file($file) ) {
my $document = $editor->{Document};
$document->{original_content} = $document->text_get;
$document->set_mimetype( $document->guess_mimetype );
$document->editor->padre_setup;
$document->rebless;
$document->colourize;
} else {
$self->main->message( sprintf( Wx::gettext("Error loading template file '%s'"), $file ) );
}
return;
}
sub plugin_preferences {
my $self = shift;
require Padre::Plugin::Perl6::Preferences;
my $prefs = Padre::Plugin::Perl6::Preferences->new($self);
$prefs->Show;
}
sub show_about {
my $self = shift;
require Syntax::Highlight::Perl6;
require App::Grok;
my $about = Wx::AboutDialogInfo->new;
$about->SetName("Padre::Plugin::Perl6");
$about->SetDescription( Wx::gettext("This plugin enables useful Perl 6 features on Padre IDE.") . "\n"
. Wx::gettext("It integrates coloring and easy access to Perl 6 help documents.") . "\n\n"
. Wx::gettext("The following modules are used:") . "\n"
. "Syntax::Highlight::Perl6 "
. $Syntax::Highlight::Perl6::VERSION . "\n"
. "App::Grok "
. $App::Grok::VERSION
. "\n" );
$about->SetVersion($Padre::Plugin::Perl6::VERSION);
# create and return the camelia icon
my $camelia_path = File::Spec->catfile( $self->_sharedir, 'icons', 'camelia-big.png' );
my $camelia_bmp = Wx::Bitmap->new( $camelia_path, Wx::wxBITMAP_TYPE_PNG );
my $camelia_icon = Wx::Icon->new();
$camelia_icon->CopyFromBitmap($camelia_bmp);
$about->SetIcon($camelia_icon);
Wx::AboutBox($about);
return;
}
sub show_perl6_doc {
my $self = shift;
# find the word under the current cursor position
my $topic = '';
my $doc = $self->current->document;
if ( $doc && $doc->mimetype eq q{application/x-perl6} ) {
# make sure it is a Perl6 document
my $editor = $doc->editor;
$topic = $editor->GetSelectedText;
if ( not $topic ) {
my $lineno = $editor->GetCurrentLine();
my $line = $editor->GetLine($lineno);
my $current_pos = $editor->GetCurrentPos() - $editor->PositionFromLine($lineno);
my $current_word = '';
while ( $line =~ m/\G.*?(\S+)/g ) {
if ( pos($line) >= $current_pos ) {
$current_word = $1;
last;
}
}
if ( $current_word =~ /^.*?(\S+)/ ) {
$topic = $1;
}
}
}
}
( run in 1.052 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )