line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl -w |
2
|
|
|
|
|
|
|
# COPYRIGHT |
3
|
|
|
|
|
|
|
# Author: Oded S. Resnik |
4
|
|
|
|
|
|
|
# Copyright (c) 2003-2010 Raz Information Systems Ltd. |
5
|
|
|
|
|
|
|
# http://www.raz.co.il |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
8
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
####################################################################### |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1021
|
use Tk; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Tk::Dialog; |
14
|
|
|
|
|
|
|
require Tk::Text::Viewer; |
15
|
|
|
|
|
|
|
use vars qw($VERSION); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$VERSION='1.002'; |
18
|
|
|
|
|
|
|
my $width = $ARGV[0] ? 132 : 80; |
19
|
|
|
|
|
|
|
my $height = 25; |
20
|
|
|
|
|
|
|
my $font = "fixed"; |
21
|
|
|
|
|
|
|
my $fontSize = "12"; |
22
|
|
|
|
|
|
|
######################################################################## |
23
|
|
|
|
|
|
|
my $mw = MainWindow->new; |
24
|
|
|
|
|
|
|
my $t1 = $mw->Scrolled('Viewer', -wrap => 'none', -width => $width, |
25
|
|
|
|
|
|
|
-height=> $height, -cursor=>'tcross', |
26
|
|
|
|
|
|
|
-font=> $font . " " . $fontSize); |
27
|
|
|
|
|
|
|
$t1->tagConfigure('sel', -foreground => 'red'); |
28
|
|
|
|
|
|
|
$t1->pack(-side => 'right', -fill => 'both', -expand => 'yes'); |
29
|
|
|
|
|
|
|
$t1->LabelConfig({-text=>"Search :", -foreground=>'blue'}); |
30
|
|
|
|
|
|
|
$t1->EntryConfig("-foreground=>'blue'"); |
31
|
|
|
|
|
|
|
# ------ Menu |
32
|
|
|
|
|
|
|
my $mMenu = $t1->Menu( -type => 'menubar' ); |
33
|
|
|
|
|
|
|
$mw->configure( -menu => $mMenu ); |
34
|
|
|
|
|
|
|
my %MenuItems = ( |
35
|
|
|
|
|
|
|
'9Help' => |
36
|
|
|
|
|
|
|
[ |
37
|
|
|
|
|
|
|
[ 'command' => 'Help', -accelerator => 'F1', |
38
|
|
|
|
|
|
|
-underline => 0, |
39
|
|
|
|
|
|
|
-command => sub { ShowHelp() ; } ], |
40
|
|
|
|
|
|
|
"-", |
41
|
|
|
|
|
|
|
[ 'command' => 'About...', -command => sub { DoAbout() ; } ], |
42
|
|
|
|
|
|
|
], |
43
|
|
|
|
|
|
|
'1File' => |
44
|
|
|
|
|
|
|
[ |
45
|
|
|
|
|
|
|
[ 'command' => 'Quit...', -accelerator => 'Control-F4', |
46
|
|
|
|
|
|
|
-underline => 0, |
47
|
|
|
|
|
|
|
-command => [destroy => $mw] ] |
48
|
|
|
|
|
|
|
], |
49
|
|
|
|
|
|
|
'2Edit' => |
50
|
|
|
|
|
|
|
[ |
51
|
|
|
|
|
|
|
[ 'command' => 'Copy', -accelerator => 'Control-c', |
52
|
|
|
|
|
|
|
-underline => 0, |
53
|
|
|
|
|
|
|
-command => sub { $t1->clipboardCopy;}, |
54
|
|
|
|
|
|
|
-state => 'normal'], |
55
|
|
|
|
|
|
|
"-", |
56
|
|
|
|
|
|
|
[ 'command' => 'Select All', -accelerator => 'Alt-a', |
57
|
|
|
|
|
|
|
-underline => 0, |
58
|
|
|
|
|
|
|
-command => sub { $t1->selectAll}], |
59
|
|
|
|
|
|
|
[ 'command' => 'Unselect', -accelerator => 'Alt-u', |
60
|
|
|
|
|
|
|
-underline => 0, |
61
|
|
|
|
|
|
|
-command => sub { $t1->unselectAll;}] |
62
|
|
|
|
|
|
|
], |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
'3Search' => |
66
|
|
|
|
|
|
|
[ |
67
|
|
|
|
|
|
|
[ 'command' => 'Find Text...', |
68
|
|
|
|
|
|
|
-accelerator => 'Control-f', |
69
|
|
|
|
|
|
|
-underline => 0, |
70
|
|
|
|
|
|
|
-command => sub { $t1->FindSimplePopUp() ; } ], |
71
|
|
|
|
|
|
|
"-", |
72
|
|
|
|
|
|
|
[ 'command' => 'Find Next', |
73
|
|
|
|
|
|
|
-accelerator => 'F4', |
74
|
|
|
|
|
|
|
-command => sub {$t1->FindSelectionNext() }], |
75
|
|
|
|
|
|
|
[ 'command' => 'Find Previous', |
76
|
|
|
|
|
|
|
-accelerator => 'F3', |
77
|
|
|
|
|
|
|
-command => sub {$t1->FindSelectionPrevious() }], |
78
|
|
|
|
|
|
|
[ 'command' => 'Find All', |
79
|
|
|
|
|
|
|
-accelerator => 'F5', |
80
|
|
|
|
|
|
|
-command => sub {$t1->FindAll('-exact','-nocase') }], |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
]); |
84
|
|
|
|
|
|
|
foreach (sort keys %MenuItems) { |
85
|
|
|
|
|
|
|
my ($binbKey, $bindCmd) = GetCmd($MenuItems{$_}); |
86
|
|
|
|
|
|
|
/^\d{1}(.*)/; |
87
|
|
|
|
|
|
|
$mMenu->Menubutton( -text =>$1, |
88
|
|
|
|
|
|
|
-underline => 0, |
89
|
|
|
|
|
|
|
-menuitems => $MenuItems{$_} |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
};# MenuItems |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#---- Check command line |
94
|
|
|
|
|
|
|
my $me = $0; |
95
|
|
|
|
|
|
|
$me =~ s|^.*/||; |
96
|
|
|
|
|
|
|
$me =~ s/\..*$//; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
if ($ARGV[0]) { |
99
|
|
|
|
|
|
|
return 1 if $ARGV[0] eq '-Test.pm Syntax test'; |
100
|
|
|
|
|
|
|
die "$me: Can't read $ARGV[0] \n" unless -r $ARGV[0]; |
101
|
|
|
|
|
|
|
$t1->Load($ARGV[0]); |
102
|
|
|
|
|
|
|
$t1->configure(-background=>'white'); |
103
|
|
|
|
|
|
|
$t1->focus(); |
104
|
|
|
|
|
|
|
$mw->title("$me: $ARGV[0]"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
|
|
|
|
|
|
my $lb = $mw->Scrolled('Listbox', -cursor=>'hand1'); |
108
|
|
|
|
|
|
|
$lb->packAdjust(-side => 'left', -fill => 'both', -delay => 1); |
109
|
|
|
|
|
|
|
$lb->bind('', |
110
|
|
|
|
|
|
|
sub { $t1->Load($lb->getSelected); |
111
|
|
|
|
|
|
|
$t1->configure(-background=>'white'); |
112
|
|
|
|
|
|
|
$t1->focus(); |
113
|
|
|
|
|
|
|
$mw->title("$me: " . $lb->getSelected) }); |
114
|
|
|
|
|
|
|
opendir(DIR,'.'); |
115
|
|
|
|
|
|
|
my $name; |
116
|
|
|
|
|
|
|
foreach $name (readdir(DIR)) |
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
$lb->insert('end',$name) if (-T $name); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
closedir(DIR); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
MainLoop; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub DoAbout { |
125
|
|
|
|
|
|
|
my $aboutdialog; |
126
|
|
|
|
|
|
|
$aboutdialog = |
127
|
|
|
|
|
|
|
$mw->Dialog(-buttons => ['Ok'], |
128
|
|
|
|
|
|
|
-default_button => 'OK', |
129
|
|
|
|
|
|
|
-bitmap=> 'info', |
130
|
|
|
|
|
|
|
-title => 'About', |
131
|
|
|
|
|
|
|
-text => "Text Viewer Version: $VERSION\n" . |
132
|
|
|
|
|
|
|
"By Oded S. Resnik\n\n" . |
133
|
|
|
|
|
|
|
"\n" . |
134
|
|
|
|
|
|
|
"\n", |
135
|
|
|
|
|
|
|
-wraplength => '6i', |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$aboutdialog -> Show; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub ShowHelp { |
142
|
|
|
|
|
|
|
my $helpmsg = ' |
143
|
|
|
|
|
|
|
key-N find previous match |
144
|
|
|
|
|
|
|
Key-n find next match |
145
|
|
|
|
|
|
|
Key-/ search forward |
146
|
|
|
|
|
|
|
Enter search text - then type Enter |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Use right mouse to select text, use left mouse for text menu. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
'; |
151
|
|
|
|
|
|
|
my $helpdialog; |
152
|
|
|
|
|
|
|
my $help_text; |
153
|
|
|
|
|
|
|
$helpdialog = $t1->DialogBox( -buttons => ["Ok"], |
154
|
|
|
|
|
|
|
-title => 'Help'); |
155
|
|
|
|
|
|
|
$help_text = $helpdialog -> add ('Label'); |
156
|
|
|
|
|
|
|
$help_text -> configure ( -font =>'terminal', |
157
|
|
|
|
|
|
|
-justify => 'left', |
158
|
|
|
|
|
|
|
-text =>$helpmsg); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$help_text -> pack; |
161
|
|
|
|
|
|
|
$helpdialog -> Show; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub GetCmd { |
165
|
|
|
|
|
|
|
# Application key binding from menu definitions |
166
|
|
|
|
|
|
|
my $rArray = shift; |
167
|
|
|
|
|
|
|
my ($rCode, $accelerator, $param) = (undef, undef, undef); |
168
|
|
|
|
|
|
|
foreach (@$rArray) { |
169
|
|
|
|
|
|
|
GetCmd($_) if (ref($_) eq 'ARRAY'); |
170
|
|
|
|
|
|
|
for ($_) { |
171
|
|
|
|
|
|
|
if (/-command|-accelerator/) { |
172
|
|
|
|
|
|
|
$param = $_; |
173
|
|
|
|
|
|
|
next; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
if ($param && $param =~ /-command/) { |
176
|
|
|
|
|
|
|
$rCode = $_ if ((ref($_)) =~ /CODE|ARRAY/); |
177
|
|
|
|
|
|
|
$param = undef; |
178
|
|
|
|
|
|
|
next; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
if ($param && $param =~ /-accelerator/) { |
181
|
|
|
|
|
|
|
$accelerator = $_; |
182
|
|
|
|
|
|
|
$param = undef; |
183
|
|
|
|
|
|
|
next; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
if ($rCode && $accelerator) { |
187
|
|
|
|
|
|
|
$mw->bind($mw,"<$accelerator>",$rCode); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
}; |
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
__END__ |