24 |
|
proc gethelp {helpfile category topic} { # Open help window |
25 |
|
global curhelp helpfontwidth |
26 |
|
if {! [winfo exists .helpwin]} { # Set up window |
27 |
< |
toplevel .helpwin |
27 |
> |
toplevel .helpwin -cursor top_left_arrow |
28 |
|
wm minsize .helpwin 500 400 |
29 |
|
wm iconbitmap .helpwin question |
30 |
< |
frame .helpwin.but -geometry 150x400 |
30 |
> |
frame .helpwin.but -width 150 -height 400 |
31 |
|
pack .helpwin.but -side right -fill none -expand no |
32 |
|
label .helpwin.but.lab -textvariable curhelp(title) |
33 |
|
place .helpwin.but.lab -relx .1667 -rely 0 |
102 |
|
} |
103 |
|
|
104 |
|
proc helpopen fname { # open the named help file |
105 |
< |
global curhelp helplib |
105 |
> |
global curhelp helpindex helplib |
106 |
|
if {"$fname" == "$curhelp(file)"} {return} |
107 |
|
if {"$curhelp(file)" != {}} { |
108 |
|
close $curhelp(fid) |
109 |
< |
unset curhelp |
109 |
> |
unset curhelp helpindex |
110 |
|
} |
111 |
|
if {[set curhelp(file) $fname] == {}} {return} |
112 |
|
# Complete file name as required |
122 |
|
wm title .helpwin $fname |
123 |
|
set curhelp(title) "[string toupper\ |
124 |
|
[file rootname [file tail $fname]]] HELP" |
125 |
+ |
set ifile [file rootname $fname].ndx |
126 |
|
wm iconname .helpwin [string tolower $curhelp(title)] |
127 |
|
.helpwin.txt configure -state normal |
128 |
|
.helpwin.txt delete 1.0 end |
129 |
|
.helpwin.txt insert end "Loading $fname..." |
130 |
|
update |
131 |
|
set curhelp(fid) [open $fname r] |
132 |
< |
set curhelp(index) {} |
133 |
< |
set catlist {} |
134 |
< |
while {[gets $curhelp(fid) li] >= 0} { |
135 |
< |
if [regexp -nocase {^\.([A-Z][A-Z0-9]*)\.([A-Z][A-Z0-9]*)$} \ |
136 |
< |
$li dummy cat top] { |
137 |
< |
lappend curhelp(index) "$cat $top [tell $curhelp(fid)]" |
138 |
< |
if {[lsearch -exact $catlist $cat] < 0} { |
139 |
< |
lappend catlist $cat |
132 |
> |
if {! [file exists $ifile] || |
133 |
> |
[file mtime $fname] > [file mtime $ifile]} { |
134 |
> |
set helpindex(catlist) {} |
135 |
> |
while {[gets $curhelp(fid) li] >= 0} { |
136 |
> |
if [regexp -nocase {^\.([A-Z][A-Z0-9]*)\.([A-Z][A-Z0-9]*)$} \ |
137 |
> |
$li dummy cat top] { |
138 |
> |
lappend helpindex([string toupper $cat]) $top |
139 |
> |
set helpindex([string toupper $cat,$top]) \ |
140 |
> |
[tell $curhelp(fid)] |
141 |
> |
if {[lsearch -exact $helpindex(catlist) $cat] < 0} { |
142 |
> |
lappend helpindex(catlist) $cat |
143 |
> |
} |
144 |
|
} |
145 |
|
} |
146 |
+ |
if {! [catch {set fi [open $ifile w]}]} { |
147 |
+ |
puts $fi "# This is an automatically created index\ |
148 |
+ |
file -- DO NOT EDIT!" |
149 |
+ |
writevars $fi helpindex |
150 |
+ |
close $fi |
151 |
+ |
catch {exec chmod 666 $ifile} |
152 |
+ |
} |
153 |
+ |
} else { |
154 |
+ |
source $ifile |
155 |
|
} |
156 |
|
.helpwin.but.catb.m delete 0 last |
157 |
< |
foreach cat $catlist { |
157 |
> |
foreach cat $helpindex(catlist) { |
158 |
|
.helpwin.but.catb.m add command -label $cat \ |
159 |
|
-command "helphist new $cat intro" |
160 |
|
} |
166 |
|
} |
167 |
|
|
168 |
|
proc helpgoto {cat top} { # find selected category and topic |
169 |
< |
global curhelp |
169 |
> |
global curhelp helpindex |
170 |
|
# Capitalize "just in case" |
171 |
|
set cat [string toupper $cat] |
172 |
|
set top [string toupper $top] |
174 |
|
set curhelp(topic) $top |
175 |
|
if {"$cat" != "$curhelp(category)"} { |
176 |
|
set curhelp(category) $cat |
163 |
– |
set toplist {} |
164 |
– |
set n [llength $curhelp(index)] |
165 |
– |
for {set i 0} {$i < $n} {incr i} { |
166 |
– |
if {"[string toupper [lindex [lindex \ |
167 |
– |
$curhelp(index) $i] 0]]" == "$cat"} { |
168 |
– |
lappend toplist [lindex [lindex \ |
169 |
– |
$curhelp(index) $i] 1] |
170 |
– |
} |
171 |
– |
} |
177 |
|
.helpwin.but.topb.m delete 0 last |
178 |
< |
foreach top $toplist { |
178 |
> |
foreach top $helpindex($cat) { |
179 |
|
.helpwin.but.topb.m add command -label $top \ |
180 |
|
-command "helphist new \$curhelp(category) $top" |
181 |
|
} |
184 |
|
} |
185 |
|
|
186 |
|
proc helpupdate {} { # update help text window |
187 |
< |
global curhelp helpfontwidth |
187 |
> |
global curhelp helpindex helpfontwidth |
188 |
|
# Print category and topic |
189 |
|
set linelen [expr "[winfo width .helpwin.txt] / $helpfontwidth - 1"] |
190 |
|
.helpwin.txt configure -state normal |
199 |
|
# Search for it in file |
200 |
|
if {"$curhelp(category) $curhelp(topic)" != |
201 |
|
"[string toupper $curhelp(next)]"} { |
202 |
< |
for {set i [llength $curhelp(index)]} {[incr i -1] >= 0} {} { |
203 |
< |
if {"$curhelp(category) $curhelp(topic)" == |
204 |
< |
[lrange [string toupper [lindex \ |
200 |
< |
$curhelp(index) $i]] 0 1]} { |
201 |
< |
break |
202 |
< |
} |
203 |
< |
} |
204 |
< |
if {$i < 0} { |
202 |
> |
if [info exists helpindex($curhelp(category),$curhelp(topic))] { |
203 |
> |
seek $curhelp(fid) $helpindex($curhelp(category),$curhelp(topic)) |
204 |
> |
} else { |
205 |
|
.helpwin.txt insert end "\nNo such help topic." |
206 |
|
.helpwin.txt configure -state disabled |
207 |
|
return ".$curhelp(category).$curhelp(topic) not found\ |
208 |
|
in $curhelp(file)" |
209 |
|
} |
210 |
– |
seek $curhelp(fid) [lindex [lindex $curhelp(index) $i] 2] |
210 |
|
} |
211 |
|
# Load help text into our window |
212 |
|
set linepos 0 |
250 |
|
set curhelp(next) "$cat $top" |
251 |
|
.helpwin.but.next configure -state normal |
252 |
|
} else { |
253 |
+ |
set curhelp(next) {} |
254 |
|
.helpwin.but.next configure -state disabled |
255 |
|
} |
256 |
|
.helpwin.txt configure -state disabled |
305 |
|
} |
306 |
|
|
307 |
|
proc helpsearch word { # search for occurances of the given word |
308 |
< |
global curhelp |
308 |
> |
global curhelp helpindex |
309 |
|
if {"$curhelp(search)" == {}} { |
310 |
|
set curhelp(msg) "No pattern." |
311 |
|
return 0 |
312 |
|
} |
313 |
|
set nmatches 0 |
314 |
< |
set cat [lindex [lindex $curhelp(index) 0] 0] |
315 |
< |
set top [lindex [lindex $curhelp(index) 0] 1] |
314 |
> |
set cat [lindex $helpindex(catlist) 0] |
315 |
> |
set top [lindex $helpindex([string toupper $cat]) 0] |
316 |
|
set startpos [tell $curhelp(fid)] |
317 |
< |
seek $curhelp(fid) [lindex [lindex $curhelp(index) 0] 2] |
317 |
> |
seek $curhelp(fid) $helpindex([string toupper $cat,$top]) |
318 |
|
set foundmatch 0 |
319 |
|
while {[gets $curhelp(fid) li] >= 0} { |
320 |
|
if [regexp -nocase {^\.([A-Z][A-Z0-9]*)\.([A-Z][A-Z0-9]*)$} \ |