⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.tcl

📁 一个用TCL/TK写的用于verilog的集成编辑环境.
💻 TCL
📖 第 1 页 / 共 4 页
字号:
# ------------------------------------------------------------------------------#  Command Tree::_destroy# ------------------------------------------------------------------------------proc Tree::_destroy { path } {    variable $path    upvar 0  $path data    if { $data(upd,afterid) != "" } {        after cancel $data(upd,afterid)    }    if { $data(dnd,afterid) != "" } {        after cancel $data(dnd,afterid)    }    _subdelete $path [lrange $data(root) 1 end]    Widget::destroy $path    unset data    rename $path {}}# ------------------------------------------------------------------------------#  Command Tree::_see# ------------------------------------------------------------------------------proc Tree::_see { path idn side } {    set bbox [$path:cmd bbox $idn]    set scrl [$path:cmd cget -scrollregion]    set ymax [lindex $scrl 3]    set dy   [$path:cmd cget -yscrollincrement]    set yv   [$path yview]    set yv0  [expr {round([lindex $yv 0]*$ymax/$dy)}]    set yv1  [expr {round([lindex $yv 1]*$ymax/$dy)}]    set y    [expr {int([lindex [$path:cmd coords $idn] 1]/$dy)}]    if { $y < $yv0 } {        $path:cmd yview scroll [expr {$y-$yv0}] units    } elseif { $y >= $yv1 } {        $path:cmd yview scroll [expr {$y-$yv1+1}] units    }    set xmax [lindex $scrl 2]    set dx   [$path:cmd cget -xscrollincrement]    set xv   [$path xview]    if { ![string compare $side "right"] } {        set xv1 [expr {round([lindex $xv 1]*$xmax/$dx)}]        set x1  [expr {int([lindex $bbox 2]/$dx)}]        if { $x1 >= $xv1 } {            $path:cmd xview scroll [expr {$x1-$xv1+1}] units        }    } else {        set xv0 [expr {round([lindex $xv 0]*$xmax/$dx)}]        set x0  [expr {int([lindex $bbox 0]/$dx)}]        if { $x0 < $xv0 } {            $path:cmd xview scroll [expr {$x0-$xv0}] units        }    }}# ------------------------------------------------------------------------------#  Command Tree::_recexpand# ------------------------------------------------------------------------------proc Tree::_recexpand { path node expand cmd } {    variable $path    upvar 0  $path data    if { [Widget::getoption $path.$node -open] != $expand } {        Widget::setoption $path.$node -open $expand        if { $cmd != "" } {            uplevel \#0 $cmd $node        }    }    foreach subnode [lrange $data($node) 1 end] {        _recexpand $path $subnode $expand $cmd    }}# ------------------------------------------------------------------------------#  Command Tree::_subdelete# ------------------------------------------------------------------------------proc Tree::_subdelete { path lnodes } {    variable $path    upvar 0  $path data    while { [llength $lnodes] } {        set lsubnodes [list]        foreach node $lnodes {            foreach subnode [lrange $data($node) 1 end] {                lappend lsubnodes $subnode            }            unset data($node)            if { [set win [Widget::getoption $path.$node -window]] != "" } {                destroy $win            }            Widget::destroy $path.$node        }        set lnodes $lsubnodes    }}# ------------------------------------------------------------------------------#  Command Tree::_update_scrollregion# ------------------------------------------------------------------------------proc Tree::_update_scrollregion { path } {    set bd   [expr {2*([$path:cmd cget -borderwidth]+[$path:cmd cget -highlightthickness])}]    set w    [expr {[winfo width  $path] - $bd}]    set h    [expr {[winfo height $path] - $bd}]    set xinc [$path:cmd cget -xscrollincrement]    set yinc [$path:cmd cget -yscrollincrement]    set bbox [$path:cmd bbox all]    if { [llength $bbox] } {        set xs [lindex $bbox 2]        set ys [lindex $bbox 3]        if { $w < $xs } {            set w [expr {int($xs)}]            if { [set r [expr {$w % $xinc}]] } {                set w [expr {$w+$xinc-$r}]            }        }        if { $h < $ys } {            set h [expr {int($ys)}]            if { [set r [expr {$h % $yinc}]] } {                set h [expr {$h+$yinc-$r}]            }        }    }    $path:cmd configure -scrollregion [list 0 0 $w $h]}# ------------------------------------------------------------------------------#  Command Tree::_cross_event# ------------------------------------------------------------------------------proc Tree::_cross_event { path } {    variable $path    upvar 0  $path data    set node [string range [lindex [$path:cmd gettags current] 1] 2 end]    if { [Widget::getoption $path.$node -open] } {        if { [set cmd [Widget::getoption $path -closecmd]] != "" } {            uplevel \#0 $cmd $node        }        Widget::setoption $path.$node -open 0    } else {        if { [set cmd [Widget::getoption $path -opencmd]] != "" } {            uplevel \#0 $cmd $node        }        Widget::setoption $path.$node -open 1    }    _redraw_idle $path 3}# ------------------------------------------------------------------------------#  Command Tree::_draw_node# ------------------------------------------------------------------------------proc Tree::_draw_node { path node x0 y0 deltax deltay padx showlines } {    global   env    variable $path    upvar 0  $path data    set x1 [expr {$x0+$deltax+5}]    set y1 $y0    if { $showlines } {        $path:cmd create line $x0 $y0 $x1 $y0 \            -fill    [Widget::getoption $path -linesfill]   \            -stipple [Widget::getoption $path -linestipple] \            -tags    line    }    $path:cmd create text [expr {$x1+$padx}] $y0 \        -text   [Widget::getoption $path.$node -text] \        -fill   [Widget::getoption $path.$node -fill] \        -font   [Widget::getoption $path.$node -font] \        -anchor w \        -tags   "node n:$node"    set len [expr {[llength $data($node)] > 1}]    set dc  [Widget::getoption $path.$node -drawcross]    set exp [Widget::getoption $path.$node -open]    if { $len && $exp } {        set y1 [_draw_subnodes $path [lrange $data($node) 1 end] \                    [expr {$x0+$deltax}] $y0 $deltax $deltay $padx $showlines]    }    if { [string compare $dc "never"] && ($len || ![string compare $dc "allways"]) } {        if { $exp } {            set bmp [file join $env(BWIDGET_LIBRARY) "images" "minus.xbm"]        } else {            set bmp [file join $env(BWIDGET_LIBRARY) "images" "plus.xbm"]        }        $path:cmd create bitmap $x0 $y0 \            -bitmap     @$bmp \            -background [$path:cmd cget -background] \            -foreground [Widget::getoption $path -linesfill] \            -tags       "cross c:$node" -anchor c    }    if { [set win [Widget::getoption $path.$node -window]] != "" } {        $path:cmd create window $x1 $y0 -window $win -anchor w -tags "win i:$node"    } elseif { [set img [Widget::getoption $path.$node -image]] != "" } {        $path:cmd create image $x1 $y0 -image $img -anchor w -tags "img i:$node"    }    return $y1}# ------------------------------------------------------------------------------#  Command Tree::_draw_subnodes# ------------------------------------------------------------------------------proc Tree::_draw_subnodes { path nodes x0 y0 deltax deltay padx showlines } {    set y1 $y0    foreach node $nodes {        set yp $y1        set y1 [_draw_node $path $node $x0 [expr {$y1+$deltay}] $deltax $deltay $padx $showlines]    }    if { $showlines && [llength $nodes] } {        set id [$path:cmd create line $x0 $y0 $x0 [expr {$yp+$deltay}] \                    -fill    [Widget::getoption $path -linesfill]   \                    -stipple [Widget::getoption $path -linestipple] \                    -tags    line]        $path:cmd lower $id    }    return $y1}# ------------------------------------------------------------------------------#  Command Tree::_update_nodes# ------------------------------------------------------------------------------proc Tree::_update_nodes { path } {    global   env    variable $path    upvar 0  $path data    set deltax [Widget::getoption $path -deltax]    set padx   [Widget::getoption $path -padx]    foreach {node flag} $data(upd,nodes) {        set idn [$path:cmd find withtag "n:$node"]        if { $idn == "" } {            continue        }        set c  [$path:cmd coords $idn]        set x0 [expr {[lindex $c 0]-$padx}]        set y0 [lindex $c 1]        if { $flag & 48 } {            # -window or -image modified            set win  [Widget::getoption $path.$node -window]            set img  [Widget::getoption $path.$node -image]            set idi  [$path:cmd find withtag i:$node]            set type [lindex [$path:cmd gettags $idi] 0]            if { [string length $win] } {                if { ![string compare $type "win"] } {                    $path:cmd itemconfigure $idi -window $win                } else {                    $path:cmd delete $idi                    $path:cmd create window $x0 $y0 -window $win -anchor w -tags "win i:$node"                }            } elseif { [string length $img] } {                if { ![string compare $type "img"] } {                    $path:cmd itemconfigure $idi -image $img                } else {                    $path:cmd delete $idi                    $path:cmd create image $x0 $y0 -image $img -anchor w -tags "img i:$node"                }            } else {                $path:cmd delete $idi            }        }        if { $flag & 8 } {            # -drawcross modified            set len [expr {[llength $data($node)] > 1}]            set dc  [Widget::getoption $path.$node -drawcross]            set exp [Widget::getoption $path.$node -open]            set idc [$path:cmd find withtag c:$node]            if { [string compare $dc "never"] && ($len || ![string compare $dc "allways"]) } {                if { $exp } {                    set bmp [file join $env(BWIDGET_LIBRARY) "images" "minus.xbm"]                } else {                    set bmp [file join $env(BWIDGET_LIBRARY) "images" "plus.xbm"]                }                if { $idc == "" } {                    $path:cmd create bitmap [expr {$x0-$deltax-5}] $y0 \                        -bitmap     @$bmp \                        -background [$path:cmd cget -background] \                        -foreground [Widget::getoption $path -linesfill] \                        -tags       "cross c:$node" -anchor c                } else {                    $path:cmd itemconfigure $idc -bitmap @$bmp                }            } else {                $path:cmd delete $idc            }        }        if { $flag & 7 } {            # -font, -text or -fill modified            $path:cmd itemconfigure $idn \                -text [Widget::getoption $path.$node -text] \                -fill [Widget::getoption $path.$node -fill] \                -font [Widget::getoption $path.$node -font]        }    }}# ------------------------------------------------------------------------------#  Command Tree::_draw_tree# ------------------------------------------------------------------------------proc Tree::_draw_tree { path } {    variable $path    upvar 0  $path data    $path:cmd delete all    $path:cmd configure -cursor watch    _draw_subnodes $path [lrange $data(root) 1 end] 8 \        [expr {-[Widget::getoption $path -deltay]/2}] \        [Widget::getoption $path -deltax] \        [Widget::getoption $path -deltay] \        [Widget::getoption $path -padx]   \        [Widget::getoption $path -showlines]    $path:cmd configure -cursor [Widget::getoption $path -cursor]}# ------------------------------------------------------------------------------#  Command Tree::_redraw_tree# ------------------------------------------------------------------------------proc Tree::_redraw_tree { path } {    variable $path    upvar 0  $path data    if { [Widget::getoption $path -redraw] } {        if { $data(upd,level) == 2 } {            _update_nodes $path        } elseif { $data(upd,level) == 3 } {            _draw_tree $path        }        _redraw_selection $path        _update_scrollregion $path        set data(upd,nodes)   {}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -