line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Padre::Plugin::Nopaste; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
91583
|
use v5.10; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
96
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
97
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1858
|
use Try::Tiny; |
|
2
|
|
|
|
|
3860
|
|
|
2
|
|
|
|
|
139
|
|
10
|
2
|
|
|
2
|
|
1241
|
use Padre::Unload (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Padre::Logger qw( TRACE DEBUG ); |
12
|
|
|
|
|
|
|
use parent qw{ |
13
|
|
|
|
|
|
|
Padre::Plugin |
14
|
|
|
|
|
|
|
Padre::Role::Task |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
use Padre::Plugin::Nopaste::Services; |
17
|
|
|
|
|
|
|
use Carp; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use English qw( -no_match_vars ); |
20
|
|
|
|
|
|
|
local $OUTPUT_AUTOFLUSH = 1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Child modules we need to unload when disabled |
23
|
|
|
|
|
|
|
use constant CHILDREN => qw{ |
24
|
|
|
|
|
|
|
Padre::Plugin::Nopaste |
25
|
|
|
|
|
|
|
Padre::Plugin::Nopaste::Task |
26
|
|
|
|
|
|
|
Padre::Plugin::Nopaste::Services |
27
|
|
|
|
|
|
|
Padre::Plugin::Nopaste::Preferences |
28
|
|
|
|
|
|
|
Padre::Plugin::Nopaste::FBP::Preferences |
29
|
|
|
|
|
|
|
App::Nopaste |
30
|
|
|
|
|
|
|
App::Nopaste::Service |
31
|
|
|
|
|
|
|
App::Nopaste::Service::Shadowcat |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
####### |
36
|
|
|
|
|
|
|
# Define Plugin Name Spell Checker |
37
|
|
|
|
|
|
|
####### |
38
|
|
|
|
|
|
|
sub plugin_name { |
39
|
|
|
|
|
|
|
return Wx::gettext('Nopaste'); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
####### |
43
|
|
|
|
|
|
|
# Define Padre Interfaces required |
44
|
|
|
|
|
|
|
####### |
45
|
|
|
|
|
|
|
sub padre_interfaces { |
46
|
|
|
|
|
|
|
return ( |
47
|
|
|
|
|
|
|
'Padre::Plugin' => '0.96', |
48
|
|
|
|
|
|
|
'Padre::Task' => '0.96', |
49
|
|
|
|
|
|
|
'Padre::Unload' => '0.96', |
50
|
|
|
|
|
|
|
'Padre::Logger' => '0.96', |
51
|
|
|
|
|
|
|
'Padre::Wx' => '0.96', |
52
|
|
|
|
|
|
|
'Padre::Wx::Role::Main' => '0.96', |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
######### |
57
|
|
|
|
|
|
|
# We need plugin_enable |
58
|
|
|
|
|
|
|
# as we have an external dependency |
59
|
|
|
|
|
|
|
######### |
60
|
|
|
|
|
|
|
sub plugin_enable { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
my $main = $self->main; |
63
|
|
|
|
|
|
|
my $config = $main->config; |
64
|
|
|
|
|
|
|
my $nick = 0; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Tests for externals used by Preference's |
67
|
|
|
|
|
|
|
if ( $config->identity_nickname ) { |
68
|
|
|
|
|
|
|
$nick = 1; |
69
|
|
|
|
|
|
|
} else { |
70
|
|
|
|
|
|
|
croak "\nYou need to set 'identity_nickname' \n Look in Tools -> Preferences -> Advance\n\n"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#Set/ReSet Config data |
74
|
|
|
|
|
|
|
if ($nick) { |
75
|
|
|
|
|
|
|
$self->_config; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return $nick; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
####### |
82
|
|
|
|
|
|
|
# Composed Method _config |
83
|
|
|
|
|
|
|
# called on enable in plugin manager, bit like run/setup for a Plugin |
84
|
|
|
|
|
|
|
####### |
85
|
|
|
|
|
|
|
sub _config { |
86
|
|
|
|
|
|
|
my $self = shift; |
87
|
|
|
|
|
|
|
my $config_db = $self->config_read; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
try { |
90
|
|
|
|
|
|
|
if ( defined $config_db->{Services} ) { |
91
|
|
|
|
|
|
|
my $tmp_services = $config_db->{Services}; |
92
|
|
|
|
|
|
|
my $tmp_channel = $config_db->{Channel}; |
93
|
|
|
|
|
|
|
$self->config_write( {} ); |
94
|
|
|
|
|
|
|
$config_db = $self->config_read; |
95
|
|
|
|
|
|
|
$config_db->{Services} = $tmp_services; |
96
|
|
|
|
|
|
|
$config_db->{Channel} = $tmp_channel; |
97
|
|
|
|
|
|
|
$self->config_write($config_db); |
98
|
|
|
|
|
|
|
return; |
99
|
|
|
|
|
|
|
} else { |
100
|
|
|
|
|
|
|
$self->config_write( {} ); |
101
|
|
|
|
|
|
|
$config_db->{Services} = 'Shadowcat'; |
102
|
|
|
|
|
|
|
$config_db->{Channel} = '#padre'; |
103
|
|
|
|
|
|
|
$self->config_write($config_db); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
catch { |
107
|
|
|
|
|
|
|
$self->config_write( {} ); |
108
|
|
|
|
|
|
|
$config_db->{Services} = 'Shadowcat'; |
109
|
|
|
|
|
|
|
$config_db->{Channel} = '#padre'; |
110
|
|
|
|
|
|
|
$self->config_write($config_db); |
111
|
|
|
|
|
|
|
return; |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
return; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
####### |
118
|
|
|
|
|
|
|
# plugin menu |
119
|
|
|
|
|
|
|
####### |
120
|
|
|
|
|
|
|
sub menu_plugins { |
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
my $main = $self->main; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Create a manual menu item |
125
|
|
|
|
|
|
|
my $menu_item = Wx::MenuItem->new( undef, -1, $self->plugin_name . "\tCtrl+Shift+V", ); |
126
|
|
|
|
|
|
|
Wx::Event::EVT_MENU( |
127
|
|
|
|
|
|
|
$main, |
128
|
|
|
|
|
|
|
$menu_item, |
129
|
|
|
|
|
|
|
sub { |
130
|
|
|
|
|
|
|
$self->paste_it; |
131
|
|
|
|
|
|
|
}, |
132
|
|
|
|
|
|
|
); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
return $menu_item; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
######## |
138
|
|
|
|
|
|
|
# plugin_disable |
139
|
|
|
|
|
|
|
######## |
140
|
|
|
|
|
|
|
sub plugin_disable { |
141
|
|
|
|
|
|
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Close the dialog if it is hanging around |
144
|
|
|
|
|
|
|
$self->clean_dialog; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# Unload all our child classes |
147
|
|
|
|
|
|
|
for my $package (CHILDREN) { |
148
|
|
|
|
|
|
|
require Padre::Unload; |
149
|
|
|
|
|
|
|
Padre::Unload->unload($package); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$self->SUPER::plugin_disable(@_); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
return 1; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
######## |
158
|
|
|
|
|
|
|
# Composed Method clean_dialog |
159
|
|
|
|
|
|
|
######## |
160
|
|
|
|
|
|
|
sub clean_dialog { |
161
|
|
|
|
|
|
|
my $self = shift; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Close the main dialog if it is hanging around |
164
|
|
|
|
|
|
|
if ( $self->{dialog} ) { |
165
|
|
|
|
|
|
|
$self->{dialog}->Hide; |
166
|
|
|
|
|
|
|
$self->{dialog}->Destroy; |
167
|
|
|
|
|
|
|
delete $self->{dialog}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
return 1; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
####### |
175
|
|
|
|
|
|
|
# plugin_preferences |
176
|
|
|
|
|
|
|
####### |
177
|
|
|
|
|
|
|
sub plugin_preferences { |
178
|
|
|
|
|
|
|
my $self = shift; |
179
|
|
|
|
|
|
|
my $main = $self->main; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# Clean up any previous existing dialog |
182
|
|
|
|
|
|
|
$self->clean_dialog; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
try { |
185
|
|
|
|
|
|
|
require Padre::Plugin::Nopaste::Preferences; |
186
|
|
|
|
|
|
|
$self->{dialog} = Padre::Plugin::Nopaste::Preferences->new($main); |
187
|
|
|
|
|
|
|
$self->{dialog}->ShowModal; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
catch { |
190
|
|
|
|
|
|
|
$self->main->error( sprintf Wx::gettext('Error: %s'), $_ ); |
191
|
|
|
|
|
|
|
}; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
return; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
####### |
198
|
|
|
|
|
|
|
# paste_it |
199
|
|
|
|
|
|
|
####### |
200
|
|
|
|
|
|
|
sub paste_it { |
201
|
|
|
|
|
|
|
my $self = shift; |
202
|
|
|
|
|
|
|
my $main = $self->main; |
203
|
|
|
|
|
|
|
my $config = $main->config; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
my $output = $main->output; |
206
|
|
|
|
|
|
|
my $current = $self->current; |
207
|
|
|
|
|
|
|
my $document = $current->document; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
my $full_text = $document->text_get; |
210
|
|
|
|
|
|
|
my $selected_text = $current->text; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
my $config_db = $self->config_read; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
TRACE('paste_it: start task to nopaste') if DEBUG; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
my $text = $selected_text || $full_text; |
217
|
|
|
|
|
|
|
return unless defined $text; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
require Padre::Plugin::Nopaste::Task; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# # Fire the task |
222
|
|
|
|
|
|
|
$self->task_request( |
223
|
|
|
|
|
|
|
task => 'Padre::Plugin::Nopaste::Task', |
224
|
|
|
|
|
|
|
text => $text, |
225
|
|
|
|
|
|
|
nick => $config->identity_nickname, |
226
|
|
|
|
|
|
|
services => $config_db->{Services}, |
227
|
|
|
|
|
|
|
channel => $config_db->{Channel}, |
228
|
|
|
|
|
|
|
on_finish => 'on_finish', |
229
|
|
|
|
|
|
|
); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# say 'end paste_it'; |
232
|
|
|
|
|
|
|
return; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
####### |
236
|
|
|
|
|
|
|
# on completion of task do this |
237
|
|
|
|
|
|
|
####### |
238
|
|
|
|
|
|
|
sub on_finish { |
239
|
|
|
|
|
|
|
my $self = shift; |
240
|
|
|
|
|
|
|
my $task = shift; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
TRACE('on_finish: nopaste_response') if DEBUG; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# Generate the dump string and set into the output window |
246
|
|
|
|
|
|
|
my $main = $self->main; |
247
|
|
|
|
|
|
|
$main->show_output(1); |
248
|
|
|
|
|
|
|
my $output = $main->output; |
249
|
|
|
|
|
|
|
$output->clear; |
250
|
|
|
|
|
|
|
if ( $task->{error} ) { |
251
|
|
|
|
|
|
|
$output->AppendText('Something went wrong, here is the response we got:'); |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
$output->AppendText( $task->{message} ); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
return; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
####### |
261
|
|
|
|
|
|
|
# Add icon to Plugin |
262
|
|
|
|
|
|
|
####### |
263
|
|
|
|
|
|
|
sub plugin_icon { |
264
|
|
|
|
|
|
|
my $class = shift; |
265
|
|
|
|
|
|
|
my $share = $class->plugin_directory_share or return; |
266
|
|
|
|
|
|
|
my $file = File::Spec->catfile( $share, 'icons', '16x16', 'nopaste.png' ); |
267
|
|
|
|
|
|
|
return unless -f $file; |
268
|
|
|
|
|
|
|
return unless -r $file; |
269
|
|
|
|
|
|
|
return Wx::Bitmap->new( $file, Wx::wxBITMAP_TYPE_PNG ); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
####### |
273
|
|
|
|
|
|
|
# Add Preferences to Context Menu |
274
|
|
|
|
|
|
|
####### |
275
|
|
|
|
|
|
|
sub event_on_context_menu { |
276
|
|
|
|
|
|
|
my ( $self, $document, $editor, $menu, $event ) = @_; |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
#Test for valid file type |
279
|
|
|
|
|
|
|
return if not $document->filename; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
$menu->AppendSeparator; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
my $item = $menu->Append( -1, Wx::gettext('Nopaste Preferences...') ); |
284
|
|
|
|
|
|
|
Wx::Event::EVT_MENU( |
285
|
|
|
|
|
|
|
$self->main, |
286
|
|
|
|
|
|
|
$item, |
287
|
|
|
|
|
|
|
sub { $self->plugin_preferences }, |
288
|
|
|
|
|
|
|
); |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
return; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
1; |
294
|
|
|
|
|
|
|
__END__ |