diff options
author | krischan <krischan> | 2002-12-27 11:49:27 (GMT) |
---|---|---|
committer | krischan <krischan> | 2002-12-27 11:49:27 (GMT) |
commit | ee27ce1cac5d6042179f3e2e6a3931c6502da372 (patch) | |
tree | c32ee8bdd118ddc34449dab99bb7c724ae16629f | |
parent | 3b09ebfc951432b6abac4ca421d77b2601f8d903 (diff) | |
download | tktreectrl-ee27ce1cac5d6042179f3e2e6a3931c6502da372.zip tktreectrl-ee27ce1cac5d6042179f3e2e6a3931c6502da372.tar.gz tktreectrl-ee27ce1cac5d6042179f3e2e6a3931c6502da372.tar.bz2 |
Added tests of selection widget command.
-rw-r--r-- | doc/treectrl.n | 60 | ||||
-rw-r--r-- | tests/treectrl.test | 78 |
2 files changed, 136 insertions, 2 deletions
diff --git a/doc/treectrl.n b/doc/treectrl.n index aaf6bd1..6184101 100644 --- a/doc/treectrl.n +++ b/doc/treectrl.n @@ -7,7 +7,7 @@ '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" '\" -'\" $Id: treectrl.n,v 1.4 2002/12/26 15:52:02 krischan Exp $ +'\" $Id: treectrl.n,v 1.5 2002/12/27 11:49:27 krischan Exp $ '\" .so man.macros .TH treectrl n 8.4 Tk "Tk Commands" @@ -729,6 +729,64 @@ Returns a list containing the names of all user defined states. Removes this state from the list of user defined states. .RE .TP +\fIpathName \fBselection \fIoption arg\fR +This command is used to adjust the selection within a treectrl. +It has several forms, depending on \fIoption\fR: +.RS +.TP +\fIpathName \fBselection add \fIfirst\fR ?\fIlast\fR? +\fIFirst\fR and \fIlast\fR (if specified) +must be the string \fBall\fR or an \fIitemDesc\fR. +Selects all of the items in the range between +\fIfirst\fR and \fIlast\fR, inclusive, +without affecting the selection state of items outside that range. +If one of the arguments is the string \fBall\fR, +all items of the treectrl widget are added to the selection instead. +.TP +\fIpathName \fBselection anchor ?\fIitemDesc\fR? +If \fIitemDesc\fR is specified, +the selection anchor is set to the described item. +The selection anchor is the end of the selection that is fixed +while dragging out a selection with the mouse. +The item description \fBanchor\fR may be used to refer to the anchor item. +This command doesn't modify the selection state of any item. +Returns the numerical id of the selection anchor item. +.TP +\fIpathName \fBselection clear ?\fIfirst\fR? ?\fIlast\fR? +\fIFirst\fR and \fIlast\fR (if specified) +must be the string \fBall\fR or an \fIitemDesc\fR. +If any of the items between \fIfirst\fR and \fIlast\fR +(inclusive) are selected, they are deselected. +The selection state is not changed for items outside this range. +If no additional arguments is given +or one of the arguments is the string \fBall\fR, +the selection is completely cleared instead. +.TP +\fIpathName \fBselection count\fR +Returns an integer indicating the number +of items in the treectrl that are currently selected. +.TP +\fIpathName \fBselection get\fR +Returns a list containing the numerical ids of +all of the items in the treectrl that are currently selected. +If there are no items selected in the treectrl then an empty +string is returned. +.TP +\fIpathName \fBselection includes \fIitemDesc\fR +Returns 1 if the item indicated by \fIitemDesc\fR is currently +selected, 0 if it isn't. +.TP +\fIpathName \fBselection modify \fIselect deselect\fR +Both arguments \fIselect\fR and \fIdeselect\fR must be +the string \fBall\fR or a possibly empty list of \fIitemDesc\fRs. +Selects all of the items described by \fIselect\fR, +then deselects all items described by \fIdeselect\fR, +without affecting the selection state of any item +not mentioned in both arguments. +If one item is described in both arguments \fIselect\fR and \fIdeselect\fR, +it is added to the selection. +.RE +.TP \fIpathName \fBstyle \fIoption\fR ?\fIelement\fR? ?\fIarg arg ...\fR? This command is used to manipulate styles, which could be considered as a geometry manager for the elements of one item. diff --git a/tests/treectrl.test b/tests/treectrl.test index cf03397..1e45b70 100644 --- a/tests/treectrl.test +++ b/tests/treectrl.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: treectrl.test,v 1.4 2002/12/26 15:54:19 krischan Exp $ +# RCS: @(#) $Id: treectrl.test,v 1.5 2002/12/27 11:52:16 krischan Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -1514,6 +1514,82 @@ test tree-7.11 {marquee visible} -body { [.t marquee visible] } -result {{-visible {} {} 0 0} 1 1 0 0 {} 1} +test tree-8.1 {selection: missing args} -body { + .t selection +} -returnCodes error -result {wrong # args: should be ".t selection command ?arg arg...?"} + +test tree-8.2 {selection: unknown command} -body { + .t selection foo +} -returnCodes error -result {bad command "foo": must be add, anchor, clear, count, get, includes, or modify} + +test tree-8.3 {selection count/get: nothing selected yet} -body { + list [.t selection count] [.t selection get] +} -result {0 {}} + +test tree-8.4 {selection anchor: always defined} -body { + .t selection anchor +} -result {0} + +test tree-8.5 {selection anchor: modifies the anchor item} -body { + .t selection anchor "root lastchild" + .t index anchor +} -result {8} + +test tree-8.6 {selection count/get: still nothing selected} -body { + list [.t selection count] [.t selection get] +} -result {0 {}} + +test tree-8.7 {selection add: all children of an item} -body { + .t selection add "1 firstchild" "1 lastchild" + list [.t selection count] [.t selection get] +} -result {2 {2 3}} + +test tree-8.8 {selection add: all items and then some} -constraints knownBug -body { + .t selection add all "1 lastchild" + list [.t selection count] [.t selection get] +} -result {10 {0 1 2 3 4 5 6 7 8 12}} + +test tree-8.9 {selection clear} -body { + .t selection clear "root firstchild" + list [.t selection count] [.t selection get] +} -result {9 {0 2 3 4 5 6 7 8 12}} + +test tree-8.10 {selection clear: some items and then all} -constraints knownBug -body { + .t selection clear "root lastchild" all + list [.t selection count] [.t selection get] +} -result {0 {}} + +test tree-8.11 {selection modify: to be or not to be?} -body { + .t selection modify all all + list [.t selection count] [.t selection get] +} -result {10 {0 1 2 3 4 5 6 7 8 12}} + +test tree-8.12 {selection clear: totally empty} -body { + .t selection clear + list [.t selection count] [.t selection get] +} -result {0 {}} + +test tree-8.12 {selection modify: to be or not to be?} -body { + .t selection modify {{root firstchild} {root lastchild}} {{root lastchild}} + list [.t selection count] [.t selection get] +} -result {2 {1 8}} + +test tree-8.13 {selection includes: missing args} -body { + .t selection includes +} -returnCodes error -result {wrong # args: should be ".t selection includes index"} + +test tree-8.14 {selection includes: invalid item} -body { + .t selection includes {foo bar} +} -returnCodes error -result {bad item description "foo bar"} + +test tree-8.15 {selection includes: item is selected} -body { + .t selection includes {root child 2} +} -result {1} + +test tree-8.16 {selection includes: item is not selected} -body { + .t selection includes {root child 0 firstchild} +} -result {0} + # cleanup image delete emptyImg ::tcltest::cleanupTests |