--- ray/src/util/getfile3.6.tcl 1994/10/27 15:56:10 2.1 +++ ray/src/util/getfile3.6.tcl 2003/02/22 02:07:30 2.10 @@ -1,8 +1,9 @@ -# SCCSid "$SunId$ LBL" +# RCSid: $Id: getfile3.6.tcl,v 2.10 2003/02/22 02:07:30 greg Exp $ # -# 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,19 +61,21 @@ proc getfile args { # get filename interactively # Create widgets catch {destroy $w} if $topwin { - toplevel $w -geometry 500x410 + toplevel $w -width 400 -height 410 wm title $w "File Picker" wm iconname $w "Files" - wm minsize $w 300 250 + wm minsize $w 400 300 } else { - frame $w -geometry 500x410 + 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 .0625 -rely .03125 -relwidth .15625 -relheight .0625 + place $w.dt -relx .025 -rely .03125 helplink $w.dt file directory intro button $w.ls -text List -command "update_dir $w" - place $w.ls -relx .0625 -rely .125 -relwidth .125 -relheight .0625 + place $w.ls -relx .025 -rely .125 -relwidth .15 -relheight .0625 helplink $w.ls file directory list entry $w.de -textvariable curdir -relief sunken place $w.de -relx .25 -rely .03125 -relwidth .6875 -relheight .0625 @@ -95,8 +103,7 @@ proc getfile args { # get filename interactively } else { bind $w.fm.fl "set_curfile $w" label $w.fl -text File: - place $w.fl -relx .10625 -rely .875 \ - -relwidth .10625 -relheight .0625 + place $w.fl -relx .10625 -rely .875 entry $w.fn -relief sunken -textvariable curfile place $w.fn -relx .25 -rely .875 \ -relwidth .6875 -relheight .0625 @@ -110,20 +117,20 @@ proc getfile args { # get filename interactively } if {$transient != [info exists sendproc]} { button $w.ok -text OK -command "destroy $w" - place $w.ok -relx .0625 -rely .28125 \ - -relwidth .125 -relheight .0625 + place $w.ok -relx .025 -rely .28125 \ + -relwidth .15 -relheight .0625 } if {$transient || [info exists sendproc]} { button $w.cancel -text Cancel \ -command "destroy $w; unset curdir" - place $w.cancel -relx .0625 -rely .375 \ - -relwidth .125 -relheight .0625 + place $w.cancel -relx .025 -rely .375 \ + -relwidth .15 -relheight .0625 } if [info exists viewproc] { button $w.vi -text View -state disabled \ -command "$viewproc \[$w.fm.fl get \[$w.fm.fl curselection\]\]" - place $w.vi -relx .0625 -rely .46875 \ - -relwidth .125 -relheight .0625 + place $w.vi -relx .025 -rely .46875 \ + -relwidth .15 -relheight .0625 bind $w.fm.fl "+chk_select $w" helplink $w.vi file file view } @@ -154,9 +161,10 @@ 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 {~}} if [catch {cd $curdir} curdir] { set oldcol [lindex [$w.de config -foreground] 4] $w.de config -foreground Red @@ -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