--- ray/src/util/getfile3.6.tcl 1994/10/28 17:17:18 2.4 +++ ray/src/util/getfile3.6.tcl 1995/07/24 13:31:22 2.9 @@ -1,8 +1,9 @@ # SCCSid "$SunId$ LBL" # -# Usage: getfile [-win w] [-perm] [-glob pattern] [-view proc] [-send proc] +# Usage: getfile [-win w] [-grab] [-perm] [-glob pattern] [-view proc] [-send proc] # # Create a dialog box (in window w if given) to get file name. +# If -grab option is given, then getfile does a local grab on its window. # Normally, a single file name and return as value. # If perm switch is given, keep window up for multiple file entries. # If pattern is given, start with list of all the specified files, @@ -19,8 +20,10 @@ proc getfile args { # get filename interactively # Set defaults set w .fpwin set topwin 1 + set dograb 0 set curdir . set curpat * + set curfile {} set transient 1 # Get options while {[llength $args]} { @@ -30,6 +33,9 @@ proc getfile args { # get filename interactively set topwin 0 set args [lreplace $args 1 1] } + -grab { + set dograb 1 + } -perm* { set transient 0 } @@ -55,14 +61,16 @@ proc getfile args { # get filename interactively # Create widgets catch {destroy $w} if $topwin { - toplevel $w -geometry 400x410 + toplevel $w -width 400 -height 410 wm title $w "File Picker" wm iconname $w "Files" wm minsize $w 400 300 } else { - frame $w -geometry 400x410 + frame $w -width 400 -height 410 pack $w } + if $dograb { grab $w } + $w configure -cursor top_left_arrow label $w.dt -text Directory: place $w.dt -relx .025 -rely .03125 helplink $w.dt file directory intro @@ -153,7 +161,7 @@ proc getfile args { # get filename interactively proc update_dir w { # Update working directory global curdir curpat - if {"$curpat" == ""} { + if {"$curpat" == {}} { set curpat * } if {"$curdir" == {}} {set curdir {~}} @@ -165,9 +173,15 @@ proc update_dir w { # Update working directory $w.de config -foreground $oldcol } set curdir [pwd] + set offset [expr [string length $curdir] - 32] + if {$offset > 0} { + $w.de view [expr $offset + \ + [string first / [string range $curdir $offset end]] \ + + 1] + } $w.fm.fl delete 0 end set ls ../ - foreach f [glob *] { + foreach f [glob -nocomplain *] { if [file isdirectory $f] { lappend ls $f/ } @@ -181,7 +195,7 @@ proc update_dir w { # Update working directory } -proc set_curfile {w {sp ""}} { # change current file selection +proc set_curfile {w {sp {}}} { # change current file selection global curdir curfile set f [$w.fm.fl get [$w.fm.fl curselection]] if [string match */ $f] { @@ -189,7 +203,7 @@ proc set_curfile {w {sp ""}} { # change current file update_dir $w } else { set curfile $f - if {"$sp" > ""} { + if {"$sp" != {}} { $sp $curdir/$curfile } } @@ -198,7 +212,7 @@ proc set_curfile {w {sp ""}} { # change current file proc chk_select w { # check if current selection is file set s [$w.fm.fl curselection] - if {"$s" > "" && [file isfile [$w.fm.fl get $s]]} { + if {"$s" != {} && [file isfile [$w.fm.fl get $s]]} { $w.vi configure -state normal } else { $w.vi configure -state disabled