diff options
-rw-r--r-- | doc/ttk_treeview.n | 16 | ||||
-rw-r--r-- | generic/ttk/ttkTagSet.c | 11 | ||||
-rw-r--r-- | generic/ttk/ttkTreeview.c | 38 | ||||
-rw-r--r-- | generic/ttk/ttkWidget.h | 2 | ||||
-rw-r--r-- | tests/ttk/treetags.test | 11 |
5 files changed, 67 insertions, 11 deletions
diff --git a/doc/ttk_treeview.n b/doc/ttk_treeview.n index bcd995b..a126dd2 100644 --- a/doc/ttk_treeview.n +++ b/doc/ttk_treeview.n @@ -344,6 +344,11 @@ Modify or query the widget state; see \fIttk::widget(n)\fR. \fIpathName \fBtag \fIargs...\fR .RS .TP +\fIpathName \fBtag add \fItag items\fR +Adds the specified \fItag\fR to each of the listed \fIitems\fR. +If \fItag\fR is already present for a particular item, +then the \fB\-tags\fR for that item are unchanged. +.TP \fIpathName \fBtag bind \fItagName \fR?\fIsequence\fR? ?\fIscript\fR? Add a Tk binding script for the event sequence \fIsequence\fR to the tag \fItagName\fR. When an X event is delivered to an item, @@ -372,6 +377,12 @@ With no additional arguments, returns a dictionary of the option settings for \fItagName\fR. See \fBTAG OPTIONS\fR for the list of available options. .TP +\fIpathName \fBtag delete \fItagName\fR +Deletes all tag information for the \fItagName\fR argument. The +command removes the tag from all items in the widget and also deletes any +other information associated with the tag, such as bindings and display +information. The command returns an empty string. +.TP \fIpathName \fBtag has \fItagName\fR ?\fIitem\fR? If \fIitem\fR is specified, returns 1 or 0 depending on whether the specified item has the named tag. @@ -381,11 +392,6 @@ the specified tag. \fIpathName \fBtag names\fR Returns a list of all tags used by the widget. .TP -\fIpathName \fBtag add \fItag items\fR -Adds the specified \fItag\fR to each of the listed \fIitems\fR. -If \fItag\fR is already present for a particular item, -then the \fB\-tags\fR for that item are unchanged. -.TP \fIpathName \fBtag remove \fItag\fR ?\fIitems\fR? Removes the specified \fItag\fR from each of the listed \fIitems\fR. If \fIitems\fR is omitted, removes \fItag\fR from each item in the tree. diff --git a/generic/ttk/ttkTagSet.c b/generic/ttk/ttkTagSet.c index e923d77..96e6c4e 100644 --- a/generic/ttk/ttkTagSet.c +++ b/generic/ttk/ttkTagSet.c @@ -80,6 +80,17 @@ void Ttk_DeleteTagTable(Ttk_TagTable tagTable) ckfree(tagTable); } +void Ttk_DeleteTagFromTable(Ttk_TagTable tagTable, Ttk_Tag tag) +{ + Tcl_HashEntry *entryPtr; + + entryPtr = Tcl_FindHashEntry(&tagTable->tags, tag->tagName); + if (entryPtr != NULL) { + DeleteTag(tagTable, tag); + Tcl_DeleteHashEntry(entryPtr); + } +} + Ttk_Tag Ttk_GetTag(Ttk_TagTable tagTable, const char *tagName) { int isNew = 0; diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index 2432fcb..b484d1c 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -79,6 +79,9 @@ static const Tk_OptionSpec ItemOptionSpecs[] = { {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0} }; +/* Forward declaration */ +static void RemoveTag(TreeItem *, Ttk_Tag); + /* + NewItem -- * Allocate a new, uninitialized, unlinked item */ @@ -2960,7 +2963,7 @@ static int TreeviewSelectionCommand( if (objc == 2) { Tcl_Obj *result = Tcl_NewListObj(0,0); - for (item = tv->tree.root->children; item; item=NextPreorder(item)) { + for (item = tv->tree.root->children; item; item = NextPreorder(item)) { if (item->state & TTK_STATE_SELECTED) Tcl_ListObjAppendElement(NULL, result, ItemID(tv, item)); } @@ -2986,7 +2989,7 @@ static int TreeviewSelectionCommand( switch (selop) { case SELECTION_SET: - for (item=tv->tree.root; item; item=NextPreorder(item)) { + for (item=tv->tree.root; item; item = NextPreorder(item)) { item->state &= ~TTK_STATE_SELECTED; } /*FALLTHRU*/ @@ -3102,6 +3105,34 @@ static int TreeviewTagConfigureCommand( return Ttk_ConfigureTag(interp, tagTable, tag, objc - 4, objv + 4); } +/* + $tv tag delete $tag + */ +static int TreeviewTagDeleteCommand( + void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) +{ + Treeview *tv = (Treeview *)recordPtr; + Ttk_TagTable tagTable = tv->tree.tagTable; + TreeItem *item = tv->tree.root; + Ttk_Tag tag; + + if (objc != 4) { + Tcl_WrongNumArgs(interp, 3, objv, "tagName"); + return TCL_ERROR; + } + + tag = Ttk_GetTagFromObj(tagTable, objv[3]); + /* remove the tag from all items */ + while (item) { + RemoveTag(item, tag); + item = NextPreorder(item); + } + /* then remove the tag from the tag table */ + Ttk_DeleteTagFromTable(tagTable, tag); + TtkRedisplayWidget(&tv->core); + + return TCL_OK; +} + /* + $tv tag has $tag ?$item? */ static int TreeviewTagHasCommand( @@ -3231,7 +3262,7 @@ static int TreeviewTagRemoveCommand( TreeItem *item = tv->tree.root; while (item) { RemoveTag(item, tag); - item=NextPreorder(item); + item = NextPreorder(item); } } @@ -3244,6 +3275,7 @@ static const Ttk_Ensemble TreeviewTagCommands[] = { { "add", TreeviewTagAddCommand,0 }, { "bind", TreeviewTagBindCommand,0 }, { "configure", TreeviewTagConfigureCommand,0 }, + { "delete", TreeviewTagDeleteCommand,0 }, { "has", TreeviewTagHasCommand,0 }, { "names", TreeviewTagNamesCommand,0 }, { "remove", TreeviewTagRemoveCommand,0 }, diff --git a/generic/ttk/ttkWidget.h b/generic/ttk/ttkWidget.h index 8eaef04..6837d89 100644 --- a/generic/ttk/ttkWidget.h +++ b/generic/ttk/ttkWidget.h @@ -226,6 +226,8 @@ MODULE_SCOPE int Ttk_EnumerateTagOptions( MODULE_SCOPE int Ttk_EnumerateTags(Tcl_Interp *, Ttk_TagTable); +MODULE_SCOPE void Ttk_DeleteTagFromTable(Ttk_TagTable, Ttk_Tag); + MODULE_SCOPE int Ttk_ConfigureTag( Tcl_Interp *interp, Ttk_TagTable tagTable, Ttk_Tag tag, int objc, Tcl_Obj *const objv[]); diff --git a/tests/ttk/treetags.test b/tests/ttk/treetags.test index 09c34e0..fd3a0c5 100644 --- a/tests/ttk/treetags.test +++ b/tests/ttk/treetags.test @@ -11,12 +11,11 @@ proc assert {expr {message ""}} { error "PANIC: $message ($expr failed)" } } -proc in {e l} { expr {[lsearch -exact $l $e] >= 0} } proc itemConstraints {tv item} { # $tag in [$tv item $item -tags] <==> [$tv tag has $tag $item] foreach tag [$tv item $item -tags] { - assert {[in $item [$tv tag has $tag]]} + assert {$item in [$tv tag has $tag]} } foreach child [$tv children $item] { itemConstraints $tv $child @@ -28,7 +27,7 @@ proc treeConstraints {tv} { # foreach tag [$tv tag names] { foreach item [$tv tag has $tag] { - assert {[in $tag [$tv item $item -tags]]} + assert {$tag in [$tv item $item -tags]} } } @@ -114,6 +113,12 @@ test treetags-1.10 "tag names - tag configured" -body { lsort [$tv tag names] } -result [list tag1 tag2 tag3 tag4 tag5] +test treetags-1.11 "tag delete" -body { + $tv tag delete tag5 + $tv tag delete tag4 + lsort [$tv tag names] +} -result [list tag1 tag2 tag3] + test treetags-1.end "cleanup" -body { $tv item item1 -tags tag1 $tv item item2 -tags tag2 |