Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/dictree?V=40
QUERY_STRINGV=40
CONTENT_TYPE
DOCUMENT_URI/revision/dictree
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.178.150
REMOTE_PORT10446
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR18.117.158.47
HTTP_CF_RAY8770c77329926390-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_CF_CONNECTING_IP18.117.158.47
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit dictree '''\[AMW\]'''\ Inspired\ by\ \[eDictor\],\ today\ I\ created\ the\ '''dictree'''\ \[megawidget\]\ using\ a\ \[ttk::treeview\]\ to\ display\ and\ edit\ the\ content\ of\ a\ \[dict\].\n\n'''Example\ Usage:'''\n======\n\ \ \ \ #\ create\ a\ sample\ dict\ with\ some\ data:\n\ \ \ \ dict\ set\ d\ author\ firstname\ \"Alexander\"\n\ \ \ \ dict\ set\ d\ author\ surname\ \ \ \"Mlynski-Wiese\"\n\ \ \ \ dict\ set\ d\ date\ \ \ \"2012-12-21\"\n\ \ \ \ dict\ set\ d\ prog\ name\ \ \ \ \"dictree\"\n\ \ \ \ dict\ set\ d\ prog\ version\ 1.1\n\ \ \ \ #\ -->\ author\ \{firstname\ Alexander\ surname\ Mlynski-Wiese\}\ date\ 2012-12-21\ prog\ \{name\ dictree\ version\ 1.1\}\n\n\ \ \ \ #\ create\ the\ widget\ and\ populate\ it\ with\ the\ dict\ data:\n\ \ \ \ dictree\ .t\ \$d\n\n\ \ \ \ #\ display\ the\ widget:\n\ \ \ \ pack\ .t\ -expand\ yes\ -fill\ both\n======\n\nThe\ widget\ will\ dive\ as\ deeply\ as\ possible\ into\ the\ data\ by\ interpreting\ it\ as\ nested\ dictionary\ whereever\ possible.\n\n\[dictree_screenshot\]\n\nIf\ you\ do\ not\ want\ this\ kind\ interpretation\ for\ any\ node,\ just\ press\ '''Alt'''\ and\ '''click'''\ on\ the\ node\ with\ the\ mouse,\ and\ it\ will\ collapse\ into\na\ leaf.<<br>>Click\ again\ to\ expand\ it\ to\ a\ node\ with\ children\ again.\n\nAlternatively,\ press\ '''Alt+Enter'''\ to\ collapse/expand\ the\ selected\ node\ in\ this\ sense.\n\nThe\ following\ keys\ allow\ modification\ of\ the\ data:\n\ \ \ \ *\ '''Alt+Up/Down'''\ moves\ the\ selected\ node\ up\ or\ down\ within\ it's\ current\ hierarchy\ level\n\ \ \ \ *\ '''Alt+Left/Right'''\ raises\ or\ lowers\ the\ selected\ node\ to\ the\ next\ hierarchy\ level\n\ \ \ \ *\ '''F2'''\ will\ allow\ modification\ of\ the\ selected\ node's\ name\n\ \ \ \ *\ '''Shift+F2'''\ will\ allow\ to\ edit\ the\ selected\ node's\ value\ (only\ if\ it\ is\ a\ leaf)\n\ \ \ \ *\ '''Delete'''\ will\ delete\ the\ selected\ node(s)\n\ \ \ \ *\ '''Insert'''\ will\ insert\ a\ new\ node\ as\ a\ sibbling\ before\ the\ selected\ node\n\ \ \ \ *\ '''Alt+Insert'''\ will\ insert\ a\ new\ node\ as\ a\ sibbling\ after\ the\ selected\ node\n\nAfter\ editing,\ you\ can\ 'reap'\ the\ tree\ to\ return\ the\ content\ as\ a\ dict:\n======\n\ \ \ \ set\ edited_d\ \[.t\ reap\]\n======\n\n-----\n***Possible\ Enhancements***\n\ \ \ \ *\ on\ right-button\ click,\ show\ a\ context\ menue\ to\ add/delete/edit/move\ the\ node\n\ \ \ \ *\ drag\ and\ drop\ of\ node\n\n-----\n***Code***\nThe\ code\ below\ can\ be\ used\ \n\ \ \ \ *\ as\ a\ '''package'''\ within\ other\ projects,\ or\ \n\ \ \ \ *\ as\ a\ '''standalone'''\ application\n\ \ \ \ **\ to\ display\ a\ dict\ loaded\ from\ a\ file\ \n\ \ \ \ **\ to\ fill\ a\ demo\ dictionary\ with\ directory\ information\ and\ display\ it\ using\ '''dictree'''\n\n<<discussion>>\ dictree.tcl\n======\n#===============================================================================\n#\ \ dictree\ widget\ \ \ \ \ \ \ \ display\ and\ edit\ dictionary\ data\ in\ ttk::treeview\n#\n#\ \ 21.12.2012,\ Alexander\ Mlynski-Wiese\n#===============================================================================\n\npackage\ require\ Tcl\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 8.5\npackage\ require\ Tk\npackage\ require\ Ttk\n\npackage\ provide\ dictree\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1.0\n\n#-------------------------------------------------------------------------------\n#\ \ dictree\ w\ d\n#\ \ create\ a\ treeview\ widget\ with\ the\ pathname\ \$w\n#\ \ and\ fill\ it\ with\ the\ dictionary\ data\ \$d\n#-------------------------------------------------------------------------------\nproc\ dictree\ \{\ w\ d\ args\ \}\ \{\n\n\ \ \ \ frame\ \$w\n\ \ \ \ ttk::treeview\ \$w.t\ -columns\ \{key\ value\}\ -displaycolumns\ value\ \ \ \ \ \ \ \ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -yscroll\ \"\$\{w\}.sby\ set\"\ -xscroll\ \"\$\{w\}.sbx\ set\"\n\n\ \ \ \ if\ \{\[tk\ windowingsystem\]\ ne\ \"aqua\"\}\ \{\n\ \ \ \ \ \ \ \ ttk::scrollbar\ \$\{w\}.sby\ -orient\ vertical\ \ \ -command\ \"\$w.t\ yview\"\n\ \ \ \ \ \ \ \ ttk::scrollbar\ \$\{w\}.sbx\ -orient\ horizontal\ -command\ \"\$w.t\ xview\"\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ scrollbar\ \$\{w\}.sby\ -orient\ vertical\ \ \ -command\ \"\$w.t\ yview\"\n\ \ \ \ \ \ \ \ scrollbar\ \$\{w\}.sbx\ -orient\ horizontal\ -command\ \"\$w.t\ xview\"\n\ \ \ \ \}\n\n\ \ \ \ \$w.t\ heading\ \\#0\ \ \ -text\ \"Directory\ Key(s)\"\n\ \ \ \ \$w.t\ heading\ value\ -text\ \"Value\"\n\n\ \ \ \ entry\ \$w.e\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ widget\ used\ for\ editing\n\n\ \ \ \ grid\ \$w.t\ \ \ \ -row\ 0\ -column\ 0\ -sticky\ news\n\ \ \ \ grid\ \$w.sby\ \ -row\ 0\ -column\ 1\ -sticky\ ns\ \ \ \ \ \ \ \ \;#\ arrange\ the\ scrollbars\n\ \ \ \ grid\ \$w.sbx\ \ -row\ 1\ -column\ 0\ -sticky\ ew\n\ \ \ \ grid\ rowconfigure\ \ \ \ \ \ \ \ \ \ \$w\ 0\ -weight\ 1\n\ \ \ \ grid\ columnconfigure\ \$w\ 0\ -weight\ 1\n\n\ \ \ \ dictree::bindings\ \$w.t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ create\ the\ bindings\n\n\ \ \ \ dict\ for\ \{key\ val\}\ \$d\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ populate\ the\ treeview\n\ \ \ \ \ \ \ \ dictree::addNode\ \$w.t\ \"\"\ \$key\ \$val\n\ \ \ \ \}\n\n\ \ \ \ #-----------------------------------------------------------------------\n\ \ \ \ #\ \ \"overload\"\ the\ widget\ proc\ to\ support\ additional\ commands\n\ \ \ \ #-----------------------------------------------------------------------\n\ \ \ \ rename\ \$w\ _\$w\n\ \ \ \ proc\ \$w\ \{cmd\ args\}\ \{\n\ \ \ \ \ \ \ \ set\ self\ \[lindex\ \[info\ level\ 0\]\ 0\]\ \;#\ get\ name\ I\ was\ called\ with\n\ \ \ \ \ \ \ \ switch\ --\ \$cmd\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ reap\ \ \ \ \{uplevel\ 1\ dictree::reap\ \$self.t\ \$args\ \}\n\ \ \ \ \ \ \ \ \ \ \ \ default\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[catch\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uplevel\ 1\ _\$self\ \$cmd\ \$args\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uplevel\ 1\ \$self.t\ \$cmd\ \$args\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\n\ \ \ \ return\ \$w\n\}\n\nnamespace\ eval\ dictree\ \{\ \ \ \ \ \ \ \ \;#\ \"private\"\ functions\n#-------------------------------------------------------------------------------\n#\ \ bindings\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ create\ the\ bindings\ for\ the\ treeview\n#-------------------------------------------------------------------------------\nproc\ bindings\ \{\ w\ \{\ debug\ 0\ \}\ \}\ \{\n\n\ \ \ \ bind\ \$w\ <plus>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::setopen\ %W\ \[%W\ selection\]\ 1\ \}\n\ \ \ \ bind\ \$w\ <minus>\ \ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::setopen\ %W\ \[%W\ selection\]\ 0\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-plus>\ \ \ \ \ \ \ \ \ \ \{\ dictree::expand\ \ \ %W\ \[%W\ selection\]\ \}\n\ \ \ \ bind\ \$w\ <Alt-minus>\ \ \ \ \ \ \ \ \ \{\ dictree::collapse\ %W\ \[%W\ selection\]\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-ButtonPress-1>\ \{\ dictree::toggle\ %W\ \[%W\ identify\ item\ %x\ %y\]\ \}\n\ \ \ \ bind\ \$w\ <Alt-Return>\ \ \ \ \ \ \ \ \{\ dictree::toggle\ %W\ \[%W\ selection\]\;\ break\ \}\n\n\ \ \ \ bind\ \$w\ <F2>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::edit\ %W\ \[%W\ selection\]\ \"#0\"\ \}\n\ \ \ \ bind\ \$w\ <Shift-F2>\ \ \ \ \ \ \ \ \ \ \{\ dictree::edit\ %W\ \[%W\ selection\]\ \"value\"\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-Up>\ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::move\ %W\ \[%W\ selection\]\ -1\;\ break\ \}\n\ \ \ \ bind\ \$w\ <Alt-Down>\ \ \ \ \ \ \ \ \ \ \{\ dictree::move\ %W\ \[%W\ selection\]\ \ 1\;\ break\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-Left>\ \ \ \ \ \ \ \ \ \ \{\ dictree::rise\ %W\ \[%W\ selection\]\ \ 1\;\ break\ \}\n\ \ \ \ bind\ \$w\ <Alt-Right>\ \ \ \ \ \ \ \ \ \{\ dictree::rise\ %W\ \[%W\ selection\]\ -1\;\ break\ \}\n\n\ \ \ \ bind\ \$w\ <Delete>\ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::delete\ %W\ \[%W\ selection\]\ \}\n\ \ \ \ bind\ \$w\ <Insert>\ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::insert\ %W\ \[%W\ selection\]\ \}\n\ \ \ \ bind\ \$w\ <Alt-Insert>\ \ \ \ \ \ \ \ \{\ dictree::insert\ %W\ \[%W\ selection\]\ 1\ \}\n\n\ \ \ \ if\ \{\ \$debug\ \}\ \{\n\ \ \ \ \ \ \ \ #\ to\ aid\ developing\ additional\ bindings:\n\ \ \ \ \ \ \ \ bind\ \$w\ <ButtonPress-1>\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ item\ \[%W\ identify\ item\ %x\ %y\]\n\ \ \ \ \ \ \ \ \ \ \ \ puts\ \"%x,%y:\ %W\ item\ \$item:\ \[%W\ item\ \$item\]\"\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ bind\ \$w\ <KeyPress>\ \{\ puts\ %K\ \}\n\ \ \ \ \}\n\n\ \ \ \ return\ \$w\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ addNode\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ recursive\ proc\ to\ create\ and\ fill\ the\ nodes\n#-------------------------------------------------------------------------------\nproc\ addNode\ \{\ w\ parent\ title\ d\ \}\ \{\n\ \ \ \ set\ node\ \[\$w\ insert\ \$parent\ end\ -text\ \$title\]\n\ \ \ \ set\ isdict\ 0\n\ \ \ \ catch\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \[dict\ get\ \$d\]\ ==\ \$d\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ isdict\ 1\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ if\ \{\ \$isdict\}\ \{\n\ \ \ \ \ \ \ \ #\ interpret\ data\ \$d\ as\ a\ dictionary\ and\ create\ a\ subnode\n\ \ \ \ \ \ \ \ dict\ for\ \{key\ val\}\ \$d\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ addNode\ \$w\ \$node\ \$key\ \$val\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ #\ \$d\ is\ not\ a\ dictionary:\ make\ this\ node\ a\ leaf\n\ \ \ \ \ \ \ \ \$w\ set\ \$node\ value\ \$d\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ setopen\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ open/close\ node(s)\n#-------------------------------------------------------------------------------\nproc\ setopen\ \{\ w\ items\ mode\ \}\ \{\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ \$w\ item\ \$item\ -open\ \$mode\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ collapse\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ collapse\ all\ child\ nodes\ and\ make\ node\ \$item\ a\ leaf\n#-------------------------------------------------------------------------------\nproc\ collapse\ \{\ w\ items\ \}\ \{\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ set\ children\ \"\"\n\ \ \ \ \ \ \ \ catch\ \{\ set\ children\ \[\$w\ children\ \$item\]\ \}\n\ \ \ \ \ \ \ \ if\ \{\ \$children\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ value\ \"\"\n\ \ \ \ \ \ \ \ \ \ \ \ foreach\ child\ \[\$w\ children\ \$item\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ collapse\ \$w\ \$child\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ value\ \[\$w\ item\ \$child\ -text\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ value\ \[\$w\ set\ \$child\ value\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ delete\ \$child\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ set\ \$item\ value\ \$value\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ expand\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ possible,\ expand\ leaf\ value\ to\ child\ nodes\n#-------------------------------------------------------------------------------\nproc\ expand\ \{\ w\ items\ \}\ \{\n\ \ \ \ global\ errorInfo\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \[\$w\ children\ \$item\]\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ d\ \[\$w\ set\ \$item\ value\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ isdict\ 0\n\ \ \ \ \ \ \ \ \ \ \ \ catch\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[dict\ get\ \$d\]\ ==\ \$d\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ isdict\ 1\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$isdict\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dict\ for\ \{key\ val\}\ \$d\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ addNode\ \$w\ \$item\ \$key\ \$val\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ set\ \$item\ value\ \"\"\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ toggle\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ toggle\ node(s)\ between\ collapsed\ /\ expanded\n#-------------------------------------------------------------------------------\nproc\ toggle\ \{\ w\ items\ \}\ \{\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \[\$w\ children\ \$item\]\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ collapse\ \$w\ \$item\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ expand\ \$w\ \$item\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ move\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ move\ node\ up/down\ among\ siblings,\ i.e.\ keep\ parent\ node\n#-------------------------------------------------------------------------------\nproc\ move\ \{\ w\ item\ increment\ \}\ \{\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\ \ \ \ set\ parent\ \[\$w\ parent\ \$item\]\n\ \ \ \ set\ index\ \ \[\$w\ index\ \ \$item\]\n\ \ \ \ incr\ index\ \$increment\n\ \ \ \ \$w\ move\ \$item\ \$parent\ \$index\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ adopt\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ move\ item\ to\ new\ parent\n#-------------------------------------------------------------------------------\nproc\ adopt\ \{\ w\ item\ newparent\ newindex\ \}\ \{\n\ \ \ \ set\ name\ \[\$w\ item\ \$item\ -text\]\n\ \ \ \ set\ children\ \[\$w\ children\ \$newparent\]\n\ \ \ \ if\ \{\ \$children\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ return\ 0\n\ \ \ \ \}\n\ \ \ \ foreach\ child\ \$children\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \$name\ ==\ \[\$w\ item\ \$child\ -text\]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ #\ not\ allowed:\ parent\ already\ has\ a\ child\ with\ that\ name\n\ \ \ \ \ \ \ \ \ \ \ \ return\ 0\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ \$w\ move\ \$item\ \$newparent\ \$newindex\n\ \ \ \ \$w\ item\ \$newparent\ -open\ 1\n\ \ \ \ return\ 1\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ rise\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ rise/fall\ one\ level\ in\ the\ hierarchy\n#-------------------------------------------------------------------------------\nproc\ rise\ \{\ w\ item\ increment\ \}\ \{\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\ \ \ \ set\ parent\ \ \[\$w\ parent\ \$item\]\n\n\ \ \ \ if\ \{\ \$increment\ >\ 0\ \}\ \{\n\ \ \ \ \ \ \ \ #\ rise\ in\ the\ hierarchy,\ make\ my\ grandpa\ my\ new\ parent\n\ \ \ \ \ \ \ \ set\ newparent\ \[\$w\ parent\ \$parent\]\ \ \ \ \ \ \ \ \;#\ grandpa\n\ \ \ \ \ \ \ \ set\ newindex\ \ \[\$w\ index\ \ \$parent\]\n\ \ \ \ \ \ \ \ incr\ newindex\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ behind\ my\ old\ parent\n\ \ \ \ \ \ \ \ adopt\ \$w\ \$item\ \$newparent\ \$newindex\n\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ #\ fall\ in\ the\ hierarchy,\ make\ a\ brother\ my\ new\ parent\n\ \ \ \ \ \ \ \ set\ index\ \ \ \ \[\$w\ index\ \$item\]\n\ \ \ \ \ \ \ \ set\ brothers\ \[\$w\ children\ \$parent\]\n\ \ \ \ \ \ \ \ set\ brother\ \ \[lindex\ \$brothers\ \[expr\ \$index-1\]\]\n\n\ \ \ \ \ \ \ \ if\ \{\ \$brother\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[adopt\ \$w\ \$item\ \$brother\ end\]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ foreach\ brother\ \$brothers\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$brother\ !=\ \$item\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[adopt\ \$w\ \$item\ \$brother\ end\]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ edit\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ edit\ node\ text\ or\ value\n#-------------------------------------------------------------------------------\nproc\ edit\ \{\ w\ item\ column\ \{\ next\ \"\"\ \}\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\ \ \ \ foreach\ \{bx\ by\ bw\ bh\}\ \[\$w\ bbox\ \$item\ \$column\]\ \{\}\n\ \ \ \ set\ ym\ \[expr\ \$by\ +\ \$bh/2\]\n\ \ \ \ while\ \{\ \$bx\ <\ 50\ &&\ \[\$w\ identify\ element\ \$bx\ \$ym\]\ !=\ \"text\"\ \}\ \{\n\ \ \ \ \ \ \ \ incr\ bx\n\ \ \ \ \ \ \ \ incr\ bw\ -1\n\ \ \ \ \}\n\n\ \ \ \ if\ \{\ \$column\ ==\ \"#0\"\ \}\ \{\n\ \ \ \ \ \ \ \ set\ dictree(\$w,text)\ \[\$w\ item\ \$item\ -text\]\n\ \ \ \ \}\ elseif\ \{\ \[\$w\ children\ \$item\]\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ return\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ set\ dictree(\$w,text)\ \[\$w\ set\ \$item\ \$column\]\n\ \ \ \ \}\n\ \ \ \ set\ parent\ \[winfo\ parent\ \$w\ \]\ \n\ \ \ \ if\ \{\ \[catch\ \{\n\ \ \ \ \ \ \ \ place\ \$parent.e\ -x\ \$bx\ -y\ \$by\ -width\ \$bw\ -height\ \$bh\n\ \ \ \ \}\ \]\ \}\ \{\n\ \ \ \ \ \ \ \ return\n\ \ \ \ \}\n\ \ \ \ \$parent.e\ configure\ -textvariable\ dictree(\$w,text)\ \ \ \ \ \ \ \ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -validate\ key\ \ \ \ \ \ \ \ \ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -validatecommand\ \"dictree::edit_check\ \$parent\ \$item\ \$column\ %P\"\n\ \ \ \ if\ \{\ \$dictree(\$w,text)\ ==\ \"(new)\"\ \}\ \{\n\ \ \ \ \ \ \ \ \$parent.e\ selection\ range\ 0\ end\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \$parent.e\ selection\ clear\n\ \ \ \ \}\n\ \ \ \ \$parent.e\ configure\ -background\ white\n\ \ \ \ \$parent.e\ icursor\ end\n\ \ \ \ focus\ \$parent.e\n\ \ \ \ grab\ \ \$parent.e\n\ \ \ \ bind\ \ \$parent.e\ <Return>\ \"dictree::edit_done\ \$w\ \$item\ \$column\ \$next\"\n\ \ \ \ bind\ \ \$parent.e\ <Escape>\ \"dictree::edit_done\ \$w\ \$item\ \{\}\ \$next\"\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ edit_check\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ check\ if\ name\ is\ allowed\n#-------------------------------------------------------------------------------\nproc\ edit_check\ \{\ w\ item\ column\ value\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ set\ ok\ 1\n\ \ \ \ if\ \{\ \$column\ ==\ \"#0\"\ \}\ \{\n\ \ \ \ \ \ \ \ set\ parent\ \[\$w\ parent\ \$item\]\n\ \ \ \ \ \ \ \ foreach\ child\ \[\$w\ children\ \$parent\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$child\ !=\ \$item\ &&\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[\$w\ item\ \$child\ -text\]\ ==\ \$value\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ ok\ 0\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ set\ parent\ \[winfo\ parent\ \$w\ \]\ \n\ \ \ \ \ \ \ \ if\ \{\ !\ \$ok\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \$w.e\ configure\ -background\ red\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \$w.e\ configure\ -background\ white\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ 1\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ edit_done\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ finish\ editing\n#-------------------------------------------------------------------------------\nproc\ edit_done\ \{\ w\ item\ \{column\ \"\"\ \}\ \{\ next\ \"\"\ \}\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ set\ parent\ \[winfo\ parent\ \$w\ \]\ \n\ \ \ \ if\ \{\ \$column\ !=\ \"\"\ &&\ \[\$parent.e\ cget\ -background\]\ ==\ \"red\"\ \}\ \{\n\ \ \ \ \ \ \ \ return\n\ \ \ \ \}\n\n\ \ \ \ grab\ release\ \$parent.e\n\ \ \ \ focus\ \$w\n\ \ \ \ if\ \{\ \$column\ ==\ \"#0\"\ \}\ \{\n\ \ \ \ \ \ \ \ \$w\ item\ \$item\ -text\ \$dictree(\$w,text)\n\ \ \ \ \}\ elseif\ \{\ \$column\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \$w\ set\ \$item\ \$column\ \$dictree(\$w,text)\n\ \ \ \ \}\n\ \ \ \ place\ forget\ \$parent.e\n\ \ \ \ if\ \{\ \$next\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \$column\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ delete\ \$item\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ selection\ set\ \$dictree(\$w,selection)\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ edit\ \$w\ \$item\ \$next\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ unset\ dictree(\$w,text)\n\ \ \ \ catch\ \{\ unset\ dictree(\$w,selection)\ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ delete\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ delete\ node(s)\ (after\ confirmation)\n#-------------------------------------------------------------------------------\nproc\ delete\ \{\ w\ items\ \}\ \{\n\ \ \ \ set\ count\ \[llength\ \$items\]\n\ \ \ \ set\ msg\ \"Do\ you\ really\ want\ to\ delete\ the\ following\ \"\n\ \ \ \ if\ \{\ \$count\ >\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ append\ msg\ \"\$count\ nodes:\\n\"\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ append\ msg\ \"node:\\n\"\n\ \ \ \ \}\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ append\ msg\ \"\ \[\$w\ item\ \$item\ -text\]\"\n\ \ \ \ \}\n\ \ \ \ append\ msg\ \"?\"\n\ \ \ \ if\ \{\ \[tk_messageBox\ -title\ \"Delete\ nodes\"\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -icon\ warning\ -message\ \$msg\ -type\ yesno\]\ ==\ \"yes\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ delete\ \$items\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ insert\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ insert\ &\ edit\ new\ node\ before/after\ given\ node\n#-------------------------------------------------------------------------------\nproc\ insert\ \{\ w\ item\ \{\ offset\ 0\ \}\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\n\ \ \ \ set\ dictree(\$w,selection)\ \[\$w\ selection\]\n\n\ \ \ \ set\ parent\ \[\$w\ parent\ \$item\]\n\ \ \ \ set\ index\ \ \[\$w\ index\ \ \$item\]\n\n\ \ \ \ set\ newidx\ \[expr\ \$index\ +\ \$offset\]\n\ \ \ \ set\ node\ \[\$w\ insert\ \$parent\ \$newidx\ -text\ \"(new)\"\]\n\ \ \ \ \$w\ set\ \$node\ value\ \"(new)\"\n\ \ \ \ \$w\ selection\ set\ \$node\n\ \ \ \ edit\ \$w\ \$node\ \"#0\"\ \"value\"\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ reap\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ the\ content\ of\ the\ treeview\ as\ dictionary\n#-------------------------------------------------------------------------------\nproc\ reap\ \{\ w\ \{\ node\ \"\"\ \}\ \}\ \{\n\ \ \ \ set\ children\ \[\$w\ children\ \$node\]\n\ \ \ \ if\ \{\ \[llength\ \$children\]\ ==\ 0\ \}\ \{\n\ \ \ \ \ \ \ \ set\ value\ \[\$w\ set\ \$node\ value\]\n\ \ \ \ \ \ \ \ dict\ set\ d\ \[\$w\ item\ \$node\ -text\]\ \$value\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ foreach\ child\ \$children\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ value\ \[reap\ \$w\ \$child\]\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$node\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ d\ \{*\}\$value\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dict\ lappend\ d\ \[\$w\ item\ \$node\ -text\]\ \{*\}\$value\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ \$d\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ dictdir\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ generate\ example\ dict\ with\ filesystem\ info\n#-------------------------------------------------------------------------------\nproc\ dictdir\ \{\ dir\ \}\ \{\n\ \ \ \ set\ d\ \"\"\n\ \ \ \ file\ stat\ \$dir\ fstat\n\ \ \ \ foreach\ item\ \[lsort\ \[array\ names\ fstat\]\]\ \{\n\ \ \ \ \ \ \ \ dict\ set\ d\ .\ \$item\ \$fstat(\$item)\n\ \ \ \ \}\n\ \ \ \ foreach\ subdir\ \[lsort\ \[glob\ -directory\ \$dir\ -nocomplain\ -types\ d\ \"*\"\]\]\ \{\n\ \ \ \ \ \ \ \ dict\ set\ d\ \{*\}\[dictdir\ \$subdir\]\n\ \ \ \ \}\n\ \ \ \ foreach\ fname\ \[lsort\ \[glob\ -directory\ \$dir\ -nocomplain\ -types\ f\ \"*\"\]\]\ \{\n\ \ \ \ \ \ \ \ file\ stat\ \$fname\ fstat\n\ \ \ \ \ \ \ \ #\ sorted:\n\ \ \ \ \ \ \ \ foreach\ item\ \[lsort\ \[array\ names\ fstat\]\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ dict\ set\ d\ \[file\ tail\ \$fname\]\ \$item\ \$fstat(\$item)\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ #\ faster\ but\ unsorted:\n\ \ \ \ \ \ \ \ #\ dict\ set\ d\ \[file\ tail\ \$fname\]\ \[array\ get\ fstat\]\n\ \ \ \ \}\n\ \ \ \ return\ \[list\ \[file\ tail\ \$dir\]/\ \$d\]\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ main\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"main\"\ for\ demo\ program\n#-------------------------------------------------------------------------------\nproc\ main\ \{\ args\ \}\ \{\n\ \ \ \ set\ fname\ \[pwd\]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ default\ to\ current\ dir\n\ \ \ \ if\ \{\ \[llength\ \$args\]\ >=\ 1\ \}\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ check\ for\ commandline\ arg\n\ \ \ \ \ \ \ \ set\ fname\ \[lindex\ \$args\ 0\]\n\ \ \ \ \}\n\ \ \ \ if\ \{\ \[file\ isdirectory\ \$fname\]\ \}\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ directory\ was\ given:\n\ \ \ \ \ \ \ \ set\ d\ \[dictdir\ \$fname\]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ parse\ directory\n\n\ \ \ \ \}\ else\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ file\ was\ given:\n\ \ \ \ \ \ \ \ set\ h\ \[open\ \[lindex\ \$args\ 0\]\ \"r\"\]\ \ \ \ \ \ \ \ \;#\ read\ dict\ from\ file\n\ \ \ \ \ \ \ \ set\ d\ \[read\ \$h\]\n\ \ \ \ \ \ \ \ close\ \$h\n\ \ \ \ \}\n\n\ \ \ \ #\ create\ dictree\ control:\n\ \ \ \ dictree\ .t\ \$d\n\ \ \ \ pack\ .t\ -expand\ yes\ -fill\ both\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ end\ of\ namespace\ dict::\n#-------------------------------------------------------------------------------\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ \"main\"\ function:\ run\ demo\ if\ this\ module\ is\ called\ rather\ than\ sourced\n#-------------------------------------------------------------------------------\nif\ \{\ \[info\ exist\ argv0\]\ &&\ \[info\ script\]\ ==\ \$argv0\ \}\ \{\n\ \ \ \ dictree::main\ \{*\}\$argv\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ end\ of\ file\n#-------------------------------------------------------------------------------\n\n======\n<<discussion>>\n\nSmall\ error\ in\ editing\n\n======\n\ \ \ \ entry\ \$w.e\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ widget\ used\ for\ editing\n======\n\nShould\ be\ \n\n\n======\n\ \ \ \ entry\ \$w.t.e\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ widget\ used\ for\ editing\n======\n\n======\n\[Bezoar\]\ 4/8/2016\ \ \nI\ made\ the\ edits\ for\ the\ errors\ above\ in\ the\ code\ to\ allow\ the\ widget\ to\ work\ right\ out\ of\ the\ box.\ I\ also\ changed\ binding\ to\ edit\ value\ from\ Alt-F2\ to\ Shift-F2\n\n<<categories>>Command\ |\ Editor\ utility\ |\ GUI\ |\ Widget regexp2} CALL {my render dictree '''\[AMW\]'''\ Inspired\ by\ \[eDictor\],\ today\ I\ created\ the\ '''dictree'''\ \[megawidget\]\ using\ a\ \[ttk::treeview\]\ to\ display\ and\ edit\ the\ content\ of\ a\ \[dict\].\n\n'''Example\ Usage:'''\n======\n\ \ \ \ #\ create\ a\ sample\ dict\ with\ some\ data:\n\ \ \ \ dict\ set\ d\ author\ firstname\ \"Alexander\"\n\ \ \ \ dict\ set\ d\ author\ surname\ \ \ \"Mlynski-Wiese\"\n\ \ \ \ dict\ set\ d\ date\ \ \ \"2012-12-21\"\n\ \ \ \ dict\ set\ d\ prog\ name\ \ \ \ \"dictree\"\n\ \ \ \ dict\ set\ d\ prog\ version\ 1.1\n\ \ \ \ #\ -->\ author\ \{firstname\ Alexander\ surname\ Mlynski-Wiese\}\ date\ 2012-12-21\ prog\ \{name\ dictree\ version\ 1.1\}\n\n\ \ \ \ #\ create\ the\ widget\ and\ populate\ it\ with\ the\ dict\ data:\n\ \ \ \ dictree\ .t\ \$d\n\n\ \ \ \ #\ display\ the\ widget:\n\ \ \ \ pack\ .t\ -expand\ yes\ -fill\ both\n======\n\nThe\ widget\ will\ dive\ as\ deeply\ as\ possible\ into\ the\ data\ by\ interpreting\ it\ as\ nested\ dictionary\ whereever\ possible.\n\n\[dictree_screenshot\]\n\nIf\ you\ do\ not\ want\ this\ kind\ interpretation\ for\ any\ node,\ just\ press\ '''Alt'''\ and\ '''click'''\ on\ the\ node\ with\ the\ mouse,\ and\ it\ will\ collapse\ into\na\ leaf.<<br>>Click\ again\ to\ expand\ it\ to\ a\ node\ with\ children\ again.\n\nAlternatively,\ press\ '''Alt+Enter'''\ to\ collapse/expand\ the\ selected\ node\ in\ this\ sense.\n\nThe\ following\ keys\ allow\ modification\ of\ the\ data:\n\ \ \ \ *\ '''Alt+Up/Down'''\ moves\ the\ selected\ node\ up\ or\ down\ within\ it's\ current\ hierarchy\ level\n\ \ \ \ *\ '''Alt+Left/Right'''\ raises\ or\ lowers\ the\ selected\ node\ to\ the\ next\ hierarchy\ level\n\ \ \ \ *\ '''F2'''\ will\ allow\ modification\ of\ the\ selected\ node's\ name\n\ \ \ \ *\ '''Shift+F2'''\ will\ allow\ to\ edit\ the\ selected\ node's\ value\ (only\ if\ it\ is\ a\ leaf)\n\ \ \ \ *\ '''Delete'''\ will\ delete\ the\ selected\ node(s)\n\ \ \ \ *\ '''Insert'''\ will\ insert\ a\ new\ node\ as\ a\ sibbling\ before\ the\ selected\ node\n\ \ \ \ *\ '''Alt+Insert'''\ will\ insert\ a\ new\ node\ as\ a\ sibbling\ after\ the\ selected\ node\n\nAfter\ editing,\ you\ can\ 'reap'\ the\ tree\ to\ return\ the\ content\ as\ a\ dict:\n======\n\ \ \ \ set\ edited_d\ \[.t\ reap\]\n======\n\n-----\n***Possible\ Enhancements***\n\ \ \ \ *\ on\ right-button\ click,\ show\ a\ context\ menue\ to\ add/delete/edit/move\ the\ node\n\ \ \ \ *\ drag\ and\ drop\ of\ node\n\n-----\n***Code***\nThe\ code\ below\ can\ be\ used\ \n\ \ \ \ *\ as\ a\ '''package'''\ within\ other\ projects,\ or\ \n\ \ \ \ *\ as\ a\ '''standalone'''\ application\n\ \ \ \ **\ to\ display\ a\ dict\ loaded\ from\ a\ file\ \n\ \ \ \ **\ to\ fill\ a\ demo\ dictionary\ with\ directory\ information\ and\ display\ it\ using\ '''dictree'''\n\n<<discussion>>\ dictree.tcl\n======\n#===============================================================================\n#\ \ dictree\ widget\ \ \ \ \ \ \ \ display\ and\ edit\ dictionary\ data\ in\ ttk::treeview\n#\n#\ \ 21.12.2012,\ Alexander\ Mlynski-Wiese\n#===============================================================================\n\npackage\ require\ Tcl\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 8.5\npackage\ require\ Tk\npackage\ require\ Ttk\n\npackage\ provide\ dictree\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1.0\n\n#-------------------------------------------------------------------------------\n#\ \ dictree\ w\ d\n#\ \ create\ a\ treeview\ widget\ with\ the\ pathname\ \$w\n#\ \ and\ fill\ it\ with\ the\ dictionary\ data\ \$d\n#-------------------------------------------------------------------------------\nproc\ dictree\ \{\ w\ d\ args\ \}\ \{\n\n\ \ \ \ frame\ \$w\n\ \ \ \ ttk::treeview\ \$w.t\ -columns\ \{key\ value\}\ -displaycolumns\ value\ \ \ \ \ \ \ \ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -yscroll\ \"\$\{w\}.sby\ set\"\ -xscroll\ \"\$\{w\}.sbx\ set\"\n\n\ \ \ \ if\ \{\[tk\ windowingsystem\]\ ne\ \"aqua\"\}\ \{\n\ \ \ \ \ \ \ \ ttk::scrollbar\ \$\{w\}.sby\ -orient\ vertical\ \ \ -command\ \"\$w.t\ yview\"\n\ \ \ \ \ \ \ \ ttk::scrollbar\ \$\{w\}.sbx\ -orient\ horizontal\ -command\ \"\$w.t\ xview\"\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ scrollbar\ \$\{w\}.sby\ -orient\ vertical\ \ \ -command\ \"\$w.t\ yview\"\n\ \ \ \ \ \ \ \ scrollbar\ \$\{w\}.sbx\ -orient\ horizontal\ -command\ \"\$w.t\ xview\"\n\ \ \ \ \}\n\n\ \ \ \ \$w.t\ heading\ \\#0\ \ \ -text\ \"Directory\ Key(s)\"\n\ \ \ \ \$w.t\ heading\ value\ -text\ \"Value\"\n\n\ \ \ \ entry\ \$w.e\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ widget\ used\ for\ editing\n\n\ \ \ \ grid\ \$w.t\ \ \ \ -row\ 0\ -column\ 0\ -sticky\ news\n\ \ \ \ grid\ \$w.sby\ \ -row\ 0\ -column\ 1\ -sticky\ ns\ \ \ \ \ \ \ \ \;#\ arrange\ the\ scrollbars\n\ \ \ \ grid\ \$w.sbx\ \ -row\ 1\ -column\ 0\ -sticky\ ew\n\ \ \ \ grid\ rowconfigure\ \ \ \ \ \ \ \ \ \ \$w\ 0\ -weight\ 1\n\ \ \ \ grid\ columnconfigure\ \$w\ 0\ -weight\ 1\n\n\ \ \ \ dictree::bindings\ \$w.t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ create\ the\ bindings\n\n\ \ \ \ dict\ for\ \{key\ val\}\ \$d\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ populate\ the\ treeview\n\ \ \ \ \ \ \ \ dictree::addNode\ \$w.t\ \"\"\ \$key\ \$val\n\ \ \ \ \}\n\n\ \ \ \ #-----------------------------------------------------------------------\n\ \ \ \ #\ \ \"overload\"\ the\ widget\ proc\ to\ support\ additional\ commands\n\ \ \ \ #-----------------------------------------------------------------------\n\ \ \ \ rename\ \$w\ _\$w\n\ \ \ \ proc\ \$w\ \{cmd\ args\}\ \{\n\ \ \ \ \ \ \ \ set\ self\ \[lindex\ \[info\ level\ 0\]\ 0\]\ \;#\ get\ name\ I\ was\ called\ with\n\ \ \ \ \ \ \ \ switch\ --\ \$cmd\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ reap\ \ \ \ \{uplevel\ 1\ dictree::reap\ \$self.t\ \$args\ \}\n\ \ \ \ \ \ \ \ \ \ \ \ default\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[catch\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uplevel\ 1\ _\$self\ \$cmd\ \$args\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uplevel\ 1\ \$self.t\ \$cmd\ \$args\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\n\ \ \ \ return\ \$w\n\}\n\nnamespace\ eval\ dictree\ \{\ \ \ \ \ \ \ \ \;#\ \"private\"\ functions\n#-------------------------------------------------------------------------------\n#\ \ bindings\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ create\ the\ bindings\ for\ the\ treeview\n#-------------------------------------------------------------------------------\nproc\ bindings\ \{\ w\ \{\ debug\ 0\ \}\ \}\ \{\n\n\ \ \ \ bind\ \$w\ <plus>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::setopen\ %W\ \[%W\ selection\]\ 1\ \}\n\ \ \ \ bind\ \$w\ <minus>\ \ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::setopen\ %W\ \[%W\ selection\]\ 0\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-plus>\ \ \ \ \ \ \ \ \ \ \{\ dictree::expand\ \ \ %W\ \[%W\ selection\]\ \}\n\ \ \ \ bind\ \$w\ <Alt-minus>\ \ \ \ \ \ \ \ \ \{\ dictree::collapse\ %W\ \[%W\ selection\]\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-ButtonPress-1>\ \{\ dictree::toggle\ %W\ \[%W\ identify\ item\ %x\ %y\]\ \}\n\ \ \ \ bind\ \$w\ <Alt-Return>\ \ \ \ \ \ \ \ \{\ dictree::toggle\ %W\ \[%W\ selection\]\;\ break\ \}\n\n\ \ \ \ bind\ \$w\ <F2>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::edit\ %W\ \[%W\ selection\]\ \"#0\"\ \}\n\ \ \ \ bind\ \$w\ <Shift-F2>\ \ \ \ \ \ \ \ \ \ \{\ dictree::edit\ %W\ \[%W\ selection\]\ \"value\"\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-Up>\ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::move\ %W\ \[%W\ selection\]\ -1\;\ break\ \}\n\ \ \ \ bind\ \$w\ <Alt-Down>\ \ \ \ \ \ \ \ \ \ \{\ dictree::move\ %W\ \[%W\ selection\]\ \ 1\;\ break\ \}\n\n\ \ \ \ bind\ \$w\ <Alt-Left>\ \ \ \ \ \ \ \ \ \ \{\ dictree::rise\ %W\ \[%W\ selection\]\ \ 1\;\ break\ \}\n\ \ \ \ bind\ \$w\ <Alt-Right>\ \ \ \ \ \ \ \ \ \{\ dictree::rise\ %W\ \[%W\ selection\]\ -1\;\ break\ \}\n\n\ \ \ \ bind\ \$w\ <Delete>\ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::delete\ %W\ \[%W\ selection\]\ \}\n\ \ \ \ bind\ \$w\ <Insert>\ \ \ \ \ \ \ \ \ \ \ \ \{\ dictree::insert\ %W\ \[%W\ selection\]\ \}\n\ \ \ \ bind\ \$w\ <Alt-Insert>\ \ \ \ \ \ \ \ \{\ dictree::insert\ %W\ \[%W\ selection\]\ 1\ \}\n\n\ \ \ \ if\ \{\ \$debug\ \}\ \{\n\ \ \ \ \ \ \ \ #\ to\ aid\ developing\ additional\ bindings:\n\ \ \ \ \ \ \ \ bind\ \$w\ <ButtonPress-1>\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ item\ \[%W\ identify\ item\ %x\ %y\]\n\ \ \ \ \ \ \ \ \ \ \ \ puts\ \"%x,%y:\ %W\ item\ \$item:\ \[%W\ item\ \$item\]\"\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ bind\ \$w\ <KeyPress>\ \{\ puts\ %K\ \}\n\ \ \ \ \}\n\n\ \ \ \ return\ \$w\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ addNode\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ recursive\ proc\ to\ create\ and\ fill\ the\ nodes\n#-------------------------------------------------------------------------------\nproc\ addNode\ \{\ w\ parent\ title\ d\ \}\ \{\n\ \ \ \ set\ node\ \[\$w\ insert\ \$parent\ end\ -text\ \$title\]\n\ \ \ \ set\ isdict\ 0\n\ \ \ \ catch\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \[dict\ get\ \$d\]\ ==\ \$d\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ isdict\ 1\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ if\ \{\ \$isdict\}\ \{\n\ \ \ \ \ \ \ \ #\ interpret\ data\ \$d\ as\ a\ dictionary\ and\ create\ a\ subnode\n\ \ \ \ \ \ \ \ dict\ for\ \{key\ val\}\ \$d\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ addNode\ \$w\ \$node\ \$key\ \$val\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ #\ \$d\ is\ not\ a\ dictionary:\ make\ this\ node\ a\ leaf\n\ \ \ \ \ \ \ \ \$w\ set\ \$node\ value\ \$d\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ setopen\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ open/close\ node(s)\n#-------------------------------------------------------------------------------\nproc\ setopen\ \{\ w\ items\ mode\ \}\ \{\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ \$w\ item\ \$item\ -open\ \$mode\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ collapse\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ collapse\ all\ child\ nodes\ and\ make\ node\ \$item\ a\ leaf\n#-------------------------------------------------------------------------------\nproc\ collapse\ \{\ w\ items\ \}\ \{\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ set\ children\ \"\"\n\ \ \ \ \ \ \ \ catch\ \{\ set\ children\ \[\$w\ children\ \$item\]\ \}\n\ \ \ \ \ \ \ \ if\ \{\ \$children\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ value\ \"\"\n\ \ \ \ \ \ \ \ \ \ \ \ foreach\ child\ \[\$w\ children\ \$item\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ collapse\ \$w\ \$child\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ value\ \[\$w\ item\ \$child\ -text\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ value\ \[\$w\ set\ \$child\ value\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ delete\ \$child\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ set\ \$item\ value\ \$value\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ expand\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ possible,\ expand\ leaf\ value\ to\ child\ nodes\n#-------------------------------------------------------------------------------\nproc\ expand\ \{\ w\ items\ \}\ \{\n\ \ \ \ global\ errorInfo\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \[\$w\ children\ \$item\]\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ d\ \[\$w\ set\ \$item\ value\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ isdict\ 0\n\ \ \ \ \ \ \ \ \ \ \ \ catch\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[dict\ get\ \$d\]\ ==\ \$d\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ isdict\ 1\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$isdict\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dict\ for\ \{key\ val\}\ \$d\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ addNode\ \$w\ \$item\ \$key\ \$val\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ set\ \$item\ value\ \"\"\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ toggle\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ toggle\ node(s)\ between\ collapsed\ /\ expanded\n#-------------------------------------------------------------------------------\nproc\ toggle\ \{\ w\ items\ \}\ \{\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \[\$w\ children\ \$item\]\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ collapse\ \$w\ \$item\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ expand\ \$w\ \$item\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ move\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ move\ node\ up/down\ among\ siblings,\ i.e.\ keep\ parent\ node\n#-------------------------------------------------------------------------------\nproc\ move\ \{\ w\ item\ increment\ \}\ \{\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\ \ \ \ set\ parent\ \[\$w\ parent\ \$item\]\n\ \ \ \ set\ index\ \ \[\$w\ index\ \ \$item\]\n\ \ \ \ incr\ index\ \$increment\n\ \ \ \ \$w\ move\ \$item\ \$parent\ \$index\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ adopt\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ move\ item\ to\ new\ parent\n#-------------------------------------------------------------------------------\nproc\ adopt\ \{\ w\ item\ newparent\ newindex\ \}\ \{\n\ \ \ \ set\ name\ \[\$w\ item\ \$item\ -text\]\n\ \ \ \ set\ children\ \[\$w\ children\ \$newparent\]\n\ \ \ \ if\ \{\ \$children\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ return\ 0\n\ \ \ \ \}\n\ \ \ \ foreach\ child\ \$children\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \$name\ ==\ \[\$w\ item\ \$child\ -text\]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ #\ not\ allowed:\ parent\ already\ has\ a\ child\ with\ that\ name\n\ \ \ \ \ \ \ \ \ \ \ \ return\ 0\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ \$w\ move\ \$item\ \$newparent\ \$newindex\n\ \ \ \ \$w\ item\ \$newparent\ -open\ 1\n\ \ \ \ return\ 1\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ rise\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ rise/fall\ one\ level\ in\ the\ hierarchy\n#-------------------------------------------------------------------------------\nproc\ rise\ \{\ w\ item\ increment\ \}\ \{\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\ \ \ \ set\ parent\ \ \[\$w\ parent\ \$item\]\n\n\ \ \ \ if\ \{\ \$increment\ >\ 0\ \}\ \{\n\ \ \ \ \ \ \ \ #\ rise\ in\ the\ hierarchy,\ make\ my\ grandpa\ my\ new\ parent\n\ \ \ \ \ \ \ \ set\ newparent\ \[\$w\ parent\ \$parent\]\ \ \ \ \ \ \ \ \;#\ grandpa\n\ \ \ \ \ \ \ \ set\ newindex\ \ \[\$w\ index\ \ \$parent\]\n\ \ \ \ \ \ \ \ incr\ newindex\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ behind\ my\ old\ parent\n\ \ \ \ \ \ \ \ adopt\ \$w\ \$item\ \$newparent\ \$newindex\n\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ #\ fall\ in\ the\ hierarchy,\ make\ a\ brother\ my\ new\ parent\n\ \ \ \ \ \ \ \ set\ index\ \ \ \ \[\$w\ index\ \$item\]\n\ \ \ \ \ \ \ \ set\ brothers\ \[\$w\ children\ \$parent\]\n\ \ \ \ \ \ \ \ set\ brother\ \ \[lindex\ \$brothers\ \[expr\ \$index-1\]\]\n\n\ \ \ \ \ \ \ \ if\ \{\ \$brother\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[adopt\ \$w\ \$item\ \$brother\ end\]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ foreach\ brother\ \$brothers\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$brother\ !=\ \$item\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \[adopt\ \$w\ \$item\ \$brother\ end\]\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ edit\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ edit\ node\ text\ or\ value\n#-------------------------------------------------------------------------------\nproc\ edit\ \{\ w\ item\ column\ \{\ next\ \"\"\ \}\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\ \ \ \ foreach\ \{bx\ by\ bw\ bh\}\ \[\$w\ bbox\ \$item\ \$column\]\ \{\}\n\ \ \ \ set\ ym\ \[expr\ \$by\ +\ \$bh/2\]\n\ \ \ \ while\ \{\ \$bx\ <\ 50\ &&\ \[\$w\ identify\ element\ \$bx\ \$ym\]\ !=\ \"text\"\ \}\ \{\n\ \ \ \ \ \ \ \ incr\ bx\n\ \ \ \ \ \ \ \ incr\ bw\ -1\n\ \ \ \ \}\n\n\ \ \ \ if\ \{\ \$column\ ==\ \"#0\"\ \}\ \{\n\ \ \ \ \ \ \ \ set\ dictree(\$w,text)\ \[\$w\ item\ \$item\ -text\]\n\ \ \ \ \}\ elseif\ \{\ \[\$w\ children\ \$item\]\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ return\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ set\ dictree(\$w,text)\ \[\$w\ set\ \$item\ \$column\]\n\ \ \ \ \}\n\ \ \ \ set\ parent\ \[winfo\ parent\ \$w\ \]\ \n\ \ \ \ if\ \{\ \[catch\ \{\n\ \ \ \ \ \ \ \ place\ \$parent.e\ -x\ \$bx\ -y\ \$by\ -width\ \$bw\ -height\ \$bh\n\ \ \ \ \}\ \]\ \}\ \{\n\ \ \ \ \ \ \ \ return\n\ \ \ \ \}\n\ \ \ \ \$parent.e\ configure\ -textvariable\ dictree(\$w,text)\ \ \ \ \ \ \ \ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -validate\ key\ \ \ \ \ \ \ \ \ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -validatecommand\ \"dictree::edit_check\ \$parent\ \$item\ \$column\ %P\"\n\ \ \ \ if\ \{\ \$dictree(\$w,text)\ ==\ \"(new)\"\ \}\ \{\n\ \ \ \ \ \ \ \ \$parent.e\ selection\ range\ 0\ end\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \$parent.e\ selection\ clear\n\ \ \ \ \}\n\ \ \ \ \$parent.e\ configure\ -background\ white\n\ \ \ \ \$parent.e\ icursor\ end\n\ \ \ \ focus\ \$parent.e\n\ \ \ \ grab\ \ \$parent.e\n\ \ \ \ bind\ \ \$parent.e\ <Return>\ \"dictree::edit_done\ \$w\ \$item\ \$column\ \$next\"\n\ \ \ \ bind\ \ \$parent.e\ <Escape>\ \"dictree::edit_done\ \$w\ \$item\ \{\}\ \$next\"\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ edit_check\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ check\ if\ name\ is\ allowed\n#-------------------------------------------------------------------------------\nproc\ edit_check\ \{\ w\ item\ column\ value\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ set\ ok\ 1\n\ \ \ \ if\ \{\ \$column\ ==\ \"#0\"\ \}\ \{\n\ \ \ \ \ \ \ \ set\ parent\ \[\$w\ parent\ \$item\]\n\ \ \ \ \ \ \ \ foreach\ child\ \[\$w\ children\ \$parent\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$child\ !=\ \$item\ &&\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[\$w\ item\ \$child\ -text\]\ ==\ \$value\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ ok\ 0\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ set\ parent\ \[winfo\ parent\ \$w\ \]\ \n\ \ \ \ \ \ \ \ if\ \{\ !\ \$ok\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \$w.e\ configure\ -background\ red\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \$w.e\ configure\ -background\ white\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ 1\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ edit_done\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ finish\ editing\n#-------------------------------------------------------------------------------\nproc\ edit_done\ \{\ w\ item\ \{column\ \"\"\ \}\ \{\ next\ \"\"\ \}\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ set\ parent\ \[winfo\ parent\ \$w\ \]\ \n\ \ \ \ if\ \{\ \$column\ !=\ \"\"\ &&\ \[\$parent.e\ cget\ -background\]\ ==\ \"red\"\ \}\ \{\n\ \ \ \ \ \ \ \ return\n\ \ \ \ \}\n\n\ \ \ \ grab\ release\ \$parent.e\n\ \ \ \ focus\ \$w\n\ \ \ \ if\ \{\ \$column\ ==\ \"#0\"\ \}\ \{\n\ \ \ \ \ \ \ \ \$w\ item\ \$item\ -text\ \$dictree(\$w,text)\n\ \ \ \ \}\ elseif\ \{\ \$column\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \$w\ set\ \$item\ \$column\ \$dictree(\$w,text)\n\ \ \ \ \}\n\ \ \ \ place\ forget\ \$parent.e\n\ \ \ \ if\ \{\ \$next\ !=\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ if\ \{\ \$column\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ delete\ \$item\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ selection\ set\ \$dictree(\$w,selection)\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ edit\ \$w\ \$item\ \$next\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ unset\ dictree(\$w,text)\n\ \ \ \ catch\ \{\ unset\ dictree(\$w,selection)\ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ delete\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ delete\ node(s)\ (after\ confirmation)\n#-------------------------------------------------------------------------------\nproc\ delete\ \{\ w\ items\ \}\ \{\n\ \ \ \ set\ count\ \[llength\ \$items\]\n\ \ \ \ set\ msg\ \"Do\ you\ really\ want\ to\ delete\ the\ following\ \"\n\ \ \ \ if\ \{\ \$count\ >\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ append\ msg\ \"\$count\ nodes:\\n\"\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ append\ msg\ \"node:\\n\"\n\ \ \ \ \}\n\ \ \ \ foreach\ item\ \$items\ \{\n\ \ \ \ \ \ \ \ append\ msg\ \"\ \[\$w\ item\ \$item\ -text\]\"\n\ \ \ \ \}\n\ \ \ \ append\ msg\ \"?\"\n\ \ \ \ if\ \{\ \[tk_messageBox\ -title\ \"Delete\ nodes\"\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -icon\ warning\ -message\ \$msg\ -type\ yesno\]\ ==\ \"yes\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ delete\ \$items\n\ \ \ \ \}\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ insert\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ insert\ &\ edit\ new\ node\ before/after\ given\ node\n#-------------------------------------------------------------------------------\nproc\ insert\ \{\ w\ item\ \{\ offset\ 0\ \}\ \}\ \{\n\ \ \ \ global\ dictree\n\ \ \ \ if\ \{\ \$item\ ==\ \"\"\ ||\ \[llength\ \$item\]\ !=\ 1\ \}\ \{\ return\ \}\n\n\ \ \ \ set\ dictree(\$w,selection)\ \[\$w\ selection\]\n\n\ \ \ \ set\ parent\ \[\$w\ parent\ \$item\]\n\ \ \ \ set\ index\ \ \[\$w\ index\ \ \$item\]\n\n\ \ \ \ set\ newidx\ \[expr\ \$index\ +\ \$offset\]\n\ \ \ \ set\ node\ \[\$w\ insert\ \$parent\ \$newidx\ -text\ \"(new)\"\]\n\ \ \ \ \$w\ set\ \$node\ value\ \"(new)\"\n\ \ \ \ \$w\ selection\ set\ \$node\n\ \ \ \ edit\ \$w\ \$node\ \"#0\"\ \"value\"\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ reap\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ the\ content\ of\ the\ treeview\ as\ dictionary\n#-------------------------------------------------------------------------------\nproc\ reap\ \{\ w\ \{\ node\ \"\"\ \}\ \}\ \{\n\ \ \ \ set\ children\ \[\$w\ children\ \$node\]\n\ \ \ \ if\ \{\ \[llength\ \$children\]\ ==\ 0\ \}\ \{\n\ \ \ \ \ \ \ \ set\ value\ \[\$w\ set\ \$node\ value\]\n\ \ \ \ \ \ \ \ dict\ set\ d\ \[\$w\ item\ \$node\ -text\]\ \$value\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ foreach\ child\ \$children\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ value\ \[reap\ \$w\ \$child\]\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\ \$node\ ==\ \"\"\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ d\ \{*\}\$value\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dict\ lappend\ d\ \[\$w\ item\ \$node\ -text\]\ \{*\}\$value\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ \$d\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ dictdir\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ generate\ example\ dict\ with\ filesystem\ info\n#-------------------------------------------------------------------------------\nproc\ dictdir\ \{\ dir\ \}\ \{\n\ \ \ \ set\ d\ \"\"\n\ \ \ \ file\ stat\ \$dir\ fstat\n\ \ \ \ foreach\ item\ \[lsort\ \[array\ names\ fstat\]\]\ \{\n\ \ \ \ \ \ \ \ dict\ set\ d\ .\ \$item\ \$fstat(\$item)\n\ \ \ \ \}\n\ \ \ \ foreach\ subdir\ \[lsort\ \[glob\ -directory\ \$dir\ -nocomplain\ -types\ d\ \"*\"\]\]\ \{\n\ \ \ \ \ \ \ \ dict\ set\ d\ \{*\}\[dictdir\ \$subdir\]\n\ \ \ \ \}\n\ \ \ \ foreach\ fname\ \[lsort\ \[glob\ -directory\ \$dir\ -nocomplain\ -types\ f\ \"*\"\]\]\ \{\n\ \ \ \ \ \ \ \ file\ stat\ \$fname\ fstat\n\ \ \ \ \ \ \ \ #\ sorted:\n\ \ \ \ \ \ \ \ foreach\ item\ \[lsort\ \[array\ names\ fstat\]\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ dict\ set\ d\ \[file\ tail\ \$fname\]\ \$item\ \$fstat(\$item)\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ #\ faster\ but\ unsorted:\n\ \ \ \ \ \ \ \ #\ dict\ set\ d\ \[file\ tail\ \$fname\]\ \[array\ get\ fstat\]\n\ \ \ \ \}\n\ \ \ \ return\ \[list\ \[file\ tail\ \$dir\]/\ \$d\]\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ main\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"main\"\ for\ demo\ program\n#-------------------------------------------------------------------------------\nproc\ main\ \{\ args\ \}\ \{\n\ \ \ \ set\ fname\ \[pwd\]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ default\ to\ current\ dir\n\ \ \ \ if\ \{\ \[llength\ \$args\]\ >=\ 1\ \}\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ check\ for\ commandline\ arg\n\ \ \ \ \ \ \ \ set\ fname\ \[lindex\ \$args\ 0\]\n\ \ \ \ \}\n\ \ \ \ if\ \{\ \[file\ isdirectory\ \$fname\]\ \}\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ directory\ was\ given:\n\ \ \ \ \ \ \ \ set\ d\ \[dictdir\ \$fname\]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ parse\ directory\n\n\ \ \ \ \}\ else\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ file\ was\ given:\n\ \ \ \ \ \ \ \ set\ h\ \[open\ \[lindex\ \$args\ 0\]\ \"r\"\]\ \ \ \ \ \ \ \ \;#\ read\ dict\ from\ file\n\ \ \ \ \ \ \ \ set\ d\ \[read\ \$h\]\n\ \ \ \ \ \ \ \ close\ \$h\n\ \ \ \ \}\n\n\ \ \ \ #\ create\ dictree\ control:\n\ \ \ \ dictree\ .t\ \$d\n\ \ \ \ pack\ .t\ -expand\ yes\ -fill\ both\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ end\ of\ namespace\ dict::\n#-------------------------------------------------------------------------------\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ \"main\"\ function:\ run\ demo\ if\ this\ module\ is\ called\ rather\ than\ sourced\n#-------------------------------------------------------------------------------\nif\ \{\ \[info\ exist\ argv0\]\ &&\ \[info\ script\]\ ==\ \$argv0\ \}\ \{\n\ \ \ \ dictree::main\ \{*\}\$argv\n\}\n\n#-------------------------------------------------------------------------------\n#\ \ end\ of\ file\n#-------------------------------------------------------------------------------\n\n======\n<<discussion>>\n\nSmall\ error\ in\ editing\n\n======\n\ \ \ \ entry\ \$w.e\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ widget\ used\ for\ editing\n======\n\nShould\ be\ \n\n\n======\n\ \ \ \ entry\ \$w.t.e\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \;#\ widget\ used\ for\ editing\n======\n\n======\n\[Bezoar\]\ 4/8/2016\ \ \nI\ made\ the\ edits\ for\ the\ errors\ above\ in\ the\ code\ to\ allow\ the\ widget\ to\ work\ right\ out\ of\ the\ box.\ I\ also\ changed\ binding\ to\ edit\ value\ from\ Alt-F2\ to\ Shift-F2\n\n<<categories>>Command\ |\ Editor\ utility\ |\ GUI\ |\ Widget} CALL {my revision dictree} CALL {::oo::Obj4096633 process revision/dictree} CALL {::oo::Obj4096631 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4