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 |
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 curhelp(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 $curhelp(catlist) $cat] < 0} { |
142 |
> |
lappend curhelp(catlist) $cat |
143 |
> |
} |
144 |
|
} |
145 |
|
} |
146 |
+ |
if {! [catch {set fi [open $ifile w]}]} { |
147 |
+ |
writevars $fi {curhelp(catlist) helpindex} |
148 |
+ |
close $fi |
149 |
+ |
catch {exec chmod 666 $ifile} |
150 |
+ |
} |
151 |
+ |
} else { |
152 |
+ |
source $ifile |
153 |
|
} |
154 |
|
.helpwin.but.catb.m delete 0 last |
155 |
< |
foreach cat $catlist { |
155 |
> |
foreach cat $curhelp(catlist) { |
156 |
|
.helpwin.but.catb.m add command -label $cat \ |
157 |
|
-command "helphist new $cat intro" |
158 |
|
} |
164 |
|
} |
165 |
|
|
166 |
|
proc helpgoto {cat top} { # find selected category and topic |
167 |
< |
global curhelp |
167 |
> |
global curhelp helpindex |
168 |
|
# Capitalize "just in case" |
169 |
|
set cat [string toupper $cat] |
170 |
|
set top [string toupper $top] |
172 |
|
set curhelp(topic) $top |
173 |
|
if {"$cat" != "$curhelp(category)"} { |
174 |
|
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 |
– |
} |
175 |
|
.helpwin.but.topb.m delete 0 last |
176 |
< |
foreach top $toplist { |
176 |
> |
foreach top $helpindex($cat) { |
177 |
|
.helpwin.but.topb.m add command -label $top \ |
178 |
|
-command "helphist new \$curhelp(category) $top" |
179 |
|
} |
182 |
|
} |
183 |
|
|
184 |
|
proc helpupdate {} { # update help text window |
185 |
< |
global curhelp helpfontwidth |
185 |
> |
global curhelp helpindex helpfontwidth |
186 |
|
# Print category and topic |
187 |
|
set linelen [expr "[winfo width .helpwin.txt] / $helpfontwidth - 1"] |
188 |
|
.helpwin.txt configure -state normal |
197 |
|
# Search for it in file |
198 |
|
if {"$curhelp(category) $curhelp(topic)" != |
199 |
|
"[string toupper $curhelp(next)]"} { |
200 |
< |
for {set i [llength $curhelp(index)]} {[incr i -1] >= 0} {} { |
201 |
< |
if {"$curhelp(category) $curhelp(topic)" == |
202 |
< |
[lrange [string toupper [lindex \ |
200 |
< |
$curhelp(index) $i]] 0 1]} { |
201 |
< |
break |
202 |
< |
} |
203 |
< |
} |
204 |
< |
if {$i < 0} { |
200 |
> |
if [info exists helpindex($curhelp(category),$curhelp(topic))] { |
201 |
> |
seek $curhelp(fid) $helpindex($curhelp(category),$curhelp(topic)) |
202 |
> |
} else { |
203 |
|
.helpwin.txt insert end "\nNo such help topic." |
204 |
|
.helpwin.txt configure -state disabled |
205 |
|
return ".$curhelp(category).$curhelp(topic) not found\ |
206 |
|
in $curhelp(file)" |
207 |
|
} |
210 |
– |
seek $curhelp(fid) [lindex [lindex $curhelp(index) $i] 2] |
208 |
|
} |
209 |
|
# Load help text into our window |
210 |
|
set linepos 0 |
248 |
|
set curhelp(next) "$cat $top" |
249 |
|
.helpwin.but.next configure -state normal |
250 |
|
} else { |
251 |
+ |
set curhelp(next) {} |
252 |
|
.helpwin.but.next configure -state disabled |
253 |
|
} |
254 |
|
.helpwin.txt configure -state disabled |
303 |
|
} |
304 |
|
|
305 |
|
proc helpsearch word { # search for occurances of the given word |
306 |
< |
global curhelp |
306 |
> |
global curhelp helpindex |
307 |
|
if {"$curhelp(search)" == {}} { |
308 |
|
set curhelp(msg) "No pattern." |
309 |
|
return 0 |
310 |
|
} |
311 |
|
set nmatches 0 |
312 |
< |
set cat [lindex [lindex $curhelp(index) 0] 0] |
313 |
< |
set top [lindex [lindex $curhelp(index) 0] 1] |
312 |
> |
set cat [lindex $curhelp(catlist) 0] |
313 |
> |
set top [lindex $helpindex([string toupper $cat]) 0] |
314 |
|
set startpos [tell $curhelp(fid)] |
315 |
< |
seek $curhelp(fid) [lindex [lindex $curhelp(index) 0] 2] |
315 |
> |
seek $curhelp(fid) $helpindex([string toupper $cat,$top]) |
316 |
|
set foundmatch 0 |
317 |
|
while {[gets $curhelp(fid) li] >= 0} { |
318 |
|
if [regexp -nocase {^\.([A-Z][A-Z0-9]*)\.([A-Z][A-Z0-9]*)$} \ |