1 |
< |
# SCCSid "$SunId$ LBL" |
1 |
> |
# RCSid: $Id$ |
2 |
|
# |
3 |
< |
# Usage: getfile [-win w] [-perm] [-glob pattern] [-view proc] [-send proc] |
3 |
> |
# Usage: getfile [-win w] [-grab] [-perm] [-glob pattern] [-view proc] [-send proc] |
4 |
|
# |
5 |
|
# Create a dialog box (in window w if given) to get file name. |
6 |
+ |
# If -grab option is given, then getfile does a local grab on its window. |
7 |
|
# Normally, a single file name and return as value. |
8 |
|
# If perm switch is given, keep window up for multiple file entries. |
9 |
|
# If pattern is given, start with list of all the specified files, |
20 |
|
# Set defaults |
21 |
|
set w .fpwin |
22 |
|
set topwin 1 |
23 |
+ |
set dograb 0 |
24 |
|
set curdir . |
25 |
|
set curpat * |
26 |
+ |
set curfile {} |
27 |
|
set transient 1 |
28 |
|
# Get options |
29 |
|
while {[llength $args]} { |
33 |
|
set topwin 0 |
34 |
|
set args [lreplace $args 1 1] |
35 |
|
} |
36 |
+ |
-grab { |
37 |
+ |
set dograb 1 |
38 |
+ |
} |
39 |
|
-perm* { |
40 |
|
set transient 0 |
41 |
|
} |
61 |
|
# Create widgets |
62 |
|
catch {destroy $w} |
63 |
|
if $topwin { |
64 |
< |
toplevel $w -geometry 400x410 |
64 |
> |
toplevel $w -width 400 -height 410 |
65 |
|
wm title $w "File Picker" |
66 |
|
wm iconname $w "Files" |
67 |
|
wm minsize $w 400 300 |
68 |
|
} else { |
69 |
< |
frame $w -geometry 400x410 |
69 |
> |
frame $w -width 400 -height 410 |
70 |
|
pack $w |
71 |
|
} |
72 |
+ |
if $dograb { grab $w } |
73 |
+ |
$w configure -cursor top_left_arrow |
74 |
|
label $w.dt -text Directory: |
75 |
|
place $w.dt -relx .025 -rely .03125 |
76 |
|
helplink $w.dt file directory intro |
161 |
|
|
162 |
|
proc update_dir w { # Update working directory |
163 |
|
global curdir curpat |
164 |
< |
if {"$curpat" == ""} { |
164 |
> |
if {"$curpat" == {}} { |
165 |
|
set curpat * |
166 |
|
} |
167 |
|
if {"$curdir" == {}} {set curdir {~}} |
173 |
|
$w.de config -foreground $oldcol |
174 |
|
} |
175 |
|
set curdir [pwd] |
176 |
+ |
set offset [expr [string length $curdir] - 32] |
177 |
+ |
if {$offset > 0} { |
178 |
+ |
$w.de view [expr $offset + \ |
179 |
+ |
[string first / [string range $curdir $offset end]] \ |
180 |
+ |
+ 1] |
181 |
+ |
} |
182 |
|
$w.fm.fl delete 0 end |
183 |
|
set ls ../ |
184 |
< |
foreach f [glob *] { |
184 |
> |
foreach f [glob -nocomplain *] { |
185 |
|
if [file isdirectory $f] { |
186 |
|
lappend ls $f/ |
187 |
|
} |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
< |
proc set_curfile {w {sp ""}} { # change current file selection |
198 |
> |
proc set_curfile {w {sp {}}} { # change current file selection |
199 |
|
global curdir curfile |
200 |
|
set f [$w.fm.fl get [$w.fm.fl curselection]] |
201 |
|
if [string match */ $f] { |
203 |
|
update_dir $w |
204 |
|
} else { |
205 |
|
set curfile $f |
206 |
< |
if {"$sp" > ""} { |
206 |
> |
if {"$sp" != {}} { |
207 |
|
$sp $curdir/$curfile |
208 |
|
} |
209 |
|
} |
212 |
|
|
213 |
|
proc chk_select w { # check if current selection is file |
214 |
|
set s [$w.fm.fl curselection] |
215 |
< |
if {"$s" > "" && [file isfile [$w.fm.fl get $s]]} { |
215 |
> |
if {"$s" != {} && [file isfile [$w.fm.fl get $s]]} { |
216 |
|
$w.vi configure -state normal |
217 |
|
} else { |
218 |
|
$w.vi configure -state disabled |