1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
# help.tcl
#
# shows HTML 2.0 files
# no directory handling
proc hlp_taglink {} {
global hlp
if {$hlp(tag) == {}} {return}
.help.t tag configure $hlp(tag) -borderwidth 0 -relief flat
regsub L: $hlp(tag) {} link
HMlink_callback .help.t $link
}
proc hlp_Next {{delta 1}} {
global hlp
if {$hlp(tag) != {}} {
.help.t tag configure $hlp(tag) -borderwidth 0 -relief flat
set hlp(tag) {}
}
set pos [.help.t index insert]
set l [llength $hlp(links)]
if {$delta > 0} {
for {set i 0} {$i < $l} {incr i} {
if {[.help.t compare $pos < [lindex [lindex $hlp(links) $i] 0]]} {break}
}
if {$i == $l} {return}
} else {
for {set i [expr $l-1]} {$i >= 0} {incr i -1} {
if {[.help.t compare $pos > [lindex [lindex $hlp(links) $i] 0]]} {break}
}
if {$i == 0} {return}
}
set entry [lindex $hlp(links) $i]
set pos [lindex $entry 0]
set hlp(tag) [lindex $entry 1]
.help.t tag configure $hlp(tag) -borderwidth 2 -relief raised
.help.t mark set insert $pos
.help.t see $pos
}
proc hlp_Copy {} {
global hlp ted_buf
set ted_buf [selection get]
}
proc ReadHtml {win file {pos ""}} {
global params hlp
cd $hlp(cur_dir)
set fd [open $file r]
set text [read $fd]
close $fd
cd [file dirname $file]
set hlp(cur_dir) [pwd]
set file [file tail $file]
lappend hlp(history) [pwd]/$file#$pos
cd $params(Primary_dir)
HMparse_html $text "HMrender $win"
if {$pos != ""} {
HMgoto $win $pos
}
}
proc HMlink_callback {win file {his 0}} {
global hlp params
if {$hlp(locked)} {return}
set pos ""
if {$his < 0} {
set l [expr [llength $hlp(history)]-2]
if {$l >= 0} {
set file [lindex $hlp(history) $l]
set hlp(history) [lreplace $hlp(history) $l end]
} else {
return
}
}
set hlp(locked) 1
regexp {([^#]*)#(.*)} $file dummy file pos
debug $pos
if {$file == "" && $pos != ""} {
HMgoto $win $pos
catch {.help.t mark set insert N:$pos}
set hlp(locked) 0
return
}
WaitHint $win "Please be patient"
HMreset_win $win
ReadHtml $win $file $pos
.help.t mark set insert 1.0
set hlp(links) {}
foreach tag [.help.t tag names] {
if [regexp {^L:.*} $tag] {
set r [.help.t tag ranges $tag]
set l [llength $r]
for {set i 0} {$i < $l} {incr i 2} {
debug "[lindex $r $i] $tag]"
lappend hlp(links) [list [lindex $r $i] $tag]
}
}
}
if {$pos != {}} {
.help.t mark set insert N:$pos
}
DelWaitHint
set hlp(locked) 0
}
proc hlpcmp {a b} {
set x [lindex $a 0]
set y [lindex $b 0]
if {$x < $y} {return -1}
if {$x > $y} {return 1}
return 0
}
proc HelpWin {} {
global hlp params gparams
toplevel .help
wm geometry .help +0+100
wm title .help Help
menu .help.menubar
.help config -menu .help.menubar
foreach m {File Topics} {
set $m [menu .help.menubar.m$m -tearoff 0]
.help.menubar add cascade -label $m -underline 0 -menu .help.menubar.m$m
}
$File add command -label Exit -accelerator Esc \
-command HelpClose
$Topics add command -label Main -accelerator M \
-command "HMlink_callback .help.t $hlp(dir)/main.html#main"
# $Topics add command -label Index -accelerator I \
# -command "HMlink_callback .help.t $hlp(dir)/index.html"
$Topics add command -label LaTeX \
-command "HMlink_callback .help.t $hlp(dir)/latex/index.html"
frame .help.b -bd 1 -relief groove
pack .help.b -fill x
HintButton .help.b.home home.ico \
"HMlink_callback .help.t $hlp(dir)/main.html#main" Home
HintButton .help.b.latex tex1.ico \
"HMlink_callback .help.t $hlp(dir)/latex/index.html" "LaTeX help"
HintButton .help.b.ref man1.ico \
"HMlink_callback .help.t $hlp(dir)/latex/sec184.html" "LaTeX index"
HintButton .help.b.left left.ico \
"HMlink_callback .help.t dummy -1" Back
HintButton .help.b.exit door1.ico HelpClose Close
pack .help.b.home .help.b.latex .help.b.ref .help.b.left -side left
pack .help.b.exit -side right
scrollbar .help.sb -command {.help.t yview}
pack .help.sb -side right -fill y
text .help.t -yscroll {.help.sb set}
catch {
.help.t configure -font \
[list $gparams(font) $gparams(fontsize) $gparams(fontstyle)]
}
pack .help.t -fill both -expand true
HMinit_win .help.t
set hlp(history) {}
set hlp(history_pos) 0
bindtags .help.t {.help.t .}
bind .help.t <Tab> {hlp_Next}
bind .help.t <Shift-Tab> {hlp_Next -1}
bind .help.t <Any-i> "HMlink_callback .help.t $hlp(dir)/latex/sec184.html"
bind .help.t <Any-m> "HMlink_callback .help.t $hlp(dir)/main.html#main"
bind .help.t <Control-c> {hlp_Copy}
bind .help.t <Return> {hlp_taglink}
bind .help.t <Escape> HelpClose
bind .help.t <Prior> [bind Text <Prior>]
bind .help.t <Next> [bind Text <Next>]
bind .help.t <Up> [bind Text <Up>]
bind .help.t <Down> [bind Text <Down>]
bind .help.t <Alt-Key> [bind all <Alt-Key>]
bind .help.t <Any-Key> { }
set x [winfo rootx .help.t]
set y [winfo rooty .help.t]
set hlp(dlg_geom) 300x200+$x+$y
set hlp(cur_dir) $hlp(dir)
set hlp(locked) 0
set hlp(tag) {}
set hlp(pos) -1
update
}
proc HelpClose {} {
global hlp
catch {xfocus $hlp(old_focus)}
catch {destroy .hint}
destroy .help
}
proc Help {win} {
global hlp params gparams
set hlp(dir) $params(hlpdir)/$gparams(hlplan)
if {![file exists $hlp(dir)]} {
Warning $params(dlg_geom) "Help directory not found.\nPlease reset \
global options!"
return
}
if {![winfo exists .help]} {
HelpWin
}
switch $win {
"." {set item "main.html#main"}
default {set item "tedit.html#main"}
}
set hlp(old_focus) [focus]
xfocus .help.t
HMlink_callback .help.t $item
set hlp(links) [lsort -command hlpcmp $hlp(links)]
debug $hlp(links)
}
|