Padre-Plugin-Moose
view release on metacpan or search on metacpan
lib/Padre/Plugin/Moose/Assistant.pm view on Meta::CPAN
# Generate the context menu for this element
my $menu = Wx::Menu->new;
Wx::Event::EVT_MENU(
$self,
$menu->Append( -1, Wx::gettext('Delete') ),
sub {
$self->delete_element($element);
}
);
# Pops up the context menu
$tree->PopupMenu(
$menu,
$event->GetPoint->x,
$event->GetPoint->y,
);
return;
}
sub on_tree_key_up {
my $self = shift;
my $event = shift;
my $mod = $event->GetModifiers || 0;
# see Padre::Wx::Main::key_up
$mod = $mod & ( Wx::MOD_ALT + Wx::MOD_CMD + Wx::MOD_SHIFT );
my $tree = $self->{tree};
my $item_id = $tree->GetSelection;
my $element = $tree->GetPlData($item_id) or return;
if ( $event->GetKeyCode == Wx::K_DELETE ) {
$self->delete_element($element);
}
$event->Skip;
return;
}
sub delete_element {
my $self = shift;
my $element = shift or return;
if ( $self->yes_no( sprintf( Wx::gettext('Do you want to delete %s?'), $element->name ) ) ) {
#TODO do the actual item deletion
}
return;
}
sub on_preferences_button_clicked {
my $self = shift;
# Create a new preferences dialog
require Padre::Plugin::Moose::Preferences;
my $prefs = Padre::Plugin::Moose::Preferences->new($self);
# Update plugin variables from plugin's configuration hash
my $plugin = $self->{plugin};
my $config = $plugin->{config};
$prefs->{generated_code_combo}->SetValue( $config->{type} );
$prefs->{comments_checkbox}->SetValue( $config->{comments} );
$prefs->{sample_code_checkbox}->SetValue( $config->{sample_code} );
$prefs->{namespace_autoclean_checkbox}->SetValue( $config->{namespace_autoclean} );
# Preferences: go modal!
if ( $prefs->ShowModal == Wx::wxID_OK ) {
# Update configuration when the user hits the OK button
my $type = $prefs->{generated_code_combo}->GetValue;
$config->{type} = $type;
$config->{comments} = $prefs->{comments_checkbox}->IsChecked;
$config->{sample_code} = $prefs->{sample_code_checkbox}->IsChecked;
$config->{namespace_autoclean} = $prefs->{namespace_autoclean_checkbox}->IsChecked;
$plugin->config_write($config);
# Update tree and preview editor
$self->show_code_in_preview(1);
# Add moose et all keywords highlight to preview editor
require Padre::Plugin::Moose::Util;
Padre::Plugin::Moose::Util::add_moose_keywords_highlighting( $self->{preview}->{Document}, $type );
# Add moose et all keywords highlight to current editor
my $doc = $self->current->document or return;
if ( $doc->isa('Padre::Plugin::Moose::Document') ) {
Padre::Plugin::Moose::Util::add_moose_keywords_highlighting( $doc, $type );
}
}
return;
}
1;
# Copyright 2008-2012 The Padre development team as listed in Padre.pm.
# LICENSE
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl 5 itself.
( run in 1.424 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )