3 # Implements the "Motif" style file selection dialog for the
4 # Unix platform. This implementation is used only if the
5 # "::tk_strictMotif" flag is set.
7 # RCS: @(#) $Id: xmfbox.tcl,v 1.25.2.3 2006/03/17 10:50:11 patthoyts Exp $
9 # Copyright (c) 1996 Sun Microsystems, Inc.
10 # Copyright (c) 1998-2000 Scriptics Corporation
12 # See the file "license.terms" for information on usage and redistribution
13 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 namespace eval ::tk::dialog {}
16 namespace eval ::tk::dialog::file {}
19 # ::tk::MotifFDialog --
21 # Implements a file dialog similar to the standard Motif file
25 # type "open" or "save"
26 # args Options parsed by the procedure.
29 # When -multiple is set to 0, this returns the absolute pathname
30 # of the selected file. (NOTE: This is not the same as a single
33 # When -multiple is set to > 0, this returns a Tcl list of absolute
34 # pathnames. The argument for -multiple is ignored, but for consistency
35 # with Windows it defines the maximum amount of memory to allocate for
36 # the returned filenames.
38 proc ::tk::MotifFDialog {type args
} {
40 set dataName __tk_filedialog
41 upvar ::tk::dialog::file::$dataName data
43 set w
[MotifFDialog_Create
$dataName $type $args]
45 # Set a grab and claim the focus too.
47 ::tk::SetFocusGrab $w $data(sEnt
)
48 $data(sEnt
) selection range
0 end
50 # Wait for the user to respond, then restore the focus and
51 # return the index of the selected button. Restore the focus
52 # before deleting the window, since otherwise the window manager
53 # may take the focus away so we can't redirect it. Finally,
54 # restore any grab that was in effect.
56 vwait ::tk::Priv(selectFilePath
)
57 set result
$Priv(selectFilePath
)
58 ::tk::RestoreFocusGrab $w $data(sEnt
) withdraw
63 # ::tk::MotifFDialog_Create --
65 # Creates the Motif file dialog (if it doesn't exist yet) and
66 # initialize the internal data structure associated with the
69 # This procedure is used by ::tk::MotifFDialog to create the
70 # dialog. It's also used by the test suite to test the Motif
71 # file dialog implementation. User code shouldn't call this
75 # dataName Name of the global "data" array for the file dialog.
76 # type "Save" or "Open"
77 # argList Options parsed by the procedure.
80 # Pathname of the file dialog.
82 proc ::tk::MotifFDialog_Create {dataName type argList
} {
83 upvar ::tk::dialog::file::$dataName data
85 MotifFDialog_Config
$dataName $type $argList
87 if {$data(-parent) eq
"."} {
90 set w
$data(-parent).
$dataName
93 # (re)create the dialog box if necessary
95 if {![winfo exists
$w]} {
96 MotifFDialog_BuildUI
$w
97 } elseif
{[winfo class
$w] ne
"TkMotifFDialog"} {
99 MotifFDialog_BuildUI
$w
101 set data
(fEnt
) $w.top.f1.ent
102 set data
(dList
) $w.top.f2.a.l
103 set data
(fList
) $w.top.f2.b.l
104 set data
(sEnt
) $w.top.f3.ent
105 set data
(okBtn
) $w.bot.ok
106 set data
(filterBtn
) $w.bot.filter
107 set data
(cancelBtn
) $w.bot.cancel
109 MotifFDialog_SetListMode
$w
111 # Dialog boxes should be transient with respect to their parent,
112 # so that they will always stay on top of their parent window. However,
113 # some window managers will create the window as withdrawn if the parent
114 # window is withdrawn or iconified. Combined with the grab we put on the
115 # window, this can hang the entire application. Therefore we only make
116 # the dialog transient if the parent is viewable.
118 if {[winfo viewable
[winfo toplevel $data(-parent)]] } {
119 wm transient
$w $data(-parent)
122 MotifFDialog_FileTypes
$w
123 MotifFDialog_Update
$w
125 # Withdraw the window, then update all the geometry information
126 # so we know how big it wants to be, then center the window in the
127 # display (Motif style) and de-iconify it.
130 wm title
$w $data(-title)
135 # ::tk::MotifFDialog_FileTypes --
137 # Checks the -filetypes option. If present this adds a list of radio-
138 # buttons to pick the file types from.
141 # w Pathname of the tk_get*File dialogue.
146 proc ::tk::MotifFDialog_FileTypes {w
} {
147 upvar ::tk::dialog::file::[winfo name
$w] data
149 set f
$w.top.f3.types
152 # No file types: use "*" as the filter and display no radio-buttons
153 if {$data(-filetypes) eq
""} {
158 # The filetypes radiobuttons
159 # set data(fileType) $data(-defaulttype)
162 MotifFDialog_SetFilter
$w [lindex $data(-filetypes) $data(fileType
)]
164 #don't produce radiobuttons for only one filetype
165 if {[llength $data(-filetypes)] == 1} {
171 if {$data(-filetypes) ne
""} {
172 foreach type
$data(-filetypes) {
173 set title
[lindex [lindex $type 0] 0]
174 set filter
[lindex $type 1]
175 radiobutton $f.b
$cnt \
177 -variable ::tk::dialog::file::[winfo name
$w](fileType
) \
179 -command "[list tk::MotifFDialog_SetFilter $w $type]"
180 pack $f.b
$cnt -side left
184 $f.b
$data(fileType
) invoke
186 pack $f -side bottom
-fill both
191 # This proc gets called whenever data(filter) is set
193 proc ::tk::MotifFDialog_SetFilter {w type
} {
194 upvar ::tk::dialog::file::[winfo name
$w] data
197 set data
(filter
) [lindex $type 1]
198 set Priv
(selectFileType
) [lindex [lindex $type 0] 0]
200 MotifFDialog_Update
$w
203 # ::tk::MotifFDialog_Config --
205 # Iterates over the optional arguments to determine the option
206 # values for the Motif file dialog; gives default values to
207 # unspecified options.
210 # dataName The name of the global variable in which
211 # data for the file dialog is stored.
212 # type "Save" or "Open"
213 # argList Options parsed by the procedure.
215 proc ::tk::MotifFDialog_Config {dataName type argList
} {
216 upvar ::tk::dialog::file::$dataName data
220 # 1: the configuration specs
223 {-defaultextension "" "" ""}
224 {-filetypes "" "" ""}
225 {-initialdir "" "" ""}
226 {-initialfile "" "" ""}
230 if { $type eq
"open" } {
231 lappend specs
{-multiple "" "" "0"}
234 set data
(-multiple) 0
235 # 2: default values depending on the type of the dialog
237 if {![info exists data
(selectPath
)]} {
238 # first time the dialog has been popped up
239 set data
(selectPath
) [pwd]
240 set data
(selectFile
) ""
243 # 3: parse the arguments
245 tclParseConfigSpec
::tk::dialog::file::$dataName $specs "" $argList
247 if {$data(-title) eq
""} {
248 if {$type eq
"open"} {
249 if {$data(-multiple) != 0} {
250 set data
(-title) "[mc {Open Multiple Files}]"
252 set data
(-title) [mc
"Open"]
255 set data
(-title) [mc
"Save As"]
259 # 4: set the default directory and selection according to the -initial
262 if {$data(-initialdir) ne
""} {
263 if {[file isdirectory
$data(-initialdir)]} {
264 set data
(selectPath
) [lindex [glob $data(-initialdir)] 0]
266 set data
(selectPath
) [pwd]
269 # Convert the initialdir to an absolute path name.
273 set data
(selectPath
) [pwd]
276 set data
(selectFile
) $data(-initialfile)
278 # 5. Parse the -filetypes option. It is not used by the motif
279 # file dialog, but we check for validity of the value to make sure
280 # the application code also runs fine with the TK file dialog.
282 set data
(-filetypes) [::tk::FDGetFileTypes $data(-filetypes)]
284 if {![info exists data
(filter
)]} {
287 if {![winfo exists
$data(-parent)]} {
288 error "bad window path name \"$data(-parent)\""
292 # ::tk::MotifFDialog_BuildUI --
294 # Builds the UI components of the Motif file dialog.
297 # w Pathname of the dialog to build.
302 proc ::tk::MotifFDialog_BuildUI {w
} {
303 set dataName
[lindex [split $w .
] end
]
304 upvar ::tk::dialog::file::$dataName data
306 # Create the dialog toplevel and internal frames.
308 toplevel $w -class TkMotifFDialog
309 set top
[frame $w.top
-relief raised
-bd 1]
310 set bot
[frame $w.bot
-relief raised
-bd 1]
312 pack $w.bot
-side bottom
-fill x
313 pack $w.top
-side top
-expand yes
-fill both
315 set f1
[frame $top.f1
]
316 set f2
[frame $top.f2
]
317 set f3
[frame $top.f3
]
319 pack $f1 -side top
-fill x
320 pack $f3 -side bottom
-fill x
321 pack $f2 -expand yes
-fill both
323 set f2a
[frame $f2.a
]
324 set f2b
[frame $f2.b
]
326 grid $f2a -row 0 -column 0 -rowspan 1 -columnspan 1 -padx 4 -pady 4 \
328 grid $f2b -row 0 -column 1 -rowspan 1 -columnspan 1 -padx 4 -pady 4 \
330 grid rowconfigure
$f2 0 -minsize 0 -weight 1
331 grid columnconfigure
$f2 0 -minsize 0 -weight 1
332 grid columnconfigure
$f2 1 -minsize 150 -weight 2
336 bind [::tk::AmpWidget label $f1.lab
-text [mc
"Fil&ter:"] -anchor w
] \
337 <<AltUnderlined
>> [list focus $f1.ent
]
339 pack $f1.lab
-side top
-fill x
-padx 6 -pady 4
340 pack $f1.ent
-side top
-fill x
-padx 4 -pady 0
341 set data
(fEnt
) $f1.ent
343 # The file and directory lists
345 set data
(dList
) [MotifFDialog_MakeSList
$w $f2a \
346 [mc
"&Directory:"] DList
]
347 set data
(fList
) [MotifFDialog_MakeSList
$w $f2b \
348 [mc
"Fi&les:"] FList
]
352 bind [::tk::AmpWidget label $f3.lab
-text [mc
"&Selection:"] -anchor w
] \
353 <<AltUnderlined
>> [list focus $f3.ent
]
355 pack $f3.lab
-side top
-fill x
-padx 6 -pady 0
356 pack $f3.ent
-side top
-fill x
-padx 4 -pady 4
357 set data
(sEnt
) $f3.ent
361 set maxWidth
[::tk::mcmaxamp &OK
&Filter
&Cancel
]
362 set maxWidth
[expr {$maxWidth<6?
6:$maxWidth}]
363 set data
(okBtn
) [::tk::AmpWidget button $bot.ok
-text [mc
"&OK"] \
365 -command [list tk::MotifFDialog_OkCmd $w]]
366 set data
(filterBtn
) [::tk::AmpWidget button $bot.filter
-text [mc
"&Filter"] \
368 -command [list tk::MotifFDialog_FilterCmd $w]]
369 set data
(cancelBtn
) [::tk::AmpWidget button $bot.cancel
-text [mc
"&Cancel"] \
371 -command [list tk::MotifFDialog_CancelCmd $w]]
373 pack $bot.ok
$bot.filter
$bot.cancel
-padx 10 -pady 10 -expand yes
\
376 # Create the bindings:
378 bind $w <Alt-Key
> [list ::tk::AltKeyInDialog $w %A
]
380 bind $data(fEnt
) <Return
> [list tk::MotifFDialog_ActivateFEnt $w]
381 bind $data(sEnt
) <Return
> [list tk::MotifFDialog_ActivateSEnt $w]
382 bind $w <Escape
> [list tk::MotifFDialog_CancelCmd $w]
383 bind $w.bot
<Destroy
> {set ::tk::Priv(selectFilePath
) {}}
385 wm protocol
$w WM_DELETE_WINDOW
[list tk::MotifFDialog_CancelCmd $w]
388 proc ::tk::MotifFDialog_SetListMode {w
} {
389 upvar ::tk::dialog::file::[winfo name
$w] data
391 if {$data(-multiple) != 0} {
392 set selectmode extended
394 set selectmode browse
397 $f.l configure
-selectmode $selectmode
400 # ::tk::MotifFDialog_MakeSList --
402 # Create a scrolled-listbox and set the keyboard accelerator
403 # bindings so that the list selection follows what the user
407 # w Pathname of the dialog box.
408 # f Frame widget inside which to create the scrolled
409 # listbox. This frame widget already exists.
410 # label The string to display on top of the listbox.
411 # under Sets the -under option of the label.
412 # cmdPrefix Specifies procedures to call when the listbox is
413 # browsed or activated.
415 proc ::tk::MotifFDialog_MakeSList {w f
label cmdPrefix
} {
416 bind [::tk::AmpWidget label $f.lab
-text $label -anchor w
] \
417 <<AltUnderlined
>> [list focus $f.l
]
418 listbox $f.l
-width 12 -height 5 -exportselection 0\
419 -xscrollcommand [list $f.h
set] -yscrollcommand [list $f.v
set]
420 scrollbar $f.v
-orient vertical
-takefocus 0 -command [list $f.l yview
]
421 scrollbar $f.h
-orient horizontal
-takefocus 0 -command [list $f.l xview
]
422 grid $f.lab
-row 0 -column 0 -sticky news
-rowspan 1 -columnspan 2 \
424 grid $f.l
-row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
425 grid $f.v
-row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news
426 grid $f.h
-row 2 -column 0 -rowspan 1 -columnspan 1 -sticky news
428 grid rowconfigure
$f 0 -weight 0 -minsize 0
429 grid rowconfigure
$f 1 -weight 1 -minsize 0
430 grid columnconfigure
$f 0 -weight 1 -minsize 0
432 # bindings for the listboxes
435 bind $list <<ListboxSelect
>> [list tk::MotifFDialog_Browse$cmdPrefix $w]
436 bind $list <Double-ButtonRelease-1
> \
437 [list tk::MotifFDialog_Activate$cmdPrefix $w]
438 bind $list <Return
> "tk::MotifFDialog_Browse$cmdPrefix [list $w]; \
439 tk::MotifFDialog_Activate$cmdPrefix [list $w]"
441 bindtags $list [list Listbox
$list [winfo toplevel $list] all
]
442 ListBoxKeyAccel_Set
$list
447 # ::tk::MotifFDialog_InterpFilter --
449 # Interpret the string in the filter entry into two components:
450 # the directory and the pattern. If the string is a relative
451 # pathname, give a warning to the user and restore the pattern
455 # w pathname of the dialog box.
458 # A list of two elements. The first element is the directory
459 # specified # by the filter. The second element is the filter
462 proc ::tk::MotifFDialog_InterpFilter {w
} {
463 upvar ::tk::dialog::file::[winfo name
$w] data
465 set text [string trim
[$data(fEnt
) get
]]
467 # Perform tilde substitution
470 if {[string index
$text 0] eq
"~"} {
471 set list [file split $text]
472 set tilde
[lindex $list 0]
473 if {[catch {set tilde
[glob $tilde]}]} {
476 set text [eval file join [concat $tilde [lrange $list 1 end
]]]
480 # If the string is a relative pathname, combine it
481 # with the current selectPath.
484 if {[file pathtype
$text] eq
"relative"} {
486 } elseif
{$badTilde} {
491 tk_messageBox -icon warning
-type ok
\
492 -message "\"$text\" must be an absolute pathname"
494 $data(fEnt
) delete
0 end
495 $data(fEnt
) insert
0 [::tk::dialog::file::JoinFile $data(selectPath
) \
498 return [list $data(selectPath
) $data(filter
)]
501 set resolved
[::tk::dialog::file::JoinFile [file dirname
$text] [file tail
$text]]
503 if {[file isdirectory
$resolved]} {
505 set fil
$data(filter
)
507 set dir
[file dirname
$resolved]
508 set fil
[file tail
$resolved]
511 return [list $dir $fil]
514 # ::tk::MotifFDialog_Update
516 # Load the files and synchronize the "filter" and "selection" fields
520 # w pathname of the dialog box.
525 proc ::tk::MotifFDialog_Update {w
} {
526 upvar ::tk::dialog::file::[winfo name
$w] data
528 $data(fEnt
) delete
0 end
529 $data(fEnt
) insert
0 \
530 [::tk::dialog::file::JoinFile $data(selectPath
) $data(filter
)]
531 $data(sEnt
) delete
0 end
532 $data(sEnt
) insert
0 [::tk::dialog::file::JoinFile $data(selectPath
) \
535 MotifFDialog_LoadFiles
$w
538 # ::tk::MotifFDialog_LoadFiles --
540 # Loads the files and directories into the two listboxes according
541 # to the filter setting.
544 # w pathname of the dialog box.
549 proc ::tk::MotifFDialog_LoadFiles {w
} {
550 upvar ::tk::dialog::file::[winfo name
$w] data
552 $data(dList
) delete
0 end
553 $data(fList
) delete
0 end
556 if {[catch {cd $data(selectPath
)}]} {
559 $data(dList
) insert end
".."
563 # Make the dir and file lists
565 # For speed we only have one glob, which reduces the file system
566 # calls (good for slow NFS networks).
568 # We also do two smaller sorts (files + dirs) instead of one large sort,
569 # which gives a small speed increase.
574 foreach f
[glob -nocomplain .
* *] {
575 if {[file isdir .
/$f]} {
578 foreach pat
$data(filter
) {
579 if {[string match
$pat $f]} {
580 if {[string match .
* $f]} {
589 eval [list $data(dList
) insert end
] [lsort -dictionary $dlist]
590 eval [list $data(fList
) insert end
] [lsort -dictionary $flist]
592 # The user probably doesn't want to see the . files. We adjust the view
593 # so that the listbox displays all the non-dot files
594 $data(fList
) yview
$top
599 # ::tk::MotifFDialog_BrowseDList --
601 # This procedure is called when the directory list is browsed
602 # (clicked-over) by the user.
605 # w The pathname of the dialog box.
610 proc ::tk::MotifFDialog_BrowseDList {w
} {
611 upvar ::tk::dialog::file::[winfo name
$w] data
614 if {[$data(dList
) curselection
] eq
""} {
617 set subdir
[$data(dList
) get
[$data(dList
) curselection
]]
622 $data(fList
) selection clear
0 end
624 set list [MotifFDialog_InterpFilter
$w]
625 set data
(filter
) [lindex $list 1]
629 set newSpec
[::tk::dialog::file::JoinFile $data(selectPath
) $data(filter
)]
632 set newSpec
[::tk::dialog::file::JoinFile [file dirname
$data(selectPath
)] \
636 set newSpec
[::tk::dialog::file::JoinFile [::tk::dialog::file::JoinFile \
637 $data(selectPath
) $subdir] $data(filter
)]
641 $data(fEnt
) delete
0 end
642 $data(fEnt
) insert
0 $newSpec
645 # ::tk::MotifFDialog_ActivateDList --
647 # This procedure is called when the directory list is activated
648 # (double-clicked) by the user.
651 # w The pathname of the dialog box.
656 proc ::tk::MotifFDialog_ActivateDList {w
} {
657 upvar ::tk::dialog::file::[winfo name
$w] data
659 if {[$data(dList
) curselection
] eq
""} {
662 set subdir
[$data(dList
) get
[$data(dList
) curselection
]]
667 $data(fList
) selection clear
0 end
671 set newDir
$data(selectPath
)
674 set newDir
[file dirname
$data(selectPath
)]
677 set newDir
[::tk::dialog::file::JoinFile $data(selectPath
) $subdir]
681 set data
(selectPath
) $newDir
682 MotifFDialog_Update
$w
684 if {$subdir ne
".."} {
685 $data(dList
) selection set 0
686 $data(dList
) activate
0
688 $data(dList
) selection set 1
689 $data(dList
) activate
1
693 # ::tk::MotifFDialog_BrowseFList --
695 # This procedure is called when the file list is browsed
696 # (clicked-over) by the user.
699 # w The pathname of the dialog box.
704 proc ::tk::MotifFDialog_BrowseFList {w
} {
705 upvar ::tk::dialog::file::[winfo name
$w] data
708 set data
(selectFile
) ""
709 foreach item
[$data(fList
) curselection
] {
710 lappend data
(selectFile
) [$data(fList
) get
$item]
712 if {[llength $data(selectFile
)] == 0} {
716 $data(dList
) selection clear
0 end
718 $data(fEnt
) delete
0 end
719 $data(fEnt
) insert
0 [::tk::dialog::file::JoinFile $data(selectPath
) \
721 $data(fEnt
) xview end
723 # if it's a multiple selection box, just put in the filenames
724 # otherwise put in the full path as usual
725 $data(sEnt
) delete
0 end
726 if {$data(-multiple) != 0} {
727 $data(sEnt
) insert
0 $data(selectFile
)
729 $data(sEnt
) insert
0 [::tk::dialog::file::JoinFile $data(selectPath
) \
730 [lindex $data(selectFile
) 0]]
732 $data(sEnt
) xview end
735 # ::tk::MotifFDialog_ActivateFList --
737 # This procedure is called when the file list is activated
738 # (double-clicked) by the user.
741 # w The pathname of the dialog box.
746 proc ::tk::MotifFDialog_ActivateFList {w
} {
747 upvar ::tk::dialog::file::[winfo name
$w] data
749 if {[$data(fList
) curselection
] eq
""} {
752 set data
(selectFile
) [$data(fList
) get
[$data(fList
) curselection
]]
753 if {$data(selectFile
) eq
""} {
756 MotifFDialog_ActivateSEnt
$w
760 # ::tk::MotifFDialog_ActivateFEnt --
762 # This procedure is called when the user presses Return inside
763 # the "filter" entry. It updates the dialog according to the
764 # text inside the filter entry.
767 # w The pathname of the dialog box.
772 proc ::tk::MotifFDialog_ActivateFEnt {w
} {
773 upvar ::tk::dialog::file::[winfo name
$w] data
775 set list [MotifFDialog_InterpFilter
$w]
776 set data
(selectPath
) [lindex $list 0]
777 set data
(filter
) [lindex $list 1]
779 MotifFDialog_Update
$w
782 # ::tk::MotifFDialog_ActivateSEnt --
784 # This procedure is called when the user presses Return inside
785 # the "selection" entry. It sets the ::tk::Priv(selectFilePath)
786 # variable so that the vwait loop in tk::MotifFDialog will be
790 # w The pathname of the dialog box.
795 proc ::tk::MotifFDialog_ActivateSEnt {w
} {
797 upvar ::tk::dialog::file::[winfo name
$w] data
799 set selectFilePath
[string trim
[$data(sEnt
) get
]]
801 if {$selectFilePath eq
""} {
802 MotifFDialog_FilterCmd
$w
806 if {$data(-multiple) == 0} {
807 set selectFilePath
[list $selectFilePath]
810 if {[file isdirectory
[lindex $selectFilePath 0]]} {
811 set data
(selectPath
) [lindex [glob $selectFilePath] 0]
812 set data
(selectFile
) ""
813 MotifFDialog_Update
$w
818 foreach item
$selectFilePath {
819 if {[file pathtype
$item] ne
"absolute"} {
820 set item
[file join $data(selectPath
) $item]
821 } elseif
{![file exists
[file dirname
$item]]} {
822 tk_messageBox -icon warning
-type ok
\
823 -message [mc
{Directory
"%1$s" does not exist.
} \
824 [file dirname
$item]]
828 if {![file exists
$item]} {
829 if {$data(type
) eq
"open"} {
830 tk_messageBox -icon warning
-type ok
\
831 -message [mc
{File
"%1$s" does not exist.
} $item]
835 if {$data(type
) eq
"save"} {
836 set message [format %s
%s
\
837 [mc
"File \"%1\$s\" already exists.\n\n" \
839 [mc
{Replace existing
file?
}]]
840 set answer
[tk_messageBox -icon warning
-type yesno
\
842 if {$answer eq
"no"} {
848 lappend newFileList
$item
851 if {$data(-multiple) != 0} {
852 set Priv
(selectFilePath
) $newFileList
854 set Priv
(selectFilePath
) [lindex $newFileList 0]
857 # Set selectFile and selectPath to first item in list
858 set Priv
(selectFile
) [file tail
[lindex $newFileList 0]]
859 set Priv
(selectPath
) [file dirname
[lindex $newFileList 0]]
863 proc ::tk::MotifFDialog_OkCmd {w
} {
864 upvar ::tk::dialog::file::[winfo name
$w] data
866 MotifFDialog_ActivateSEnt
$w
869 proc ::tk::MotifFDialog_FilterCmd {w
} {
870 upvar ::tk::dialog::file::[winfo name
$w] data
872 MotifFDialog_ActivateFEnt
$w
875 proc ::tk::MotifFDialog_CancelCmd {w
} {
878 set Priv
(selectFilePath
) ""
879 set Priv
(selectFile
) ""
880 set Priv
(selectPath
) ""
883 proc ::tk::ListBoxKeyAccel_Set {w
} {
884 bind Listbox
<Any-KeyPress
> ""
885 bind $w <Destroy
> [list tk::ListBoxKeyAccel_Unset $w]
886 bind $w <Any-KeyPress
> [list tk::ListBoxKeyAccel_Key $w %A
]
889 proc ::tk::ListBoxKeyAccel_Unset {w
} {
892 catch {after cancel
$Priv(lbAccel
,$w,afterId
)}
893 unset -nocomplain Priv
(lbAccel
,$w) Priv
(lbAccel
,$w,afterId
)
896 # ::tk::ListBoxKeyAccel_Key--
898 # This procedure maintains a list of recently entered keystrokes
899 # over a listbox widget. It arranges an idle event to move the
900 # selection of the listbox to the entry that begins with the
904 # w The pathname of the listbox.
905 # key The key which the user just pressed.
910 proc ::tk::ListBoxKeyAccel_Key {w key
} {
916 append Priv
(lbAccel
,$w) $key
917 ListBoxKeyAccel_Goto
$w $Priv(lbAccel
,$w)
919 after cancel
$Priv(lbAccel
,$w,afterId
)
921 set Priv
(lbAccel
,$w,afterId
) [after 500 \
922 [list tk::ListBoxKeyAccel_Reset $w]]
925 proc ::tk::ListBoxKeyAccel_Goto {w
string} {
928 set string [string tolower
$string]
929 set end
[$w index end
]
932 for {set i
0} {$i < $end} {incr i
} {
933 set item
[string tolower
[$w get
$i]]
934 if {[string compare
$string $item] >= 0} {
937 if {[string compare
$string $item] <= 0} {
943 if {$theIndex >= 0} {
944 $w selection clear
0 end
945 $w selection set $theIndex $theIndex
946 $w activate
$theIndex
948 event generate
$w <<ListboxSelect
>>
952 proc ::tk::ListBoxKeyAccel_Reset {w
} {
955 unset -nocomplain Priv
(lbAccel
,$w)
958 proc ::tk_getFileType {} {
961 return $Priv(selectFileType
)