/usr/share/doc/tk-tile/examples/autocomplete.tcl is in tk-tile 0.8.2-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #
# autocomplete.tcl,v 1.1 2005/01/28 01:25:19 muonics Exp
#
# Demonstration of inline auto-completion for Tile combobox widgets.
#
# Usage:
#
# enableAutoComplete path ?presorted?
#
# path may be an individual window to enable auto-completion for only
# that window, or TCombobox to enable it for all comboboxes.
#
# By default, the values list is assumed to be pre-sorted to optimize
# the search. If it is not presorted, pass 0 in for the second arg,
# and the list will be sorted before the search at the cost of some
# overhead.
#
namespace eval tile::combobox {
namespace export enableAutocomplete
}
## enableAutocomplete
#
# Enable inline auto-completion for the specified combobox widget.
#
proc tile::combobox::enableAutocomplete { w {presorted 1} } {
bind $w <KeyPress> [namespace code [list DoAutoComplete %W %A $presorted]]
}
## DoAutoComplete
#
# Perform inline auto-completion of typed text in the combobox.
#
proc tile::combobox::DoAutoComplete { w s presorted } {
set old [$w get]
tile::entry::Insert $w $s
set new [$w get]
# Only auto-complete if the string length has changed due to insertion.
if {[string length $old] != [string length $new]} {
set values [$w cget -values]
if {!$presorted} {
set values [lsort -dictionary $values]
}
set match [lsearch -inline $values $new*]
if {[string length $match]} {
$w delete 0 end
$w insert end $match
$w selection range [string length $new] end
$w icursor [string length $new]
}
}
}
|