# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # This module contains H's menu routines. Some of these are called # # only once, at startup, but many are called on the fly to build # # dynamic menus. Check the button definitions to see which have a # # dynamic binding pointing to one of these routines. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # global argv initfile Hist URLs stk stkN N PrintCmd SendCmd set PrintCmd lpr set SendCmd M_EditSend if ![info exists stk ] {set stk {}} if ![info exists stkN] {set stkN 0} if ![info exists initfile] {set initfile {}} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Create the "Cmd" menu widget. proc menuCmd {w X Y} { global V me URLt opt PrintCmd SendCmd curX curY set curX $X set curY $Y if {$V>1} {puts "menuCmd X=$X Y=$Y ..."} if [winfo exists .b.bCmd.menu] {destroy .b.bCmd.menu} menu .b.bCmd.menu -activeborderwidth 0 .b.bCmd.menu add command -label {New viewer} -command "exec $me &" .b.bCmd.menu add cascade -label Load -menu .b.bCmd.menu.load .b.bCmd.menu add cascade -label Save -menu .b.bCmd.menu.save .b.bCmd.menu add command -label Find -command "FindWin $w" .b.bCmd.menu add command -label Print -command "txtSaveAs $w $PrintCmd" .b.bCmd.menu add cascade -label Edit -menu .b.bCmd.menu.edit .b.bCmd.menu add cascade -label Send -menu .b.bCmd.menu.send .b.bCmd.menu add command -label Quit -command exit menu .b.bCmd.menu.load -activeborderwidth 0 .b.bCmd.menu.load add command -label Settings -command "LoadSettings" .b.bCmd.menu.load add command -label Document -command "LoadFile $w {} $URLt($w.d.t) GET" menu .b.bCmd.menu.edit -activeborderwidth 0 .b.bCmd.menu.edit add command -label {Initialization file} -command {editInitFile} .b.bCmd.menu.edit add command -label {Environment} -command {editEnv} menu .b.bCmd.menu.save -activeborderwidth 0 .b.bCmd.menu.save add command -label {Save settings} -command "SaveSettings {}" .b.bCmd.menu.save add command -label {Save source} -command {txtSaveAs .src.t} .b.bCmd.menu.save add command -label {Save formatted} -command {txtSaveAs .d.t} menu .b.bCmd.menu.send -activeborderwidth 0 .b.bCmd.menu.send add command -label {Send source} -command {txtSaveAs .src.t $SendCmd} .b.bCmd.menu.send add command -label {Send formatted} -command {txtSaveAs .d.t $SendCmd} if {$X && $Y} {tk_popup .b.bCmd.menu $X $Y} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # We use the .htmlsettings file for dynamic options that are easily # # sharable between browsers via the Cmd..Load..Settings menu item. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc LoadSettings {} { global env Path Source .htmlsettings if ![info exists "Path(.htmlsettings)"] { if [info exists env(HOME)] { if [file exists "$env(HOME)/.htmlsettings"] { source "$env(HOME)/.htmlsettings" set Path(.htmlsettings) "$env(HOME)/.htmlsettings" } } } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Saving things to the .htmlsettings file is more work. We might want # # to be on the lookout for variables to add here. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc SaveSettings {file} { global B V me env opt Path URLs if {$file != {}} { set filename $file } elseif [info exists Path(.htmlsettings)] { set filename $Path(.htmlsettings) } elseif [info exists env(HOME)] { set filename "$env(HOME)/.htmlsettings" } else { Msg "Can't locate .htmlsettings file." return } if [catch {open $filename w} f] { Msg "Can't write \"$filename\"" return } Msg "Writing $f=\"$filename\"" puts $f "# Dynamic HTML reader settings" puts $f "global B opt URLs" puts $f "set B {$B}" foreach n [array names opt] { puts $f "set opt($n) {$opt($n)}" } if {$URLs != {}} { puts $f "set URLs {" foreach u $URLs { puts $f " {$u}" } puts $f "}" } close $f } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Create the title widget for a window. We set it up here, but don't pack it # yet, because normally the title will be shown in the window manager's title # bar. We have our own title widget mostly for when the title bar isn't shown. #proc Title {w state} { # global B C V FB R me opt fonts title # entry $w.i.t -textvariable title -font $fonts(F4vsb) \ # -bd 0 -relief $R -width 0 -highlightthickness 0 -fg yellow -bg navy ## pack $w.i.t -in $w.i -expand 1 -fill x # if {$V>1} {puts "$me/Title: on."} # set opt(TTL) $state #} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc titleon w { global opt set opt(TTL) 1 Packs $w } proc titleoff w { global opt set opt(TTL) 0 pack forget $w.i.t } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Create the "Opt" menu widget. proc menuOpt {w X Y} { global V me opt curX curY set curX $X set curY $Y if {$V>1} {puts "$me/menuOpt: w=$w X=$X Y=$Y ..."} if [winfo exists $w.b.bOpt.menu] { if {$V>4} {puts "$me/menuOpt: Destroy old $w.b.bOpt.menu"} destroy $w.b.bOpt.menu } if {$V>4} {puts "$me/menuOpt: Create new $w.b.bOpt.menu"} menu $w.b.bOpt.menu -activeborderwidth 0 $w.b.bOpt.menu add cascade -label {On/Off} -menu $w.b.bOpt.menu.onoff menu $w.b.bOpt.menu.onoff -activeborderwidth 0 $w.b.bOpt.menu add cascade -label {Info} -menu $w.b.bOpt.menu.onoff.info menu $w.b.bOpt.menu.onoff.info -activeborderwidth 0 if {$opt(H) > 0} { $w.b.bOpt.menu.onoff add command -command {set opt(H) 0} -label {Don't assume HTML} } else { $w.b.bOpt.menu.onoff add command -command {set opt(H) 1} -label {Assume HTML} } if {$opt(IMG) > 0} { $w.b.bOpt.menu.onoff add command -command {set opt(IMG) 0} -label {Ignore images} } else { $w.b.bOpt.menu.onoff add command -command {set opt(IMG) 1} -label {Show images} } if {$opt(TARGET) > 0} { $w.b.bOpt.menu.onoff add command -command {set opt(IMG) 0} -label {Ignore targets} } else { $w.b.bOpt.menu.onoff add command -command {set opt(IMG) 1} -label {Show targets} } if {$opt(TTL) > 0} { $w.b.bOpt.menu.onoff.info add command -command "titleoff {$w}" -label {Hide title} } else { $w.b.bOpt.menu.onoff.info add command -command "titleon {$w}" -label {Show title} } if {$opt(ALT) > 0} { $w.b.bOpt.menu.onoff add command -command "set opt(ALT) 0; Packs {$w}" -label {Hide ALT titles} } else { $w.b.bOpt.menu.onoff add command -command "set opt(ALT) 1; Packs {$w}" -label {Show ALT titles} } if {$opt(URL) > 0} { $w.b.bOpt.menu.onoff.info add command -command "set opt(URL) 0; Packs {$w}" -label {Hide URL} } else { $w.b.bOpt.menu.onoff.info add command -command "set opt(URL) 1; Packs {$w}" -label {Show URL} } if {$opt(MSG) > 0} { $w.b.bOpt.menu.onoff.info add command -command "set opt(MSG) 0; Packs {$w}" -label {Hide message} } else { $w.b.bOpt.menu.onoff.info add command -command "set opt(MSG) 1; Packs {$w}" -label {Show message} } if {$opt(LNK) > 0} { $w.b.bOpt.menu.onoff.info add command -command "set opt(LNK) 0; Packs {$w}" -label {Hide link URL} } else { $w.b.bOpt.menu.onoff.info add command -command "set opt(LNK) 1; Packs {$w}" -label {Show link URL} } if {$opt(NAM) > 0} { $w.b.bOpt.menu.onoff.info add command -command "set opt(NAM) 0; Packs {$w}" -label {Hide widget name} } else { $w.b.bOpt.menu.onoff.info add command -command "set opt(NAM) 1; Packs {$w}" -label {Show widget name} } $w.b.bOpt.menu add cascade -label {Level of table handling} -menu $w.b.bOpt.menu.table menu $w.b.bOpt.menu.table $w.b.bOpt.menu.table add command -command {set opt(TABLE) 0} -label {0: None} $w.b.bOpt.menu.table add command -command {set opt(TABLE) 1} -label {1: tk} $w.b.bOpt.menu.table add command -command {set opt(TABLE) 2} -label {2: tkTable} $w.b.bOpt.menu add cascade -label {Level of popup handling} -menu $w.b.bOpt.menu.popup menu $w.b.bOpt.menu.popup $w.b.bOpt.menu.popup add command -command {set opt(POPUP) 0} -label {0: No popups} $w.b.bOpt.menu.popup add command -command {set opt(POPUP) 1} -label {1: original URLs} $w.b.bOpt.menu.popup add command -command {set opt(POPUP) 2} -label {2: expanded URLs} $w.b.bOpt.menu.popup add command -command {set opt(POPUP) 3} -label {3: both URLs} if $opt(Option) { $w.b.bOpt.menu add command -command {OptionWin 0} -label {Hide Option window} } else { $w.b.bOpt.menu add command -command {OptionWin 1} -label {Show Option window} } if {$X && $Y} {tk_popup $w.b.bOpt.menu $X $Y} if {$V>4} {puts "$me/menuOpt: Done."} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Create the "Win" menu widget. proc menuWin {w X Y} { global V me opt curX curY set curX $X set curY $Y if {$V>1} {puts "$me/menuWin: w=$w X=$X Y=$Y ..."} if [winfo exists .b.bWin.menu] { if {$V>4} {puts "$me/menuWin: Destroy old .b.bWin.menu"} destroy .b.bWin.menu } if {$V>4} {puts "$me/menuWin: Create new .b.bWin.menu"} menu .b.bWin.menu -activeborderwidth 0 if $opt(Option) { .b.bWin.menu add command -command {OptionWin 0} -label {Hide Option window} } else { .b.bWin.menu add command -command {OptionWin 1} -label {Show Option window} } if $opt(Debug) { .b.bWin.menu add command -command {DebugWin 0} -label {Hide Debug window} } else { .b.bWin.menu add command -command {DebugWin 1} -label {Show Debug window} } if $opt(Header) { .b.bWin.menu add command -command {HeaderWin 0} -label {Hide Header window} } else { .b.bWin.menu add command -command {HeaderWin 1} -label {Show Header window} } if $opt(Source) { .b.bWin.menu add command -command {SourceWin 0} -label {Hide Source window} } else { .b.bWin.menu add command -command {SourceWin 1} -label {Show Source window} } if {$X && $Y} {tk_popup .b.bWin.menu $X $Y} if {$V>4} {puts "$me/menuWin: Done."} } if ![info exists Hist] {if {$argv != {}} {set Hist $argv} else {set Hist {}}} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Create the "Hist" menu widget. The b arg tells us which mouse # # button the user clicked on the menu button. For B1 and B2, we # # generate commands to load the URL into the current window w; for B3 # # and Shift-B1we generate commands to fire up a new HTML viewer. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc menuHst {b w X Y} { global V me Hist curW curX curY set curX $X set curY $Y if {$V>1} {puts "menuHst X=$X Y=$Y ..."} if [winfo exists .b.bHst.menu] {destroy .b.bHst.menu} menu .b.bHst.menu -activeborderwidth 0 foreach u $Hist { switch $b { L {.b.bHst.menu add command -label $u -command "LoadFile {$curW} {} $u GET"} H {.b.bHst.menu add command -label $u -command "exec $me $u &"} } } if {$X && $Y} {tk_popup .b.bHst.menu $X $Y} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Create the "URL Stack" menu widget. This is very much like the # # above "Hist" menu routine, but using the menu stack (array) rather # # than the Hist list. We also use the b arg to distinguish B1 and B2 # # from B3 and Shift-B1. The former reload the URL into the current # # window; the latter load the URL into a new HTMO viewer window. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc menuStk {b w X Y} { global V me stk stkN curX curY set curX $X set curY $Y if {$V>1} {puts "menuStk X=$X Y=$Y ..."} if [winfo exists .b.st.bStk.menu] {destroy .b.st.bStk.menu} menu .b.st.bStk.menu -activeborderwidth 0 set i 0 foreach u $stk { if {$i == $stkN} {set x {>}} else {set x { }} switch $b { L {.b.st.bStk.menu add command -label "$x$u" -command "Stk $i"} H {.b.st.bStk.menu add command -label "$x$u" -command "exec $me $u &"} } incr i } if {$X && $Y} {tk_popup .b.st.bStk.menu $X $Y} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Load a URL from the stack. The arg is a direction, "up" or "dn", or a number. proc Stk {d} { global V stk stkN if {$V>1} {puts "Stk \"$d\""} if {$d == {dn}} { if {[incr stkN] >= [llength $stk]} {incr stkN -1} if {$V>1} {puts "Stk: stkN=$stkN (incr)"} } elseif {$d == {up}} { if {[incr stkN -1] < 0} {set stkN 0} if {$V>1} {puts "Stk: stkN=$stkN (decr)"} } else { if {$V>1} {puts "Stk: Absolute stack position \"$d\"."} set stkN $d } LoadFile .d.t {} [lindex $stk $stkN] GET } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc editInitFile {} { global V me env initfile Path if {$V>1} {set id "$me/editInitFile"} if [info exists Path(.htmlinit)] { set initfile $Path(.htmlinit) } elseif [info exists Path(.htmlrc)] { set initfile $Path(.htmlrc) } else { set initfile $env(HOME)/.htmlinit if {$V>1} {puts "$id: No inititialization file found, using default."} } if {$V>1} {puts "$id: Initialization file is \"$Path(.htmlinit)\""} editFile $initfile } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc editEnv {} { global V me env newenvvar newenvval if {$V>1} {set id "$me/editInitEnv"} if [winfo exists .env] {destroy .env} toplevel .env set r 0 foreach n [lsort [array names env]] { label .env.n$r -text $n entry .env.v$r -textvariable env($n) -width 0 grid .env.n$r -in .env -row $r -column 0 grid .env.v$r -in .env -row $r -column 1 -sticky w incr r } entry .env.n$r -textvariable newenvvar -width 0 entry .env.v$r -textvariable newenvval -width 0 grid .env.n$r -in .env -row $r -column 0 grid .env.v$r -in .env -row $r -column 1 -sticky w bind .env.n$r newEnvVar bind .env.v$r newEnvVar } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc newEnvVar {} { global V me env newenvvar newenvval if {$V>1} {set id "$me/newEnvVar"; puts "$id: $newenvvar=\"$newenvval\""} set env($newenvvar $newenvval editEnv } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc editFile f { global V E me env if {$V>1} {set id "$me/editFile"} set cmd "xterm -e $E $f" if {$V>1} {puts "$id: Edit command \"$cmd\""} eval exec $cmd & }