Plugin/WebGUI.pm

filter: Statementstmt 84.6% 11 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 88.8% 16 / 18 CC 1 SCAR 0.6
CC
1
Cov
85%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Document/WebGUI/Asset.pm ↑ Summary
1 package Padre::Plugin::WebGUI;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $Padre::Plugin::WebGUI::VERSION = '1.002';
4 }
5  
6 # ABSTRACT: Developer tools for WebGUI
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use base 'Padre::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 0 ▶use Padre::Logger;
Subroutine BEGIN: called CC=1 SCAR=2.6
12 use Padre::Util ('_T');
13 use Padre::Plugin::WebGUI::Assets;
14  
15  
16 # Used to control dev niceties
17 my $DEV_MODE = 0;
18  
19  
20 sub plugin_name {
21 return _T("WebGUI");
22 }
23  
24  
25 sub padre_interfaces {
26 'Padre::Plugin' => 0.43,
27 ;
28 }
29  
30  
31 sub registered_documents {
32 'application/x-webgui-asset' => 'Padre::Document::WebGUI::Asset',
33 'application/x-webgui-template' => 'Padre::Document::WebGUI::Asset::Template',
34 'application/x-webgui-snippet' => 'Padre::Document::WebGUI::Asset::Snippet',
35 ;
36 }
37  
38  
39 sub plugin_directory_share {
40 my $self = shift;
41  
42 my $share = $self->SUPER::plugin_directory_share;
43 return $share if $share;
44  
45 # Try this one instead (for dev version)
46 my $path = Cwd::realpath( File::Spec->join( File::Basename::dirname(__FILE__), '../../../', 'share' ) );
47 return $path if -d $path;
48  
49 return;
50 }
51  
52  
53 sub plugin_enable {
54 my $self = shift;
55  
56 TRACE('Enabling Padre::Plugin::WebGUI') if DEBUG;
57  
58 # workaround Padre bug
59 my %registered_documents = $self->registered_documents;
60 while ( my ( $k, $v ) = each %registered_documents ) {
61 Padre::MimeTypes->add_highlighter_to_mime_type( $k, $v );
62 }
63  
64 # Create empty config object if it doesn't exist
65 my $config = $self->config_read;
66 if ( !$config ) {
67 $self->config_write( {} );
68 }
69  
70 return 1;
71 }
72  
73  
74 # called when the plugin is disabled/reloaded
75 sub plugin_disable {
76 my $self = shift;
77  
78 TRACE('Disabling Padre::Plugin::WebGUI') if DEBUG;
79  
80 if ( my $asset_tree = $self->{asset_tree} ) {
81 $self->main->right->hide($asset_tree);
82 delete $self->{asset_tree};
83 }
84  
85 # Unload all private classese here, so that they can be reloaded
86 require Class::Unload;
87 Class::Unload->unload('Padre::Plugin::WebGUI::Assets');
88  
89 # I think this would be bad if a doc was open when you reloaded the plugin, but handy when developing
90 if ($DEV_MODE) {
91 Class::Unload->unload('Padre::Document::WebGUI::Asset');
92 }
93 }
94  
95  
96 sub menu_plugins {
97 my $self = shift;
98 my $main = shift;
99  
100 $self->{menu} = Wx::Menu->new;
101  
102 # Asset Tree
103 $self->{asset_tree_toggle} = $self->{menu}->AppendCheckItem( -1, _T("Show Asset Tree"), );
104 Wx::Event::EVT_MENU( $main, $self->{asset_tree_toggle}, sub { $self->toggle_asset_tree } );
105  
106 # Turn on Asset Tree as soon as Plugin is enabled
107 # Disabled - we can't have this here because menu_plugins is called repeatedly
108 # if ( $self->config_read->{show_asset_tree} ) {
109 # $self->{asset_tree_toggle}->Check(1);
110 #
111 # $self->toggle_asset_tree;
112 # }
113  
114 # Online Resources
115 my $resources_submenu = Wx::Menu->new;
116 my %resources = $self->online_resources;
117 while ( my ( $name, $resource ) = each %resources ) {
118 Wx::Event::EVT_MENU( $main, $resources_submenu->Append( -1, $name ), $resource, );
119 }
120 $self->{menu}->Append( -1, _T("Online Resources"), $resources_submenu );
121  
122 # About
123 Wx::Event::EVT_MENU( $main, $self->{menu}->Append( -1, _T("About"), ), sub { $self->show_about }, );
124  
125 # Reload (handy when developing this plugin)
126 if ($DEV_MODE) {
127 $self->{menu}->AppendSeparator;
128  
129 Wx::Event::EVT_MENU(
130 $main,
131 $self->{menu}->Append( -1, _T("Reload WebGUI Plugin\tCtrl+Shift+R"), ),
132 sub { $main->ide->plugin_manager->reload_current_plugin },
133 );
134 }
135  
136 # Return our plugin with its label
137 return ( $self->plugin_name => $self->{menu} );
138 }
139  
140  
141 sub online_resources {
142 my %RESOURCES = (
143 'Bug Tracker' => sub {
144 Padre::Wx::launch_browser('http://webgui.org/bugs');
145 },
146 'Community Live Support' => sub {
147 Padre::Wx::launch_irc( 'irc.freenode.org' => 'webgui' );
148 },
149 'GitHub - WebGUI' => sub {
150 Padre::Wx::launch_browser('http://github.com/plainblack/webgui');
151 },
152 'GitHub - WGDev' => sub {
153 Padre::Wx::launch_browser('http://github.com/haarg/wgdev');
154 },
155 'Planet WebGUI' => sub {
156 Padre::Wx::launch_browser('http://patspam.com/planetwebgui');
157 },
158 'RFE Tracker' => sub {
159 Padre::Wx::launch_browser('http://webgui.org/rfe');
160 },
161 'Stats' => sub {
162 Padre::Wx::launch_browser('http://webgui.org/webgui-stats');
163 },
164 'WebGUI.org' => sub {
165 Padre::Wx::launch_browser('http://webgui.org');
166 },
167 'Wiki' => sub {
168 Padre::Wx::launch_browser('http://webgui.org/community-wiki');
169 },
170 );
171 return map { $_ => $RESOURCES{$_} } sort { $a cmp $b } keys %RESOURCES;
172 }
173  
174  
175 sub show_about {
176 my $self = shift;
177  
178 # Generate the About dialog
179 my $about = Wx::AboutDialogInfo->new;
180 $about->SetName("Padre::Plugin::WebGUI");
181 $about->SetDescription( <<"END_MESSAGE" );
182 WebGUI Plugin for Padre
183 http://patspam.com
184 END_MESSAGE
185 $about->SetVersion($Padre::Plugin::WebGUI::VERSION);
186  
187 # Show the About dialog
188 Wx::AboutBox($about);
189  
190 return;
191 }
192  
193  
194 sub ping { 1 }
195  
196  
197 sub toggle_asset_tree {
198 my $self = shift;
199  
200 return unless $self->ping;
201  
202 my $asset_tree = $self->asset_tree;
203 if ( $self->{asset_tree_toggle}->IsChecked ) {
204 $self->main->right->show($asset_tree);
205 $asset_tree->update_gui;
206 $self->config_write( { %{ $self->config_read }, show_asset_tree => 1 } );
207 }
208 else {
209 $self->main->right->hide($asset_tree);
210 $self->config_write( { %{ $self->config_read }, show_asset_tree => 0 } );
211 }
212  
213 $self->main->aui->Update;
214 $self->ide->save_config;
215  
216 return;
217 }
218  
219  
220 sub asset_tree {
221 my $self = shift;
222  
223 if ( !$self->{asset_tree} ) {
224 $self->{asset_tree} = Padre::Plugin::WebGUI::Assets->new($self);
225 }
226 return $self->{asset_tree};
227 }
228  
229  
230 1;
231  
232 __END__
« Document/WebGUI/Asset.pm ↑ Summary