| 1 | package Padre::Plugin::Cookbook; | ||
| 2 | |||
| 3 | 3 | ▶ | use 5.010001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 0 | ▶ | use Padre::Plugin; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use Padre::Util; | ||
| 9 | use Padre::Wx; | ||
| 10 | |||
| 11 | our $VERSION = '0.24'; | ||
| 12 | use parent qw(Padre::Plugin); | ||
| 13 | |||
| 14 | # Child modules we need to unload when disabled | ||
| 15 | use constant CHILDREN => qw{ | ||
| 16 | Padre::Plugin::Cookbook::Recipe01::Main | ||
| 17 | Padre::Plugin::Cookbook::Recipe01::FBP::MainFB | ||
| 18 | Padre::Plugin::Cookbook::Recipe02::Main | ||
| 19 | Padre::Plugin::Cookbook::Recipe02::FBP::MainFB | ||
| 20 | Padre::Plugin::Cookbook::Recipe03::Main | ||
| 21 | Padre::Plugin::Cookbook::Recipe03::FBP::MainFB | ||
| 22 | Padre::Plugin::Cookbook::Recipe03::About | ||
| 23 | Padre::Plugin::Cookbook::Recipe03::FBP::AboutFB | ||
| 24 | Padre::Plugin::Cookbook::Recipe04::Main | ||
| 25 | Padre::Plugin::Cookbook::Recipe04::FBP::MainFB | ||
| 26 | Padre::Plugin::Cookbook::Recipe04::About | ||
| 27 | Padre::Plugin::Cookbook::Recipe04::FBP::AboutFB | ||
| 28 | }; | ||
| 29 | |||
| 30 | ####### | ||
| 31 | # Define Padre Interfaces required | ||
| 32 | ####### | ||
| 33 | sub padre_interfaces { | ||
| 34 | return ( | ||
| 35 | |||
| 36 | # Default, required | ||
| 37 | 'Padre::Plugin' => '0.96', | ||
| 38 | |||
| 39 | # used by Main, About and by Padre::Plugin::FormBuilder | ||
| 40 | 'Padre::Wx' => '0.96', | ||
| 41 | 'Padre::Wx::Main' => '0.96', | ||
| 42 | 'Padre::Wx::Role::Main' => '0.96', | ||
| 43 | 'Padre::DB' => '0.96', | ||
| 44 | 'Padre::Logger' => '0.96', | ||
| 45 | ); | ||
| 46 | } | ||
| 47 | |||
| 48 | ####### | ||
| 49 | # Define Plugin Name required | ||
| 50 | ####### | ||
| 51 | sub plugin_name { | ||
| 52 | return Wx::gettext('Plugin Cookbook'); | ||
| 53 | } | ||
| 54 | |||
| 55 | ####### | ||
| 56 | # Add Plugin to Padre Menu | ||
| 57 | ####### | ||
| 58 | sub menu_plugins_simple { | ||
| 59 | my $self = shift; | ||
| 60 | return $self->plugin_name => [ | ||
| 61 | Wx::gettext('01 - Hello World') => sub { | ||
| 62 | $self->load_dialog_recipe01_main; | ||
| 63 | }, | ||
| 64 | Wx::gettext('02 - Fun with widgets...') => sub { | ||
| 65 | $self->load_dialog_recipe02_main; | ||
| 66 | }, | ||
| 67 | Wx::gettext('03 - About dialogs...') => sub { | ||
| 68 | $self->load_dialog_recipe03_main; | ||
| 69 | }, | ||
| 70 | Wx::gettext('04 - ConfigDB...') => sub { | ||
| 71 | $self->load_dialog_recipe04_main; | ||
| 72 | }, | ||
| 73 | ]; | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | ####### | ||
| 78 | # Add icon to Plugin | ||
| 79 | ####### | ||
| 80 | sub plugin_icon { | ||
| 81 | my $class = shift; | ||
| 82 | my $share = $class->plugin_directory_share or return; | ||
| 83 | my $file = File::Spec->catfile( $share, 'icons', '16x16', 'cookbook.png' ); | ||
| 84 | return unless -f $file; | ||
| 85 | return unless -r $file; | ||
| 86 | return Wx::Bitmap->new( $file, Wx::wxBITMAP_TYPE_PNG ); | ||
| 87 | } | ||
| 88 | |||
| 89 | ####### | ||
| 90 | # Clean up dialog Main, Padre::Plugin, | ||
| 91 | # POD out of date as of v0.84 | ||
| 92 | ####### | ||
| 93 | sub plugin_disable { | ||
| 94 | my $self = shift; | ||
| 95 | |||
| 96 | # Close the dialog if it is hanging around | ||
| 97 | $self->clean_dialog; | ||
| 98 | |||
| 99 | # Unload all our child classes | ||
| 100 | for my $package (CHILDREN) { | ||
| 101 | require Padre::Unload; | ||
| 102 | Padre::Unload->unload($package); | ||
| 103 | } | ||
| 104 | |||
| 105 | $self->SUPER::plugin_disable(@_); | ||
| 106 | |||
| 107 | return 1; | ||
| 108 | |||
| 109 | } | ||
| 110 | |||
| 111 | ######## | ||
| 112 | # Composed Method, | ||
| 113 | # Load Recipe-01 Main Dialog, only once | ||
| 114 | ####### | ||
| 115 | sub load_dialog_recipe01_main { | ||
| 116 | my $self = shift; | ||
| 117 | |||
| 118 | # Padre main window integration | ||
| 119 | my $main = $self->main; | ||
| 120 | |||
| 121 | # Close the dialog if it is hanging around | ||
| 122 | $self->clean_dialog; | ||
| 123 | |||
| 124 | # Create the new dialog | ||
| 125 | require Padre::Plugin::Cookbook::Recipe01::Main; | ||
| 126 | $self->{dialog} = Padre::Plugin::Cookbook::Recipe01::Main->new($main); | ||
| 127 | $self->{dialog}->Show; | ||
| 128 | |||
| 129 | return; | ||
| 130 | } | ||
| 131 | |||
| 132 | ######## | ||
| 133 | # Composed Method, | ||
| 134 | # Load Recipe-02 Main Dialog, only once | ||
| 135 | ####### | ||
| 136 | sub load_dialog_recipe02_main { | ||
| 137 | my $self = shift; | ||
| 138 | |||
| 139 | # Padre main window integration | ||
| 140 | my $main = $self->main; | ||
| 141 | |||
| 142 | # Close the dialog if it is hanging around | ||
| 143 | $self->clean_dialog; | ||
| 144 | |||
| 145 | # Create the new dialog | ||
| 146 | require Padre::Plugin::Cookbook::Recipe02::Main; | ||
| 147 | $self->{dialog} = Padre::Plugin::Cookbook::Recipe02::Main->new($main); | ||
| 148 | $self->{dialog}->Show; | ||
| 149 | |||
| 150 | return; | ||
| 151 | } | ||
| 152 | |||
| 153 | ######## | ||
| 154 | # Composed Method, | ||
| 155 | # Load Recipe-03 Main Dialog, only once | ||
| 156 | ####### | ||
| 157 | sub load_dialog_recipe03_main { | ||
| 158 | my $self = shift; | ||
| 159 | |||
| 160 | # Padre main window integration | ||
| 161 | my $main = $self->main; | ||
| 162 | |||
| 163 | # Close the dialog if it is hanging around | ||
| 164 | $self->clean_dialog; | ||
| 165 | |||
| 166 | # Create the new dialog | ||
| 167 | require Padre::Plugin::Cookbook::Recipe03::Main; | ||
| 168 | $self->{dialog} = Padre::Plugin::Cookbook::Recipe03::Main->new($main); | ||
| 169 | $self->{dialog}->Show; | ||
| 170 | |||
| 171 | return; | ||
| 172 | } | ||
| 173 | |||
| 174 | ######## | ||
| 175 | # Composed Method, | ||
| 176 | # Load Recipe-04 Main Dialog, only once | ||
| 177 | ####### | ||
| 178 | sub load_dialog_recipe04_main { | ||
| 179 | my $self = shift; | ||
| 180 | |||
| 181 | # Padre main window integration | ||
| 182 | my $main = $self->main; | ||
| 183 | |||
| 184 | # Close the dialog if it is hanging around | ||
| 185 | $self->clean_dialog; | ||
| 186 | |||
| 187 | # Create the new dialog | ||
| 188 | require Padre::Plugin::Cookbook::Recipe04::Main; | ||
| 189 | $self->{dialog} = Padre::Plugin::Cookbook::Recipe04::Main->new($main); | ||
| 190 | $self->{dialog}->Show; | ||
| 191 | $self->{dialog}->set_up; | ||
| 192 | |||
| 193 | return; | ||
| 194 | } | ||
| 195 | |||
| 196 | ######## | ||
| 197 | # Composed Method clean_dialog | ||
| 198 | ######## | ||
| 199 | sub clean_dialog { | ||
| 200 | my $self = shift; | ||
| 201 | |||
| 202 | # Close the main dialog if it is hanging around | ||
| 203 | if ( $self->{dialog} ) { | ||
| 204 | $self->{dialog}->Hide; | ||
| 205 | $self->{dialog}->Destroy; | ||
| 206 | delete $self->{dialog}; | ||
| 207 | } | ||
| 208 | |||
| 209 | return 1; | ||
| 210 | } | ||
| 211 | |||
| 212 | 1; | ||
| 213 | |||
| 214 | __END__ | ||