Tk Source Code

Artifact [2c99ace9]
Login

Artifact 2c99ace9a61b826f647963c663a6afba7d8c929f59080a4b64d3199537c5d379:

Attachment "treeview.patch" to ticket [1bb2f1d7] added by emiliano 2020-05-04 00:56:45. (unpublished)
Index: doc/ttk_treeview.n
==================================================================
--- doc/ttk_treeview.n
+++ doc/ttk_treeview.n
@@ -370,10 +370,17 @@
 (or the empty string if the option has not been specified for \fItagName\fR).
 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.
 Otherwise, returns a list of all items which have
 the specified tag.

Index: generic/ttk/ttkTagSet.c
==================================================================
--- generic/ttk/ttkTagSet.c
+++ generic/ttk/ttkTagSet.c
@@ -77,10 +77,22 @@
     }
 
     Tcl_DeleteHashTable(&tagTable->tags);
     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;
     Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(

Index: generic/ttk/ttkTreeview.c
==================================================================
--- generic/ttk/ttkTreeview.c
+++ generic/ttk/ttkTreeview.c
@@ -77,10 +77,13 @@
 	TK_OPTION_NULL_OK,0,ITEM_OPTION_TAGS_CHANGED },
 
     {TK_OPTION_END, 0,0,0, NULL, TCL_AUTO_LENGTH,TCL_AUTO_LENGTH, 0,0,0}
 };
 
+/* Forward declaration */
+static void RemoveTag(TreeItem *, Ttk_Tag);
+
 /* + NewItem --
  * 	Allocate a new, uninitialized, unlinked item
  */
 static TreeItem *NewItem(void)
 {
@@ -3099,10 +3102,38 @@
     }
     /* else */
     TtkRedisplayWidget(&tv->core);
     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(
     void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
@@ -3242,10 +3273,11 @@
 
 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 },
     { 0,0,0 }
 };

Index: generic/ttk/ttkWidget.h
==================================================================
--- generic/ttk/ttkWidget.h
+++ generic/ttk/ttkWidget.h
@@ -223,10 +223,12 @@
 
 MODULE_SCOPE int Ttk_EnumerateTagOptions(
     Tcl_Interp *, Ttk_TagTable, Ttk_Tag);
 
 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[]);