I had to do this several months ago....when I talked to Joe back then,
I believe there was no plan for this, however, I'll let him speak to
that now.
What I had to do is [place] an entry where the tree item was, to let
the user edit the text. It works Ok, but it would be nicer to have it
within treeview.
For me, I bound a proc to the Double-1, and in the proc, I [place] the
entry widget where the Double-1 click occurred. It's not very exact,
but works ok. I have to discover the y coord, and you might also have
to adjust it if the window is resized (use <Configure>).
Note: My tree only has one column, so if there are multiple columns,
this may be trickier.
something like this:
bind .tree <Double-1> [list embedEntry $base %W %X %Y]
bind .tree <Configure> [list adjustEntryWidth %W]
proc embedEntry {base_ wid_ {y_ ""}} {
variable W
catch {$wid_ delete dummy}
catch {destroy ${wid_}.addressentry}
##
## find a good y to start at
##
if {$y_ == ""} {
$wid_ insert {} end -id dummy
update idletasks
## find better starting number
set y 31
for {set i 20} {$i <= 200} {incr i} {
set x [lindex [$wid_ identify 10 $i] 1]
if {$x == "dummy"} {
set y $i
break
}
}
} else {
set y [expr {$y_ - [winfo rooty $wid_]}]
}
# hard coded for now
set x 8
set item [lindex [$wid_ identify $x $y] 1]
set W(recipient_entry) [::ttk::entry ${wid_}.addressentry -width
52]
place ${wid_}.addressentry -x $x -y [expr {$y + 1}] -in $wid_
${wid_}.addressentry insert 0 [$wid_ item $item -text]
bind ${wid_}.addressentry <Key-Escape> [list destroy
${wid_}.addressentry]
bind ${wid_}.addressentry <Return> [list replaceToString $wid_
$item ${wid_}.addressentry]
focus ${wid_}.addressentry
adjustEntryWidth $wid_
return
}
proc adjustEntryWidth {treewid_} {
variable W
if {![info exists W(recipient_entry)]} {return}
if {![winfo exists $W(recipient_entry)]} {return}
set twid [winfo width $treewid_]
##
## This is called for both tree widgets, so only need
## this for the one that has the embedded entry widget
##
if {[string equal $treewid_ .tree]} {
set ewid [expr {$twid - 16}]
set fsize [font measure TkTextFont 0]
$W(recipient_entry) configure -width [expr {$ewid / $fsize}]
}
$treewid_ column #0 -width [expr {$twid - 12}]
return
}
ttk::treeview is great, I like it especially for it's simple usage and
tile themes.
But for more sophisticated things, like your node-editing problem, you
might want to have a look at tktreectrl
(http://tktreectrl.sourceforge.net/).
Eckhard
I tried using TreeCtrl and got the following core dump on Solaris using
Tcl/Tk v8.4.12 when trying the demo.tcl script in the demos directory.
Here's the stack trace:
(gdb) where
#0 0xfed8f8f8 in AllocHax_Alloc () from /data1/optlocal/tcltk-8.4.12/lib/treectrl2.1/libtreectrl2.1.so
#1 0xfed8fdb8 in PerStateInfo_FromObj () from /data1/optlocal/tcltk-8.4.12/lib/treectrl2.1/libtreectrl2.1.so
#2 0xfed5f39c in Column_Config () from /data1/optlocal/tcltk-8.4.12/lib/treectrl2.1/libtreectrl2.1.so
#3 0xfed631f0 in Tree_InitColumns () from /data1/optlocal/tcltk-8.4.12/lib/treectrl2.1/libtreectrl2.1.so
#4 0xfed640a8 in TreeObjCmd () from /data1/optlocal/tcltk-8.4.12/lib/treectrl2.1/libtreectrl2.1.so
#5 0xff1a80dc in TclEvalObjvInternal () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#6 0xff1d1dbc in TclExecuteByteCode () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#7 0xff1d12b8 in TclCompEvalObj () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#8 0xff205ae8 in TclObjInterpProc () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#9 0xff1a80dc in TclEvalObjvInternal () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#10 0xff1d1dbc in TclExecuteByteCode () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#11 0xff1d12b8 in TclCompEvalObj () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#12 0xff205ae8 in TclObjInterpProc () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#13 0xff1a80dc in TclEvalObjvInternal () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#14 0xff1a89dc in Tcl_EvalEx () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#15 0xff1ee700 in Tcl_FSEvalFile () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#16 0xff1ed368 in Tcl_EvalFile () from /opt/local/tcltk-8.4.12/lib/libtcl8.4.so
#17 0xff2c0abc in Tk_MainEx () from /opt/local/tcltk-8.4.12/lib/libtk8.4.so
#18 0x000109b0 in main ()
Any ideas?
Joey
Hmm, sorry - no. I was using it once on Windows, and there it works
fine...
Eckhard
I've used BWidget tree for this. It's pure tcl based on the canvas. It
has the in-place text editing built in like what you want.
But that's a problem I just dealed with, so it's quite fresh in my mind
:-):
set path [list [$tree selection]]
set sel [$tree selection]
while {1} {
set parItem [$tree parent $sel]
if {$parItem == ""} {
break
}
set path [concat $parItem $path]
set sel $parItem
}
Eckhard