| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Author: Oded S. Resnik Email: razinf@cpan.org |
|
2
|
|
|
|
|
|
|
# Copyright (c) 2003-2004 RAZ Information Systems LTD. http://www.raz.co.il |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
#You may distribute under the terms of either the GNU General Public |
|
5
|
|
|
|
|
|
|
#License or the Artistic License, as specified in the Perl README file |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
package Tk::Text::Viewer; |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
21288
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
68
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.95'; |
|
11
|
|
|
|
|
|
|
$ENV{LANG} = 'C' unless $ENV{LANG}; |
|
12
|
1
|
|
|
1
|
|
1653
|
use Tk::Text; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use base qw(Tk::Text); |
|
14
|
|
|
|
|
|
|
Construct Tk::Widget 'Viewer'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#default enrty lable options |
|
17
|
|
|
|
|
|
|
my $rh_entry_label = {-text=>'Find:', Name=>'entry_label', -cursor=> 'arrow'}; |
|
18
|
|
|
|
|
|
|
my $rh_entry = {-width=>25, -relief=>'sunken', -borderwidth=>3}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub LabelConfig { |
|
22
|
|
|
|
|
|
|
#Allow client to change serach label options |
|
23
|
|
|
|
|
|
|
my ($w, $config) = @_; |
|
24
|
|
|
|
|
|
|
$w->ConfigDo($config,$rh_entry_label); |
|
25
|
|
|
|
|
|
|
}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub EntryConfig { |
|
28
|
|
|
|
|
|
|
#Allow client to change serach enrty options |
|
29
|
|
|
|
|
|
|
my ($w, $config) = @_; |
|
30
|
|
|
|
|
|
|
$w->ConfigDo($config,$rh_entry); |
|
31
|
|
|
|
|
|
|
}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub ConfigDo { |
|
34
|
|
|
|
|
|
|
#Genegric Wigdet config |
|
35
|
|
|
|
|
|
|
my ($w, $config, $rh_wiget_def) = @_; |
|
36
|
|
|
|
|
|
|
if (ref($config) eq '') { |
|
37
|
|
|
|
|
|
|
if ($config =~ /=>/) { |
|
38
|
|
|
|
|
|
|
my ($key,$value) = split ('=>',$config); |
|
39
|
|
|
|
|
|
|
$key =~ s/\s//g; |
|
40
|
|
|
|
|
|
|
$value =~ s/\'|\"//g; |
|
41
|
|
|
|
|
|
|
$$rh_wiget_def{"$key"} = $value if $key; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
else { |
|
44
|
|
|
|
|
|
|
$$rh_wiget_def{"text"} = $config if $config; |
|
45
|
|
|
|
|
|
|
}; |
|
46
|
|
|
|
|
|
|
}; |
|
47
|
|
|
|
|
|
|
if (ref($config) eq 'HASH') { |
|
48
|
|
|
|
|
|
|
foreach my $key (keys %$config) |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
|
|
|
|
|
|
$key =~ s/\s//g; |
|
51
|
|
|
|
|
|
|
$$config{$key} =~ s/\'|\"//g; |
|
52
|
|
|
|
|
|
|
$$rh_wiget_def{$key} = $$config{$key}; |
|
53
|
|
|
|
|
|
|
}; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#Fix context menu |
|
58
|
|
|
|
|
|
|
sub clipEvents |
|
59
|
|
|
|
|
|
|
{ |
|
60
|
|
|
|
|
|
|
return qw[Copy]; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub SearchMenuItems |
|
64
|
|
|
|
|
|
|
{# Remoove the Replace option |
|
65
|
|
|
|
|
|
|
my ($w) = @_; |
|
66
|
|
|
|
|
|
|
my $rOptions = $w->SUPER::SearchMenuItems(@_); |
|
67
|
|
|
|
|
|
|
my $rNewOptions = undef; |
|
68
|
|
|
|
|
|
|
for ( 0 .. $#$rOptions) { |
|
69
|
|
|
|
|
|
|
next if $$rOptions[$_][1] =~ /replace/i; |
|
70
|
|
|
|
|
|
|
push (@$rNewOptions, $$rOptions[$_]); |
|
71
|
|
|
|
|
|
|
}; |
|
72
|
|
|
|
|
|
|
return $rNewOptions; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub ClassInit |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
|
|
|
|
|
|
my ($class,$mw) = @_; |
|
78
|
|
|
|
|
|
|
my $cb = $mw->bind($class,''); |
|
79
|
|
|
|
|
|
|
$class->bindRdOnly($mw); |
|
80
|
|
|
|
|
|
|
$mw->bind($class,'',$cb) if (defined $cb); |
|
81
|
|
|
|
|
|
|
$cb = $mw->bind($class,''); |
|
82
|
|
|
|
|
|
|
$mw->bind($class,'',$cb) if (defined $cb); |
|
83
|
|
|
|
|
|
|
$class->clipboardOperations($mw,'Copy'); |
|
84
|
|
|
|
|
|
|
$mw->bind($class,'',FindSimplePopUp); |
|
85
|
|
|
|
|
|
|
$mw->bind($class,'', FindSelectionNext); |
|
86
|
|
|
|
|
|
|
$mw->bind($class,'', FindSelectionPrevious); |
|
87
|
|
|
|
|
|
|
$mw->bind($class,'', FindAll ); |
|
88
|
|
|
|
|
|
|
return $class; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub Tk::Widget::ScrlViewer { shift->Scrolled('Viewer' => @_) } |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub GetSelPattern { |
|
95
|
|
|
|
|
|
|
# As we want to be able to to "Next" afer FindAll we |
|
96
|
|
|
|
|
|
|
# can't always use selection so we use tags |
|
97
|
|
|
|
|
|
|
my $w=shift; |
|
98
|
|
|
|
|
|
|
my @ranges = $w->tagRanges('sel'); #Get tag index |
|
99
|
|
|
|
|
|
|
my ($start_index, $end_index) = @ranges; |
|
100
|
|
|
|
|
|
|
my $range_pattern = $w->get($start_index, $end_index) if @ranges; |
|
101
|
|
|
|
|
|
|
my $select_patern; #Selection |
|
102
|
|
|
|
|
|
|
eval { $select_patern = $w->SelectionGet(-selection => "PRIMARY"); }; |
|
103
|
|
|
|
|
|
|
if ($range_pattern) { |
|
104
|
|
|
|
|
|
|
return $range_pattern if ($range_pattern eq $select_patern); |
|
105
|
|
|
|
|
|
|
return $select_pattern |
|
106
|
|
|
|
|
|
|
if ($select_pattern && @ranges> 1 |
|
107
|
|
|
|
|
|
|
&& $select_pattern !~ /$range_patten/i); |
|
108
|
|
|
|
|
|
|
$w->unselectAll; |
|
109
|
|
|
|
|
|
|
$w->tagAdd('sel', $start_index, $end_index); |
|
110
|
|
|
|
|
|
|
return $range_pattern; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
return $select_pattern; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub FindSimplePopUp { |
|
116
|
|
|
|
|
|
|
my $w=shift; |
|
117
|
|
|
|
|
|
|
my $pattern = $w->GetSelPattern(); |
|
118
|
|
|
|
|
|
|
foreach ($w->children) { #Not allowing open when active |
|
119
|
|
|
|
|
|
|
if ($_->name eq 'entry_label' ) { |
|
120
|
|
|
|
|
|
|
$w->bell; |
|
121
|
|
|
|
|
|
|
return; |
|
122
|
|
|
|
|
|
|
}; |
|
123
|
|
|
|
|
|
|
}; |
|
124
|
|
|
|
|
|
|
my $entry_label = $w-> Label(%$rh_entry_label); |
|
125
|
|
|
|
|
|
|
$entry_label-> pack(-anchor=>'sw', -side=>'left', -expand => 'no'); |
|
126
|
|
|
|
|
|
|
my $find_entry = $w->Entry(%$rh_entry); |
|
127
|
|
|
|
|
|
|
if ($pattern) { #Defalut value for entry the previous value |
|
128
|
|
|
|
|
|
|
$find_entry -> insert(0, $pattern); |
|
129
|
|
|
|
|
|
|
$find_entry -> selectionRange(0, length ($pattern)); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
$find_entry -> bind( '' => \&KeyCheck); |
|
132
|
|
|
|
|
|
|
$find_entry -> pack (-anchor=>'se', -expand => 'yes' , -fill => 'x', |
|
133
|
|
|
|
|
|
|
-side=>'right'); |
|
134
|
|
|
|
|
|
|
$find_entry -> focus(); |
|
135
|
|
|
|
|
|
|
return; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub FindAll { |
|
139
|
|
|
|
|
|
|
my ($w,$mode, $case, $pattern ) = @_; |
|
140
|
|
|
|
|
|
|
$mode = '-exact' unless $mode; |
|
141
|
|
|
|
|
|
|
$case = '-nocase' unless $case; |
|
142
|
|
|
|
|
|
|
if (!$pattern) { |
|
143
|
|
|
|
|
|
|
$pattern = $w->GetSelPattern(); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
return $w->SUPER::FindAll($mode, $case, $pattern); |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub FindSelectionNext { |
|
149
|
|
|
|
|
|
|
my $w = shift; |
|
150
|
|
|
|
|
|
|
$w->FindNext('-forward', '-exact', '-case',$w->GetSelPattern()); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub FindSelectionPrevious { |
|
154
|
|
|
|
|
|
|
my $w = shift; |
|
155
|
|
|
|
|
|
|
$w->FindNext('-backward', '-exact', '-case',$w->GetSelPattern()); |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub FindSimpleDo |
|
159
|
|
|
|
|
|
|
{ |
|
160
|
|
|
|
|
|
|
my $w = shift; |
|
161
|
|
|
|
|
|
|
my $parent = $w->parent; |
|
162
|
|
|
|
|
|
|
$parent->FindNext ('-forward','-exact','-nocase',$w->get()); |
|
163
|
|
|
|
|
|
|
$parent->focus(); |
|
164
|
|
|
|
|
|
|
foreach ($parent->children) { |
|
165
|
|
|
|
|
|
|
$_->destroy() if ($_->name eq 'entry_label' ); |
|
166
|
|
|
|
|
|
|
}; |
|
167
|
|
|
|
|
|
|
$w->destroy(); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub KeyCheck |
|
171
|
|
|
|
|
|
|
{ |
|
172
|
|
|
|
|
|
|
my $class = shift; |
|
173
|
|
|
|
|
|
|
my $Key = $class->XEvent->K; |
|
174
|
|
|
|
|
|
|
FindSimpleDo($class) if ($Key =~ /Return|Tab/); |
|
175
|
|
|
|
|
|
|
return 1; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub Load |
|
179
|
|
|
|
|
|
|
# Load copied from TextUndo |
|
180
|
|
|
|
|
|
|
# Unicode support added for UTF-8 locale |
|
181
|
|
|
|
|
|
|
{ |
|
182
|
|
|
|
|
|
|
my ($text,$file) = @_; |
|
183
|
|
|
|
|
|
|
my $fmode = ($ENV{LANG} =~ /\.UTF-8/) && $]> 5.007 ? "<:utf8" : "<"; |
|
184
|
|
|
|
|
|
|
if (open(FILE,$fmode, $file)) |
|
185
|
|
|
|
|
|
|
{ |
|
186
|
|
|
|
|
|
|
$text->MainWindow->Busy; |
|
187
|
|
|
|
|
|
|
$text->delete('1.0','end'); |
|
188
|
|
|
|
|
|
|
while () |
|
189
|
|
|
|
|
|
|
{ |
|
190
|
|
|
|
|
|
|
$text->insert('end',$_); |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
close(FILE); |
|
193
|
|
|
|
|
|
|
$text->markSet('insert', '@1,0'); |
|
194
|
|
|
|
|
|
|
$text->MainWindow->Unbusy; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
else |
|
197
|
|
|
|
|
|
|
{ |
|
198
|
|
|
|
|
|
|
$text->messageBox(-message => "Cannot open $file: $!\n"); |
|
199
|
|
|
|
|
|
|
die; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
return 1; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
1; |