From: Mike C. <mik...@us...> - 2002-09-19 16:15:32
|
Update of /cvsroot/maxima/maxima/interfaces/xmaxima/Tkmaxima In directory usw-pr-cvs1:/tmp/cvs-serv22214/Tkmaxima Modified Files: Browser.tcl Added Files: Bindings.tcl Log Message: Break out bindings and make them more consistent with Windows --- NEW FILE: Bindings.tcl --- # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # # $Id: Bindings.tcl,v 1.1 2002/09/19 16:15:28 mikeclarkson Exp $ # ###### Bindings.tcl ###### ############################################################ # Netmath Copyright (C) 1998 William F. Schelter # # For distribution under GNU public License. See COPYING. # ############################################################ global NCtextHelp set NCtextHelp " Bindings: <Return> This sends the current expression (ie where the insert cursor is) for evaluation. <Linefeed> (Control-j) This inserts a newline, and is useful for entering multiline input. <Control-k> Kills the current line and puts it in kill ring. Successive control-k's append their output together. <Control-y> Yank out the last kill, Meta-y cycles thru previous kills. <Control-g> Interrupt the current computation. <Alt-p> Previous input, or if repeated cycle through the previous inputs. If the current input is not empty, then match only inputs which begin with the current input. <Alt-n> Like Previous input, but in opposite direction. " proc vMAXSetCNTextBindings {w} { bind CNtext <Return> "CMeval %W ; break" bind CNtext <Control-g> "CMinterrupt %W " bind CNtext <Control-u> "CNclearinput %W " bind CNtext "\)" "CNblinkMatchingParen %W %A" bind CNtext "\]" "CNblinkMatchingParen %W %A" bind CNtext "\}" "CNblinkMatchingParen %W %A" bind CNtext <Control-j> "tkTextInsert %W %A ; openMathAnyKey %W %K %A" bind CNtext <Alt-p> "CNpreviousInput $w -1" bind CNtext <Alt-n> "CNpreviousInput $w 1" bind CNtext <Alt-s> {sendMaxima %W ":s\n" } bind CNtext <Control-Key-c> {tk_textCopy %W ;break} bind CNtext <Control-Key-x> {tk_textCut %W ;break} bind CNtext <Control-Key-v> {tk_textPaste %W ;break} } global maxima_priv set maxima_priv(doublek) 0 bind OpenMathText <Control-Key-k><Control-Key-k> { set maxima_priv(doublek) 1 } global maxima_priv if {0} { # xmaxima should not be binding the Text class if {! [info exists maxima_priv(bindings_added) ] } { bind Text <Control-Key-k> "+openMathControlK %W" bind Text <B3-Motion> [bind Text <B2-Motion>] bind Text <Button-3> [bind Text <Button-2>] set maxima_priv(bindings_added) 1 } } else { bind OpenMathText <Control-Key-k> "+openMathControlK %W" } #mike - I'm decreeing windows Cut/Copy/Paste conventions for # keybindings, and will preobably reserve Alt-key for menu shortcuts. bind OpenMathText <Control-Key-y> "OpenMathYank %W 0; break" bind OpenMathText <Alt-Key-y> "OpenMathYank %W 1; break" bind OpenMathText <Meta-Key-y> "OpenMathYank %W 1; break" # put the clipboard paste on Control-Shift-y # event add <<Paste>> <Control-Shift-y> # Copy bind OpenMathText <Alt-Key-w> { pushCommand %W SaveSelection "" if { "[selection own -displayof %W]" == "%W"} { pushl [saveText %W sel.first sel.last] killRing selection clear -displayof %W } } bind OpenMathText <Key> {openMathAnyKey %W %K %A} bind OpenMathText <Alt-Key> {openMathAnyKey %W %K ALT_%A} # stop the double button click word selection in openMathText.. bind OpenMathText <Double-Button-1> { break; } bind OpenMathText <Control-c><Key-e> {doInvoke %W insert ; break} # ok - mark bind OpenMathText <Control-Key-space> { pushCommand %W SetAnchor "" %W mark set anchor insert } # #----------------------------------------------------------------- # # binding -- push the current selection on the killRing, and # if there is no selection, push the region between the anchor and # the point. # Results: # # Side Effects: # #---------------------------------------------------------------- # bind OpenMathText <Control-Key-w> { pushCommand %W OpenMathTextCut "" # in the first case the <<Cut>> event on Text will delete the selection. if { [catch { pushl [saveText %W sel.first sel.last] killRing } ] } { catch { set range [getRange %W anchor insert] pushl [eval saveText %W $range] killRing eval %W delete $range } } } proc openMathAnyKey { win keysym s } { # puts "$win `$keysym' `$s'" if { "$s" != "" } { pushCommand $win openMathAnyKey [list $win $keysym $s] } if { "$s" != "" && [doInsertp [$win tag names insert]] && ("$s" == "$keysym" || [regexp "\[\n\t \]" "$s" junk] )} { setModifiedFlag $win insert } } proc OpenMathYank {win level } { global maxima_priv #puts "doing OpenMathYank $win $level" if { $level == 0 } { set maxima_priv(currentwin) $win pushCommand $win OpenMathYank [list $win $level] set maxima_priv(point) insert $win mark set beforeyank insert $win mark gravity beforeyank left eval [peekl killRing "" ] } elseif { [catch { set last $maxima_priv(lastcom,$win) set m [lindex [lindex $last 1] 1] incr m if { "[lindex $last 0]" == "OpenMathYank" && \ "$maxima_priv(currentwin)" == "$win" && \ "$maxima_priv(point)" == "insert" } {set doit 1}} ] \ || $doit==0} { pushCommand $win Error "" } else { set res [peekl killRing _none_ [expr {$m + 1}]] if { "$res" == "_none_" } { # this will cause to cycle set m 0 } else { $win delete beforeyank insert eval $res } pushCommand $win OpenMathYank [list $win $m] } catch { $win see insert} } proc saveText { win args } { if {[catch {$win index [lindex $args 1 ]} endregion]} {return ""} set tags [ldelete sel [$win tag names]] set prev [lindex $args 0] if { "$prev" == "" } {set prev 0.0 } if { "$endregion" == "" } {set endregion end} set allar($prev) 1 set allar($endregion) 1 foreach v $tags { set ranges [tagRanges $win $v $prev $endregion] foreach {begin end} $ranges { lappend start($begin) $v lappend stop($end) $v set allar($begin) 1 set allar($end) 1 } } proc __comp { a b} " return \[$win compare \$a > \$b \] " set all [lsort -command __comp [array names allar]] set result "" foreach v $all { append result "Tins [list [array names currentTags]] [quoteBraces [$win get $prev $v]]\n" set prev $v if { [info exists start($v)] } { foreach u $start($v) { set currentTags($u) 1} } if { [info exists stop($v)] } { foreach u $stop($v) { unset currentTags($u) } } #puts -nonewline "..deleting{$stop($v)} giving {$currentTags}" # puts ">>" } return $result } proc openMathControlK { win } { global maxima_priv if { $maxima_priv(doublek) != 0 } { set now [popl killRing ""] } else { set now "" } set maxima_priv(doublek) 0 if { [$win compare insert == "insert lineend" ] } { if { [$win compare insert < end] } { append now "\nTins {[ldelete sel [$win tag names insert]]} {\n}" } } else { append now "\n[saveText $win insert {insert lineend}]" } pushl $now killRing } Index: Browser.tcl =================================================================== RCS file: /cvsroot/maxima/maxima/interfaces/xmaxima/Tkmaxima/Browser.tcl,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Browser.tcl 14 Sep 2002 17:25:34 -0000 1.10 +++ Browser.tcl 19 Sep 2002 16:15:28 -0000 1.11 @@ -2,16 +2,12 @@ # # $Id$ # -###### browser.tcl ###### +###### Browser.tcl ###### ############################################################ # Netmath Copyright (C) 1998 William F. Schelter # # For distribution under GNU public License. See COPYING. # ############################################################ -global MathServer -set MathServer "locahost 4443" - - ## source keyb.tcl ###### keyb.tcl ###### @@ -34,10 +30,6 @@ -global maxima_priv -set maxima_priv(sticky) "^Teval$|^program:" - - # #----------------------------------------------------------------- # @@ -62,7 +54,7 @@ # puts "before=$before" foreach v [concat $after $before] { - if { [regexp $maxima_priv(sticky) $v] } { + if { [regexp -- $maxima_priv(sticky) $v] } { lappend both $v } } @@ -85,190 +77,14 @@ } proc getRange { win a b } { - if { [$win compare $a < $b ] } { return "$a $b" } else { return "$b $a"} -} - - -# -#----------------------------------------------------------------- -# -# binding -- push the current selection on the killRing, and -# if there is no selection, push the region between the anchor and -# the point. -# Results: -# -# Side Effects: -# -#---------------------------------------------------------------- -# -bind OpenMathText <Control-Key-w> { - pushCommand %W OpenMathTextCut "" - # in the first case the <<Cut>> event on Text will delete the selection. - if { [catch { pushl [saveText %W sel.first sel.last] killRing } ] } { - catch { - set range [getRange %W anchor insert] - pushl [eval saveText %W $range] killRing - eval %W delete $range - } - } -} - - -global maxima_priv -if {0} { -if {! [info exists maxima_priv(bindings_added) ] } { - bind Text <Control-Key-k> "openMathControlK %W \n [bind Text <Control-Key-k>]" - bind Text <B3-Motion> [bind Text <B2-Motion>] - bind Text <Button-3> [bind Text <Button-2>] - - set maxima_priv(bindings_added) 1 -} -} -set maxima_priv(doublek) 0 - -bind OpenMathText <Control-Key-k><Control-Key-k> { - set maxima_priv(doublek) 1 -} - -proc openMathControlK { win } { - global maxima_priv - if { $maxima_priv(doublek) != 0 } { - set now [popl killRing ""] - } else { - set now "" - } - set maxima_priv(doublek) 0 - if { [$win compare insert == "insert lineend" ] } { - if { [$win compare insert < end] } { - append now "\nTins {[ldelete sel [$win tag names insert]]} {\n}" - } } else { - append now "\n[saveText $win insert {insert lineend}]" - } - pushl $now killRing -} - -bind OpenMathText <Control-Key-y> "OpenMathYank %W 0; break" -bind OpenMathText <Alt-Key-y> "OpenMathYank %W 1; break" -bind OpenMathText <Meta-Key-y> "OpenMathYank %W 1; break" - -proc OpenMathYank {win level } { - global maxima_priv - #puts "doing OpenMathYank $win $level" - if { $level == 0 } { - set maxima_priv(currentwin) $win - pushCommand $win OpenMathYank [list $win $level] - set maxima_priv(point) insert - $win mark set beforeyank insert - $win mark gravity beforeyank left - eval [peekl killRing "" ] - } else { - if { [catch { - set last $maxima_priv(lastcom,$win) - set m [lindex [lindex $last 1] 1] - incr m - if { "[lindex $last 0]" == "OpenMathYank" && - "$maxima_priv(currentwin)" == "$win" - && "$maxima_priv(point)" == "insert" } {set doit 1}} ] - || $doit==0} { - pushCommand $win Error "" } else { - - set res [peekl killRing _none_ [expr {$m + 1}]] - if { "$res" == "_none_" } { - # this will cause to cycle - set m 0 - } else { - $win delete beforeyank insert - eval $res - } - pushCommand $win OpenMathYank [list $win $m] - } - } - catch { $win see insert} -} - -# put the clipboard paste on Control-Shift-y -event add <<Paste>> <Control-Shift-y> - -bind OpenMathText <Alt-Key-w> { - pushCommand %W SaveSelection "" - if { "[selection own -displayof %W]" == "%W"} { - pushl [saveText %W sel.first sel.last] killRing - selection clear -displayof %W - } -} - -bind OpenMathText <Key> {openMathAnyKey %W %K %A} -bind OpenMathText <Alt-Key> {openMathAnyKey %W %K ALT_%A} - -# stop the double button click word selection in openMathText.. -bind OpenMathText <Double-Button-1> { break; } -bind OpenMathText <Control-c><Key-e> {doInvoke %W insert ; break; } - -bind OpenMathText <Control-Key-space> { - pushCommand %W SetAnchor "" - %W mark set anchor insert } - - -proc openMathAnyKey { win keysym s } { - # puts "$win `$keysym' `$s'" - if { "$s" != "" } { - pushCommand $win openMathAnyKey [list $win $keysym $s] - } - - if { "$s" != "" && [doInsertp [$win tag names insert]] - && ("$s" == "$keysym" || [regexp "\[\n\t \]" "$s" junk] )} { - setModifiedFlag $win insert - } -} - -proc saveText { win args } { - set tags [ldelete sel [$win tag names]] - set prev [lindex $args 0] - set endregion [$win index [lindex $args 1 ]] - if { "$prev" == "" } {set prev 0.0 } - if { "$endregion" == "" } {set endregion end} - set allar($prev) 1 - set allar($endregion) 1 - foreach v $tags { - set ranges [tagRanges $win $v $prev $endregion] - foreach {begin end} $ranges { - lappend start($begin) $v - lappend stop($end) $v - set allar($begin) 1 - set allar($end) 1 - - } - } - proc __comp { a b} " return \[$win compare \$a > \$b \] " - set all [lsort -command __comp [array names allar]] - set result "" - foreach v $all { - append result "Tins [list [array names currentTags]] [quoteBraces [$win get $prev $v]]\n" - set prev $v - - - if { [info exists start($v)] } { - - foreach u $start($v) { set currentTags($u) 1} - } - - if { [info exists stop($v)] } { - - foreach u $stop($v) { unset currentTags($u) } - } - - - - #puts -nonewline "..deleting{$stop($v)} giving {$currentTags}" - - # puts ">>" - + if { [$win compare $a < $b ] } { + return "$a $b" + } else { + return "$b $a" } - return $result } - # #----------------------------------------------------------------- # @@ -283,10 +99,11 @@ #---------------------------------------------------------------- # proc tagRanges { win tag begin end } { - if { [$win compare $begin <= 1.0 ] && - [$win compare $end >= end ] } { - return [$win tag ranges $tag ] } else { - set answer "" + if { [$win compare $begin <= 1.0 ] && \ + [$win compare $end >= end ] } { + return [$win tag ranges $tag ] + } else { + set answer "" set begin [$win index $begin] set end [$win index $end] if { [lsearch [$win tag names $begin] $tag ]>=0 } { @@ -319,8 +136,6 @@ } - - # #----------------------------------------------------------------- # @@ -409,9 +224,6 @@ -global maxima_priv -set maxima_priv(richTextCommands) {Tins TinsSlashEnd} - ## endsource keyb.tcl proc underTop {top win} { @@ -422,18 +234,24 @@ } } +# now unused proc showHistory { window } { set top [winfo toplevel $window] set win [omPanel $window] makeLocal $win history historyIndex + set w [underTop $top .historylist] - catch {destroy $w} + if {[winfo exists $w]} {catch {destroy $w}} + frame $w -borderwidth 2 -relief raised label $w.title -text "History List" -relief raised + pack $w.title -side top -fill x setHelp $w.title {This window may be dragged elsewhere by grabbing this title bar with the mouse. Double clicking on a history item, moves to that page.} - button $w.dismiss -command "destroy $w" -text dimsiss + + button $w.dismiss -command "destroy $w" -text Close + pack $w.dismiss -side bottom -fill x setHelp $w.dismiss {Remove the history list} - pack $w.title $w.dismiss -side top -expand 1 -fill x + scrollbar $w.scrolly -command "$w.list yview" scrollbar $w.scrollx -orient horizontal -command "$w.list xview" pack $w.scrollx -side bottom -fill x -expand 1 @@ -457,6 +275,7 @@ bind $w.title <1> "startDragPlacedWindow $w %X %Y" place $w -relx .4 -rely .8 -in $top + } proc deleteAllTraces {var} { @@ -464,6 +283,8 @@ uplevel "#0" trace vdelete $var [lindex $v 0] [list [lindex $v 1]] } } + +# now unused proc resetHistory { win list args } { set action [lindex $args 1] if { [catch { @@ -506,12 +327,14 @@ oset $win placeinfo [list $x $y $new] } +# now unused proc OpenMathMoveHistory { win n } { makeLocal $win history historyIndex incr historyIndex $n if { $historyIndex >= [llength $history] } { - set historyIndex [expr {[llength $history] -1}] } - if { $historyIndex <0 } { set historyIndex 0} + set historyIndex [expr {[llength $history] -1}] + } + if { $historyIndex < 0 } { set historyIndex 0} if { "[lindex $history $historyIndex]" != ""} { OpenMathGetWindow $win [lindex $history $historyIndex] oset $win historyIndex $historyIndex @@ -520,7 +343,7 @@ proc toLocalFilename { url } { set type [assoc type $url] - switch $type { + switch -- $type { http { return [assoc filename $url] } @@ -619,7 +442,7 @@ } proc encodeURL { lis } { set type [assoc type $lis ""] - switch $type { + switch -- $type { nmtp { if { [ set port [assoc port $lis 4443]] != 4443 } { append type "($port)" @@ -660,7 +483,7 @@ set ans $decode } else { foreach {x y } $current { - switch $x { + switch -- $x { dirname { set ndir [assoc dirname $decode ""] set cdir [assoc dirname $current ""] @@ -704,21 +527,12 @@ return $ans } -global maxima_priv -set maxima_priv(urlHandlers) { - text/html netmath - text/plain netmath - image/gif netmath - application/postscript "ghostview -safer %s" - application/pdf "acroread %s" - application/x-dvi "xdvi %s" -} - proc getURLrequest { path server port types {post ""} {meth ""} } { global maxima_priv - if { "$meth" != "" } {set method $meth } else { - + if { "$meth" != "" } { + set method $meth + } else { set method GET if { "$post" != "" } {set method POST} } @@ -758,13 +572,22 @@ #puts "getting $resolved,post=<$post>" switch [assoc type $res] { http { + #mike FIXME: replace with http get # puts $res # puts "socket [assoc server $res] [assoc port $res 80]" if { [info exists maxima_priv(proxy,http) ] } { set sock [eval socket $maxima_priv(proxy,http)] # puts "opening proxy request socket $maxima_priv(proxy,http)" } else { - set sock [socket [assoc server $res] [assoc port $res 80]] + set server [assoc server $res] + set port [assoc port $res 80] + #mike FIXME - use async sockets and dns + if {[catch {socket $server $port} sock]} { + global errorInfo + tide_failure [M "Error connecting to %s on %s\n%s" \ + $server $port $sock] + return + } } fconfigure $sock -blocking 0 @@ -796,7 +619,8 @@ set ans $maxima_priv(url_result) unset maxima_priv(url_result) return $ans - } else {return "had error" + } else { + return "had error" } } file { @@ -816,6 +640,7 @@ return $answer } default { + #mike dirpath? error "not supported [lindex $res 0]" } } @@ -843,11 +668,6 @@ } -global maxima_priv -set maxima_priv(imagecounter) 0 - -set maxima_priv(brokenimage,data) R0lGODlhHQAgAMIAAAAAAP9jMcbGxoSEhP///zExY/9jzgCEACH5BAEAAAIALAAAAAAdACAAAAPOOLrcLjDCQaq9+CoZaf7YIIicx50nNZYV6k4tCRPuYduSR8vmef+dy2rU4vyOM8uqJzkCBYCoNEqkGZ04SGHLBSiKTewhx/AyI+LxqWIGh5Eo9pdm8D3jhDa9/nrJTQaBfS5/LYGCgxyFe4cnAY+Qj1oFegKHjRKRkpMbgJeIEJqTBTyGnxybAlwbQYygKFusOaavo5SkJ5WYErELKAO6fBy4LxS6vFzEv4snpLIpIszIMiWKeXMWvS7RGXoVsX0g11NR1Bzk6F4jCn0ODgkAOwAA - proc backgroundGetImage { image res width height } { global maxima_priv #puts [list backgroundGetImage $image $res $width $height ] @@ -985,6 +805,7 @@ proc doRead { sock } { global maxima_priv + #puts reading; flush stdout; set tem [read $sock] append maxima_priv(url_result) $tem @@ -992,12 +813,14 @@ # flush stdout if { [eof $sock] } { set maxima_priv(done) 1 - close $sock} + close $sock + } } proc tes {} { OpenMathOpenUrl http://www.ma.utexas.edu/users/wfs/foo/t1.om } + proc tempName { name extension } { set count [pid] while { [file exists $name[incr count].$extension] } { list } @@ -1008,7 +831,10 @@ upvar 1 $string result set tmp [tempName $file $ext ] set open $tmp - if { [lsearch {x-gzip x-compress} $encoding] >= 0 } { lappend dogzip |gzip -dc > $open ; set open $dogzip} + if { [lsearch {x-gzip x-compress} $encoding] >= 0 } { + # FIXME: Unix only + lappend dogzip |gzip -dc > $open ; set open $dogzip + } set fi [open $open w] fconfigure $fi -translation binary puts -nonewline $fi $result @@ -1017,11 +843,6 @@ return $tmp } -global debugParse -if { ![info exists debugParse ] } { - set debugParse 0 -} - proc OpenMathOpenUrl { name args} { global maxima_priv @@ -1243,6 +1064,7 @@ return [lindex $maxima_default(defaultservers) 0] } +#mike FIXME: This is an abomination proc fileBaseprogram { textwin parent x y } { set e $textwin.e catch { destroy $e } @@ -1262,13 +1084,17 @@ proc fontDialog { top } { global maxima_default + set font [xHMmapFont font:propor:normal:r:3] - catch { destroy $top } + if {[winfo exists $top]} {catch { destroy $top }} + toplevel $top wm iconify $top + set win $top.text text $win -font [list [font config $font -family] [font config $font -size]] -height 20 wm deiconify $top + foreach fam {propor fixed} { set lis "" set i 0 @@ -1380,8 +1206,10 @@ proc mkLabelListBoxChooser { win items textvar} { button $win -textvariable $textvar -command "listBoxChoose $win [list $items] $textvar" } + proc listBoxChoose { win items textvar } { global maxima_default + set whei [winfo height $win] set items [eval $items] set hei [llength $items] |