Tk Library Source Code

View Ticket
Login
Ticket UUID: 2825354
Title: Tree node -helpcmd option
Type: Patch Version: None
Submitter: danckaert Created on: 2009-07-22 13:10:45
Subsystem: bwidget Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-07-24 22:51:46
Resolution: Accepted Closed By: oehhar
    Closed on: 2009-07-23 08:01:08
Description:
This patch ensures that the DynamicHelp -helpcmd option can be used in a Tree. Example:

pack [Tree .t -padx 2]
proc helpfor {n} {return "Help for $n"}
.t insert end root node1 -text "Node 1" -helpcmd {helpfor node1}
.t insert end root node2 -text "Node 2" -helpcmd {helpfor node2}
.t insert end root node3 -text "Node 3" -helpcmd {helpfor node3}

The patch also contains a slight visual adjustment of initial node of the tree. This is in fact a reversal of a patch which was introduced in version 1.49. I did not understand why this was changed back then. It made the tree appear more like a "fork" than a tree, which is also apparent in the example above.
User Comments: oehhar added on 2009-07-24 22:51:46:
Koen answered on tcl-devel:

Ok, I already thought that the Windows style you were referring to always had exactly one top node, which is not the case for BWidget (where the real "root" node is actually invisible).

I propose to make the line dependent on whether there are multiple top nodes. (Harald, the patch for that is below.) It seems we could agree on that, and I prefer it to an extra option (= extra documentation, which will probably difficult to understand without trying out.)

--Koen


Index: tree.tcl
===================================================================
RCS file: /cvsroot/tcllib/bwidget/tree.tcl,v
retrieving revision 1.59
diff -b -u -r1.59 tree.tcl
--- tree.tcl30 Jun 2009 16:17:37 -00001.59
+++ tree.tcl24 Jul 2009 13:26:22 -0000
@@ -1369,12 +1369,9 @@
         set yp $y1
         set y1 [_draw_node $path $node $x0 [expr {$y1+$deltay}] $deltax $deltay $padx $showlines]
     }
-    if { $showlines && [llength $nodes] } {
-if {$y0 < 0} {
-    # Adjust the drawing of the line to the first root node
-    # to start at the vertical point (not go up).
-    incr y0 $deltay
-}
+    # Only draw a line to the virtual root node when there are multiple top nodes.
+    set len [llength $nodes]
+    if { $showlines && $len && !($y0 < 0 && $len < 2) } {
         set id [$path.c create line $x0 $y0 $x0 [expr {$yp+$deltay}] \
                     -fill    [Widget::getoption $path -linesfill]   \
                     -stipple [Widget::getoption $path -linestipple] \
---

Jeff answered: Agreed.

---

The upper patch is applied and committed.

Thanks to all.

oehhar added on 2009-07-23 15:01:08:
a) Visual representation:
A line from the top of the tree widget window downwards to the first node was removed with the following log entry:

2004-04-21  Jeff Hobbs  <[email protected]>
    * tree.tcl (_draw_subnodes): Adjust the drawing of the line to the
    first root node to start at the vertical point (not go up). 

Jeff explained further by E-Mail:
The reason I made that change was to be visually compatible with Windows (older style, as new style is no lines) when you actually have sub-nodes (the [+] and [-] indicators).  The line to the top is then inconsistent with the way others draw.
You could try and make that check contingent on whether subnodes exist, but I think that may seem odd. 

b) tree -helpcmd patch
Patch is ok, integrated in cvs, command added to docs.

danckaert added on 2009-07-22 20:10:46:

File Added - 336092: tree.patch

Attachments: