diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/tk.tcl | 9 | ||||
-rw-r--r-- | library/tkfbox.tcl | 117 | ||||
-rw-r--r-- | library/ttk/entry.tcl | 2 | ||||
-rw-r--r-- | library/ttk/treeview.tcl | 2 |
4 files changed, 66 insertions, 64 deletions
diff --git a/library/tk.tcl b/library/tk.tcl index 7ef25ec..cac9075 100644 --- a/library/tk.tcl +++ b/library/tk.tcl @@ -391,6 +391,7 @@ switch -exact -- [tk windowingsystem] { event add <<NextPara>> <Control-Down> event add <<SelectPrevPara>> <Control-Shift-Up> event add <<SelectPrevPara>> <Control-Shift-Down> + event add <<ToggleSelection>> <Control-ButtonPress-1> # Some OS's define a goofy (as in, not <Shift-Tab>) keysym that is # returned when the user presses <Shift-Tab>. In order for tab @@ -417,7 +418,7 @@ switch -exact -- [tk windowingsystem] { event add <<Redo>> <Control-Key-y> <Control-Lock-Key-Y> event add <<ContextMenu>> <Button-3> - event add <<SelectAll>> <Control-Key-slash> + event add <<SelectAll>> <Control-Key-slash> <Control-Key-a> <Control-Lock-Key-A> event add <<SelectNone>> <Control-Key-backslash> event add <<NextChar>> <Right> event add <<SelectNextChar>> <Shift-Right> @@ -427,9 +428,9 @@ switch -exact -- [tk windowingsystem] { event add <<SelectNextWord>> <Control-Shift-Right> event add <<PrevWord>> <Control-Left> event add <<SelectPrevWord>> <Control-Shift-Left> - event add <<LineStart>> <Home> <Control-Key-a> <Control-Lock-Key-A> + event add <<LineStart>> <Home> event add <<SelectLineStart>> <Shift-Home> - event add <<LineEnd>> <End> <Control-Key-e> <Control-Lock-Key-E> + event add <<LineEnd>> <End> event add <<SelectLineEnd>> <Shift-End> event add <<PrevLine>> <Up> event add <<NextLine>> <Down> @@ -439,6 +440,7 @@ switch -exact -- [tk windowingsystem] { event add <<NextPara>> <Control-Down> event add <<SelectPrevPara>> <Control-Shift-Up> event add <<SelectPrevPara>> <Control-Shift-Down> + event add <<ToggleSelection>> <Control-ButtonPress-1> } "aqua" { event add <<Cut>> <Command-Key-x> <Key-F2> <Control-Lock-Key-X> @@ -476,6 +478,7 @@ switch -exact -- [tk windowingsystem] { event add <<NextPara>> <Option-Down> event add <<SelectPrevPara>> <Shift-Option-Up> event add <<SelectPrevPara>> <Shift-Option-Down> + event add <<ToggleSelection>> <Command-ButtonPress-1> } } diff --git a/library/tkfbox.tcl b/library/tkfbox.tcl index ff79df8..ae16939 100644 --- a/library/tkfbox.tcl +++ b/library/tkfbox.tcl @@ -588,38 +588,15 @@ proc ::tk::dialog::file::Update {w} { set showHidden $showHiddenVar - # Make the dir list - # Using -directory [pwd] is better in some VFS cases. - set cmd [list glob -tails -directory [pwd] -type d -nocomplain *] - if {$showHidden} { - lappend cmd .* - } - set dirs [lsort -dictionary -unique [{*}$cmd]] - set dirList {} - foreach d $dirs { - if {$d eq "." || $d eq ".."} { - continue - } - lappend dirList $d - } - $data(icons) add $folder $dirList + # Make the dir list. Note that using an explicit [pwd] (instead of '.') is + # better in some VFS cases. + $data(icons) add $folder [GlobFiltered [pwd] d 1] if {$class eq "TkFDialog"} { # Make the file list if this is a File Dialog, selecting all but # 'd'irectory type files. # - set cmd [list glob -tails -directory [pwd] \ - -type {f b c l p s} -nocomplain] - if {$data(filter) eq "*"} { - lappend cmd * - if {$showHidden} { - lappend cmd .* - } - } else { - lappend cmd {*}$data(filter) - } - set fileList [lsort -dictionary -unique [{*}$cmd]] - $data(icons) add $file $fileList + $data(icons) add $file [GlobFiltered [pwd] {f b c l p s}] } # Update the Directory: option menu @@ -1148,50 +1125,72 @@ proc ::tk::dialog::file::Done {w {selectFilePath ""}} { set Priv(selectFilePath) $selectFilePath } +# ::tk::dialog::file::GlobFiltered -- +# +# Gets called to do globbing, returning the results and filtering them +# according to the current filter (and removing the entries for '.' and +# '..' which are never shown). Deals with evil cases such as where the +# user is supplying a filter which is an invalid list or where it has an +# unbalanced brace. The resulting list will be dictionary sorted. +# +# Arguments: +# dir Which directory to search +# type List of filetypes to look for ('d' or 'f b c l p s') +# overrideFilter Whether to ignore the filter for this search. +# +# NB: Assumes that the caller has mapped the state variable to 'data'. +# +proc ::tk::dialog::file::GlobFiltered {dir type {overrideFilter 0}} { + variable showHiddenVar + upvar 1 data(filter) filter + + if {$filter eq "*" || $overrideFilter} { + set patterns [list *] + if {$showHiddenVar} { + lappend patterns .* + } + } elseif {[string is list $filter]} { + set patterns $filter + } else { + # Invalid list; assume we can use non-whitespace sequences as words + set patterns [regexp -inline -all {\S+} $filter] + } + + set opts [list -tails -directory $dir -type $type -nocomplain] + + set result {} + catch { + # We have a catch because we might have a really bad pattern (e.g., + # with an unbalanced brace); even [glob -nocomplain] doesn't like it. + # Using a catch ensures that it just means we match nothing instead of + # throwing a nasty error at the user... + foreach f [glob {*}$opts -- {*}$patterns] { + if {$f eq "." || $f eq ".."} { + continue + } + lappend result $f + } + } + return [lsort -dictionary -unique $result] +} + proc ::tk::dialog::file::CompleteEnt {w} { variable showHiddenVar upvar ::tk::dialog::file::[winfo name $w] data set f [$data(ent) get] if {$data(-multiple)} { - if {[catch {llength $f} len] || $len != 1} { + if {![string is list $f] || [llength $f] != 1} { return -code break } set f [lindex $f 0] } # Get list of matching filenames and dirnames - set globF [list glob -tails -directory $data(selectPath) \ - -type {f b c l p s} -nocomplain] - set globD [list glob -tails -directory $data(selectPath) -type d \ - -nocomplain *] - if {$data(filter) eq "*"} { - lappend globF * - if {$showHiddenVar} { - lappend globF .* - lappend globD .* - } - if {[winfo class $w] eq "TkFDialog"} { - set files [lsort -dictionary -unique [{*}$globF]] - } else { - set files {} - } - set dirs [lsort -dictionary -unique [{*}$globD]] - } else { - if {$showHiddenVar} { - lappend globD .* - } - if {[winfo class $w] eq "TkFDialog"} { - set files [lsort -dictionary -unique [{*}$globF {*}$data(filter)]] - } else { - set files {} - } - set dirs [lsort -dictionary -unique [{*}$globD]] - } - # Filter specials - set dirs [lsearch -all -not -exact -inline $dirs .] - set dirs [lsearch -all -not -exact -inline $dirs ..] + set files [if {[winfo class $w] eq "TkFDialog"} { + GlobFiltered $data(selectPath) {f b c l p s} + }] set dirs2 {} - foreach d $dirs {lappend dirs2 $d/} + foreach d [GlobFiltered $data(selectPath) d] {lappend dirs2 $d/} set targets [concat \ [lsearch -glob -all -inline $files $f*] \ diff --git a/library/ttk/entry.tcl b/library/ttk/entry.tcl index 22c4115..f5ba19e 100644 --- a/library/ttk/entry.tcl +++ b/library/ttk/entry.tcl @@ -78,7 +78,7 @@ bind TEntry <B1-Leave> { ttk::Repeatedly ttk::entry::AutoScroll %W } bind TEntry <B1-Enter> { ttk::CancelRepeat } bind TEntry <ButtonRelease-1> { ttk::CancelRepeat } -bind TEntry <Control-ButtonPress-1> { +bind TEntry <<ToggleSelection>> { %W instate {!readonly !disabled} { %W icursor @%x ; focus %W } } diff --git a/library/ttk/treeview.tcl b/library/ttk/treeview.tcl index 1160e9b..8772587 100644 --- a/library/ttk/treeview.tcl +++ b/library/ttk/treeview.tcl @@ -43,7 +43,7 @@ bind Treeview <KeyPress-space> { ttk::treeview::ToggleFocus %W } bind Treeview <Shift-ButtonPress-1> \ { ttk::treeview::Select %W %x %y extend } -bind Treeview <Control-ButtonPress-1> \ +bind Treeview <<ToggleSelection>> \ { ttk::treeview::Select %W %x %y toggle } ttk::copyBindings TtkScrollable Treeview |