| 1 | package Padre::Plugin::ParserTool; | ||
| 2 | |||
| 3 | use 5.008005; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Params::Util 1.00 (); | ||
| 7 | use Padre::Plugin 0.89 (); | ||
| 8 | |||
| 9 | our $VERSION = '0.01'; | ||
| 10 | our @ISA = 'Padre::Plugin'; | ||
| 11 | |||
| 12 | # Child modules we need to unload when disabled | ||
| 13 | use constant CHILDREN => qw{ | ||
| 14 | Padre::Plugin::ParserTool | ||
| 15 | Padre::Plugin::ParserTool::Dialog | ||
| 16 | Padre::Plugin::ParserTool::FBP | ||
| 17 | }; | ||
| 18 | |||
| 19 | ###################################################################### | ||
| 20 | # Configuration Methods | ||
| 21 | |||
| 22 | sub plugin_name { | ||
| 23 | Wx::gettext('Parser Tool'); | ||
| 24 | } | ||
| 25 | |||
| 26 | sub padre_interfaces { | ||
| 27 | 'Padre::Plugin' => '0.89', 'Padre::Wx' => '0.89', 'Padre::Wx::Role::Dialog' => '0.89',; | ||
| 28 | } | ||
| 29 | |||
| 30 | sub menu_plugins { | ||
| 31 | my $self = shift; | ||
| 32 | my $main = shift; | ||
| 33 | |||
| 34 | # Create a manual menu item | ||
| 35 | my $item = Wx::MenuItem->new( | ||
| 36 | undef, | ||
| 37 | -1, | ||
| 38 | $self->plugin_name, | ||
| 39 | ); | ||
| 40 | Wx::Event::EVT_MENU( | ||
| 41 | $main, $item, | ||
| 42 | sub { | ||
| 43 | local $@; | ||
| 44 | eval { $self->menu_dialog($main); }; | ||
| 45 | }, | ||
| 46 | ); | ||
| 47 | |||
| 48 | return $item; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub plugin_disable { | ||
| 52 | my $self = shift; | ||
| 53 | |||
| 54 | # Clean up the dialog if it is still open | ||
| 55 | if ( $self->{dialog} ) { | ||
| 56 | $self->{dialog}->Hide; | ||
| 57 | $self->{dialog}->Destroy; | ||
| 58 | delete $self->{dialog}; | ||
| 59 | } | ||
| 60 | |||
| 61 | # TODO: Switch to Padre::Unload once Padre 0.96 is released | ||
| 62 | for my $package (CHILDREN) { | ||
| 63 | require Padre::Unload; | ||
| 64 | Padre::Unload->unload($package); | ||
| 65 | } | ||
| 66 | |||
| 67 | $self->SUPER::plugin_disable(@_); | ||
| 68 | } | ||
| 69 | |||
| 70 | ###################################################################### | ||
| 71 | # Main Methods | ||
| 72 | |||
| 73 | sub menu_dialog { | ||
| 74 | my $self = shift; | ||
| 75 | my $main = shift; | ||
| 76 | |||
| 77 | # Spawn the dialog | ||
| 78 | require Padre::Plugin::ParserTool::Dialog; | ||
| 79 | unless ( $self->{dialog} ) { | ||
| 80 | $self->{dialog} = Padre::Plugin::ParserTool::Dialog->new($main); | ||
| 81 | } | ||
| 82 | $self->{dialog}->refresh; | ||
| 83 | $self->{dialog}->ShowModal; | ||
| 84 | |||
| 85 | return; | ||
| 86 | } | ||
| 87 | |||
| 88 | 1; | ||
| 89 | |||
| 90 | __END__ |