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
|
#==============================================================================
# Contains the implementation of the tablelist::sortByColumn command.
#
# Copyright (c) 2000-2002 Csaba Nemethi (E-mail: csaba.nemethi@t-online.de)
#==============================================================================
#------------------------------------------------------------------------------
# tablelist::sortByColumn
#
# Sorts the contents of the tablelist widget win by its col'th column. Returns
# the sorting order (increasing or decreasing).
#------------------------------------------------------------------------------
proc tablelist::sortByColumn {win col} {
#
# Check the arguments
#
if {![winfo exists $win]} {
return -code error "bad window path name \"$win\""
}
if {[string compare [winfo class $win] Tablelist] != 0} {
return -code error "window \"$win\" is not a tablelist widget"
}
if {[catch {::$win columnindex $col} result] != 0} {
return -code error $result
}
if {$result < 0 || $result >= [::$win columncount]} {
return -code error "column index \"$col\" out of range"
}
#
# Determine the sorting order
#
set col $result
if {$col == [::$win sortcolumn] &&
[string compare [::$win sortorder] increasing] == 0} {
set sortOrder decreasing
} else {
set sortOrder increasing
}
#
# Sort the widget's contents based on the given column
#
if {[catch {::$win sortbycolumn $col -$sortOrder} result] == 0} {
return $sortOrder
} else {
return -code error $result
}
}
|