line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package tkShortcuts; |
5
|
1
|
|
|
1
|
|
19841
|
use Tk; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#require Tk; |
7
|
|
|
|
|
|
|
#require Tk; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw (Exporter); |
13
|
|
|
|
|
|
|
our @EXPORT = qw (superdirchoose superopenfile returntext saveit htmlcolret $VERSION $superdirwin $win_openfile $w $rett_win $as $html_win) ; |
14
|
|
|
|
|
|
|
our @EXPORT_OK = (@EXPORT); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "1.00a"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$as = 0; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub superdirchoose |
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
$superdirwin = new MainWindow(-title=>'Choose a Directory'); |
23
|
|
|
|
|
|
|
$superdirwin -> maxsize (300, 380); |
24
|
|
|
|
|
|
|
my $d = $superdirwin -> DirTree () -> pack (-fill=>'x'); |
25
|
|
|
|
|
|
|
my $l_makedir = $superdirwin -> Label (-text=>"CREATE NEW DIRECTORY\nType in a name for your directory.\nSelect a directory for it to be created under.") -> pack (-fill=>'x'); |
26
|
|
|
|
|
|
|
my $ent_dir = $superdirwin -> Entry () -> pack (-fill=>'x'); |
27
|
|
|
|
|
|
|
my $butt_newdir = $superdirwin -> Button (-text=>'New Directory', -command=>sub { superdirnewdir ($ent_dir-> get(), $d->info ('selection') ); } ) -> pack (-fill=>'x') ; |
28
|
|
|
|
|
|
|
my $ret; |
29
|
|
|
|
|
|
|
my $lplacer = $superdirwin -> Label () -> pack (-fill=>'x' ); |
30
|
|
|
|
|
|
|
my $retb = $superdirwin -> Button (-text=>'Chooose Selected Directory', -command=>sub { $ret = superdirdone ($d); } ) -> pack (-fill=>'x' ); |
31
|
|
|
|
|
|
|
my $butt_cancel = $superdirwin -> Button (-text=>"Cancel", -command=>sub { $superdirwin-> destroy (); $superdirwin = ''; }) -> pack (-fill=>'x') ; |
32
|
|
|
|
|
|
|
MainLoop(); |
33
|
|
|
|
|
|
|
return $ret; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub superopenfile |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
$openw = new MainWindow(-title=>"Open a File"); |
39
|
|
|
|
|
|
|
$open_dir = $openw -> DirTree (-width=>60) -> pack (-fill=>'x' ); |
40
|
|
|
|
|
|
|
my $open_changedir = $openw -> Button (-text=>"Change Directory", -command=>\&superopencdir) -> pack (-fill=>'x'); |
41
|
|
|
|
|
|
|
$open_botl = $openw -> Label (-text=>"Browse for a file"); |
42
|
|
|
|
|
|
|
$open_list = $openw -> Listbox (); |
43
|
|
|
|
|
|
|
my @j; |
44
|
|
|
|
|
|
|
$open_sel = $openw -> Button (-text=>"Select File", -command=>sub { @j = superopenfinal (); $openw -> destroy(); } ); |
45
|
|
|
|
|
|
|
MainLoop(); |
46
|
|
|
|
|
|
|
return @j ; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub saveit |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
@contents_file = @_; |
53
|
|
|
|
|
|
|
$file = $contents_file[0]; |
54
|
|
|
|
|
|
|
@contents = @contents_file[1 .. @contents_file]; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
if ($as) |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
$str = "Save '$file' as..."; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
$str = "Save '$file'" ; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$w = new MainWindow(-title=>"Save '$file'"); |
67
|
|
|
|
|
|
|
$dirlist = $w -> DirTree (-width=>55) -> pack(-fill=>'x') ; |
68
|
|
|
|
|
|
|
$dirlabel = $w -> Label (-text=>"Select a directory for the new directory to be created under and enter name for the new directory:") -> pack (-fill=>'x' ); |
69
|
|
|
|
|
|
|
$dirent = $w -> Entry () -> pack (-fill=>'x') ; |
70
|
|
|
|
|
|
|
$newdir = $w -> Button (-command=>sub { newdir(); } , -activebackground=>'blue', -text=>'NEW DIR')-> pack (-fill=>'x'); |
71
|
|
|
|
|
|
|
$botlabel = $w -> Label (-text=>"Select a directory where you want to save the file and type the file name:") -> pack (-fill=>'x'); |
72
|
|
|
|
|
|
|
$filename = $w -> Entry () -> pack (-fill=>'x'); |
73
|
|
|
|
|
|
|
$filename -> insert (0, $file) if ! $as ; |
74
|
|
|
|
|
|
|
$finalsavebutt = $w -> Button (-command=>\&savefinal, -text=>'SAVE THE FILE', -activebackground=>'blue') -> pack (-fill=>'both'); |
75
|
|
|
|
|
|
|
if ($file =~ /^$|^\s*$/) |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
my $d = $w -> Dialog (-text=>"Your file name was blank. Try again" ,-title=>"Error"); |
78
|
|
|
|
|
|
|
$d->Show(); |
79
|
|
|
|
|
|
|
$w -> destroy(); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
MainLoop(); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub returntext |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
my $wintit = shift; |
88
|
|
|
|
|
|
|
my $butttext = shift; |
89
|
|
|
|
|
|
|
$rett_win = new MainWindow(); |
90
|
|
|
|
|
|
|
my $d = $rett_win -> Dialog (); |
91
|
|
|
|
|
|
|
my $d2 = $rett_win -> Dialog(); |
92
|
|
|
|
|
|
|
$d -> configure (-text=>'Error: You did not supply the argument for the window title', -title=>'Error'); |
93
|
|
|
|
|
|
|
$d2 -> configure (-text=>'Error: You did not supply the argument for the button text', -title=>'Error'); |
94
|
|
|
|
|
|
|
if (! $wintit) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
$d -> Show() ; |
97
|
|
|
|
|
|
|
$rett_win -> destroy(); |
98
|
|
|
|
|
|
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
if (! $butttext) |
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
$d2 -> Show (); |
103
|
|
|
|
|
|
|
$rett_win -> destroy(); |
104
|
|
|
|
|
|
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
$rett_win -> configure (-title=>"$wintit"); |
107
|
|
|
|
|
|
|
$ret_txt = $rett_win -> Text () -> pack (-fill=>'x'); |
108
|
|
|
|
|
|
|
my @z; |
109
|
|
|
|
|
|
|
my $ret_butt = $rett_win -> Button (-text=>"$butttext", -command=>sub {@z = rettxt_getcont(); $rett_win ->destroy(); $rett_win = ''; } )->pack(); |
110
|
|
|
|
|
|
|
MainLoop(); |
111
|
|
|
|
|
|
|
return (@z); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub htmlcolret |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
my $ret; |
117
|
|
|
|
|
|
|
$html_win = new MainWindow(-title=>"Html Color Chooser"); |
118
|
|
|
|
|
|
|
my $t = $html_win -> Table (-rows=>4, -columns=>4, -scrollbars=>0) -> pack (-fill=>'x'); |
119
|
|
|
|
|
|
|
my $one = $t -> Button (-background=>"black", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#000000'); }); |
120
|
|
|
|
|
|
|
my $two = $t -> Button (-background=>"gray75", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#C0C0C0 '); }); |
121
|
|
|
|
|
|
|
my $three = $t -> Button (-background=>"gray50", width=>4, -command=>sub { $ret = htmlreturnfinal ('#808080'); }); |
122
|
|
|
|
|
|
|
my $four = $t -> Button (-background=>"white", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#FFFFFF'); }); |
123
|
|
|
|
|
|
|
my $five = $t -> Button (-background=>"darkred", -width=>4 , -command=>sub { $ret = htmlreturnfinal ('#800000'); }); |
124
|
|
|
|
|
|
|
my $six = $t -> Button (-background=>"red", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#FF0000'); }); |
125
|
|
|
|
|
|
|
my $seven = $t -> Button (-background=>"DarkMagenta", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#800080'); } ); |
126
|
|
|
|
|
|
|
my $eight = $t -> Button (-background=>"green4", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#008000');}); |
127
|
|
|
|
|
|
|
my $nine = $t -> Button (-background=>"green", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#00FF00');}); |
128
|
|
|
|
|
|
|
my $ten = $t -> Button (-background=>"Gold4", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#808000');}); |
129
|
|
|
|
|
|
|
my $eleven = $t -> Button (-background=>"yellow", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#FFFF00');}); |
130
|
|
|
|
|
|
|
my $twelve = $t -> Button (-background=>"navy", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#000080');}); |
131
|
|
|
|
|
|
|
my $thirteen = $t -> Button (-background=>"turquoise4", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#008080');}); |
132
|
|
|
|
|
|
|
my $fourteen = $t -> Button (-background=>"cyan", -width=>4, -command=>sub { $ret = htmlreturnfinal ('#00FFFF');}); |
133
|
|
|
|
|
|
|
$t->put (0, 1, $one) ; |
134
|
|
|
|
|
|
|
$t->put (0, 2, $two) ; |
135
|
|
|
|
|
|
|
$t->put (0, 3, $three) ; |
136
|
|
|
|
|
|
|
$t->put (0, 4, $four) ; |
137
|
|
|
|
|
|
|
$t->put (1, 1, $five) ; |
138
|
|
|
|
|
|
|
$t->put (1, 2, $six); |
139
|
|
|
|
|
|
|
$t->put (1, 3, $seven) ; |
140
|
|
|
|
|
|
|
$t->put (1, 4, $eight) ; |
141
|
|
|
|
|
|
|
$t->put (2, 1, $nine) ; |
142
|
|
|
|
|
|
|
$t->put (2, 2, $ten) ; |
143
|
|
|
|
|
|
|
$t->put (2, 3, $eleven) ; |
144
|
|
|
|
|
|
|
$t->put (2, 4, $twelve) ; |
145
|
|
|
|
|
|
|
$t->put (3, 2, $thirteen) ; |
146
|
|
|
|
|
|
|
$t->put (3, 3, $fourteen) ; |
147
|
|
|
|
|
|
|
MainLoop(); |
148
|
|
|
|
|
|
|
return $ret; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
####################################################### |
153
|
|
|
|
|
|
|
# |
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
### subs not exported |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
############################## |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
####################################################### |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub htmlreturnfinal |
163
|
|
|
|
|
|
|
{ |
164
|
|
|
|
|
|
|
$html_win -> destroy(); |
165
|
|
|
|
|
|
|
return shift; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub rettxt_getcont |
169
|
|
|
|
|
|
|
{ |
170
|
|
|
|
|
|
|
my $t = join '', @tmp; |
171
|
|
|
|
|
|
|
return ( $ret_txt -> Contents ); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub savefinal |
175
|
|
|
|
|
|
|
{ |
176
|
|
|
|
|
|
|
$die1 = $w -> Dialog (-text=>'An error occured while saving. Remember to select only one directory and to include a file name.' ,-title=>"Error"); |
177
|
|
|
|
|
|
|
$die2 = $w -> Dialog (-text=>'File already exists. Overwrite it?', -buttons=>['Yes', 'No'], -title=>"Overwrite file?"); |
178
|
|
|
|
|
|
|
if (! $dirlist -> info ('selection') or $dirlist-> info ('selection') > 1 or $filename-> get() =~ /^$|^\s*$/) |
179
|
|
|
|
|
|
|
{ |
180
|
|
|
|
|
|
|
$die1 -> Show() ; |
181
|
|
|
|
|
|
|
return; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
if (-e join ('', $dirlist->info('selection')) . '/' . $filename-> get() ) |
184
|
|
|
|
|
|
|
{ |
185
|
|
|
|
|
|
|
$tmp=$die2->Show(); |
186
|
|
|
|
|
|
|
if ($tmp eq 'No') |
187
|
|
|
|
|
|
|
{ |
188
|
|
|
|
|
|
|
return; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
$finfile = join ('', $dirlist->info('selection')) . '/' . $filename-> get(); |
192
|
|
|
|
|
|
|
open (A,">$finfile"); |
193
|
|
|
|
|
|
|
print A @contents; |
194
|
|
|
|
|
|
|
close (A); |
195
|
|
|
|
|
|
|
$w -> $destroy; |
196
|
|
|
|
|
|
|
$w = ''; |
197
|
|
|
|
|
|
|
return; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
sub newdir |
201
|
|
|
|
|
|
|
{ |
202
|
|
|
|
|
|
|
$g = $w -> Dialog (-text=>"No directory selected or directory name empty or directory already exists.", -title=>'Error'); |
203
|
|
|
|
|
|
|
$a = $w -> Dialog (-text=>"Directory created successfully.", -title=>'Success'); |
204
|
|
|
|
|
|
|
if ( ! $dirlist -> info ('selection') or $dirlist -> info ('selection') > 1 or $dirent -> get() =~ /^$|^\s*$/) |
205
|
|
|
|
|
|
|
{ |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
$g->Show(); |
208
|
|
|
|
|
|
|
return; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
print (join ('', $dirlist -> info ('selection')) . $dirent -> get()); |
211
|
|
|
|
|
|
|
$a -> Show and return 1 if mkdir (join ('', $dirlist -> info ('selection')) . '/' .$dirent -> get()); |
212
|
|
|
|
|
|
|
$g->Show(); |
213
|
|
|
|
|
|
|
return 0; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub superopenfinal |
217
|
|
|
|
|
|
|
{ |
218
|
|
|
|
|
|
|
my ($files); |
219
|
|
|
|
|
|
|
my $d = $openw -> Dialog (-title=>'Error', -text=>'Error: You selected an invalid file or did not select a file.' ); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
$files = $open_list -> get ($open_list -> curselection); |
222
|
|
|
|
|
|
|
$_ = $files; |
223
|
|
|
|
|
|
|
if (/^\.$/ or /^\.\.$/ or ! $files) |
224
|
|
|
|
|
|
|
{ |
225
|
|
|
|
|
|
|
$d-> Show(); |
226
|
|
|
|
|
|
|
return; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
my $d2 = join '', $open_dir-> info ('selection'); |
229
|
|
|
|
|
|
|
chomp ($d2, $files); |
230
|
|
|
|
|
|
|
open (F, $d2 . '/' . $files); |
231
|
|
|
|
|
|
|
my @files2 = ; |
232
|
|
|
|
|
|
|
my $files2 = join '', @files2; |
233
|
|
|
|
|
|
|
close (F); |
234
|
|
|
|
|
|
|
return ($files, $files2 ); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
sub superopencdir |
237
|
|
|
|
|
|
|
{ |
238
|
|
|
|
|
|
|
$open_list -> delete (0 , 'end'); |
239
|
|
|
|
|
|
|
my $d = $openw -> Dialog (-title=>'Error', -text=>'Error: you selected more than one diretory.'); |
240
|
|
|
|
|
|
|
my @a; |
241
|
|
|
|
|
|
|
@a = $open_dir -> info('selection' ); |
242
|
|
|
|
|
|
|
if (@a) |
243
|
|
|
|
|
|
|
{ |
244
|
|
|
|
|
|
|
$open_botl -> pack (-fill=>'x' ); |
245
|
|
|
|
|
|
|
$open_list -> pack (-fill=>'x' ); |
246
|
|
|
|
|
|
|
$open_sel -> pack (-fill=>'x'); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
print scalar (@a); |
249
|
|
|
|
|
|
|
if (@a > 1) |
250
|
|
|
|
|
|
|
{ |
251
|
|
|
|
|
|
|
$d->Show(); |
252
|
|
|
|
|
|
|
return; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
opendir (A, $a[0]); |
255
|
|
|
|
|
|
|
my @dir = readdir ( A ); |
256
|
|
|
|
|
|
|
closedir ( A ) ; |
257
|
|
|
|
|
|
|
$open_list -> insert ('end', @dir); |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub superdirdone |
262
|
|
|
|
|
|
|
{ |
263
|
|
|
|
|
|
|
my $v = shift; |
264
|
|
|
|
|
|
|
my $v2 = $v-> info ('selection'); |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
if (! $v2) |
267
|
|
|
|
|
|
|
{ |
268
|
|
|
|
|
|
|
my $errdialog = $superdirwin -> Dialog (-title=>'Error', -text=>'Error: you did not select a directory'); |
269
|
|
|
|
|
|
|
$errdialog -> Show(); |
270
|
|
|
|
|
|
|
return; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
$superdirwin -> destroy(); |
273
|
|
|
|
|
|
|
return $v2; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub superdirnewdir |
277
|
|
|
|
|
|
|
{ |
278
|
|
|
|
|
|
|
my $cont = shift; |
279
|
|
|
|
|
|
|
my $dir = shift; |
280
|
|
|
|
|
|
|
my $errordialog=$superdirwin-> Dialog (-text=>"An error occured.\n\nPossible cause 1: you didn't select a directory.\nPossible cause 2: you didn't type in a directory name or it was all in spaces.\nPossible cause 3: the directory you are trying to create already exists.\nPossible cause 4: the directory name was invalid.", -title=>"Error"); |
281
|
|
|
|
|
|
|
my $sucessdialog = $superdirwin->Dialog (-text=>"Directory created sucessfully.", -title=>'success'); |
282
|
|
|
|
|
|
|
if (-e "$dir/$cont" or $dir =~ /^$/ or $cont =~ /^$|^\s*$/) |
283
|
|
|
|
|
|
|
{ |
284
|
|
|
|
|
|
|
$errordialog -> Show(); |
285
|
|
|
|
|
|
|
return 0; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
if (mkdir "$dir/$cont") |
288
|
|
|
|
|
|
|
{ |
289
|
|
|
|
|
|
|
$sucessdialog -> Show (); |
290
|
|
|
|
|
|
|
return 1; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
else |
293
|
|
|
|
|
|
|
{ |
294
|
|
|
|
|
|
|
$errordialog -> Show(); |
295
|
|
|
|
|
|
|
return |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
1; |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
__END__ |