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

📄 hierarchy.itk

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 ITK
📖 第 1 页 / 共 5 页
字号:
	# Due to a bug in the tk4.2 grid, we have to check the 	# propagation before setting it.  Setting it to the same	# value it already is will cause it to toggle.	#	if {[grid propagate $shell]} {	    grid propagate $shell no	}		$itk_component(list) configure -height 1	$shell configure \		-height [winfo pixels $shell $itk_option(-height)]     } else {	configure -visibleitems $itk_option(-visibleitems)    }}# ------------------------------------------------------------------# OPTION: -visibleitems## Specified the widthxheight in characters and lines for the text.# This option is only administered if the width and height options# are both set to zero, otherwise they take precedence.  With the# visibleitems option engaged, geometry constraints are maintained# only on the text.  The size of the other components such as # labels, margins, and scroll bars, are additive and independent, # effecting the overall size of the scrolled text.  In contrast,# should the width and height options have non zero values, they# are applied to the scrolled text as a whole.  The text is # compressed or expanded to maintain the geometry constraints.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::visibleitems {    if {[regexp {^[0-9]+x[0-9]+$} $itk_option(-visibleitems)]} {	if {($itk_option(-width) == 0) && \		($itk_option(-height) == 0)} {	    set chars [lindex [split $itk_option(-visibleitems) x] 0]	    set lines [lindex [split $itk_option(-visibleitems) x] 1]	    	    set shell [lindex [grid info $itk_component(clipper)] 1]	    #	    # Due to a bug in the tk4.2 grid, we have to check the 	    # propagation before setting it.  Setting it to the same	    # value it already is will cause it to toggle.	    #	    if {! [grid propagate $shell]} {		grid propagate $shell yes	    }	    	    $itk_component(list) configure -width $chars -height $lines	}	    } else {	error "bad visibleitems option\		\"$itk_option(-visibleitems)\": should be\		widthxheight"    }}# ------------------------------------------------------------------# OPTION: -textmenuloadcommand## Dynamically loads the popup menu based on what was selected.## Douglas R. Howard, Jr.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::textmenuloadcommand {}# ------------------------------------------------------------------# OPTION: -imagemenuloadcommand## Dynamically loads the popup menu based on what was selected.## Douglas R. Howard, Jr.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::imagemenuloadcommand {}# ------------------------------------------------------------------#                         PUBLIC METHODS# ------------------------------------------------------------------# ----------------------------------------------------------------------# PUBLIC METHOD: clear## Removes all items from the display including all tags and icons.  # The display will remain empty until the -filter or -querycommand # options are set.# ----------------------------------------------------------------------body iwidgets::Hierarchy::clear {} {    $itk_component(list) configure -state normal -cursor watch    $itk_component(list) delete 1.0 end    $itk_component(list) configure -state disabled -cursor $itk_option(-cursor)        catch {unset _nodes}    catch {unset _text}    catch {unset _tags}    catch {unset _icons}    catch {unset _states}    catch {unset _images}    catch {unset _indents}    return}# ----------------------------------------------------------------------# PUBLIC METHOD: selection option ?uid uid...?## Handles all operations controlling selections in the hierarchy.# Selections may be cleared, added, removed, or queried.  The add and# remove options accept a series of unique ids.# ----------------------------------------------------------------------body iwidgets::Hierarchy::selection {op args} {    switch -- $op {        clear {            $itk_component(list) tag remove hilite 1.0 end            catch {unset _selected}	    return        }        add {            foreach node $args {                set _selected($node) 1                catch {                    $itk_component(list) tag add hilite \			    "$node.first" "$node.last"                }            }        }        remove {            foreach node $args {                catch {                    unset _selected($node)                    $itk_component(list) tag remove hilite \			    "$node.first" "$node.last"                }            }        }	get {	    return [array names _selected]	}        default {            error "bad selection operation \"$op\":\                   should be add, remove, clear or get"        }    }}# ----------------------------------------------------------------------# PUBLIC METHOD: mark option ?arg arg...?## Handles all operations controlling marks in the hierarchy.  Marks may # be cleared, added, removed, or queried.  The add and remove options # accept a series of unique ids.# ----------------------------------------------------------------------body iwidgets::Hierarchy::mark {op args} {    switch -- $op {        clear {            $itk_component(list) tag remove lowlite 1.0 end            catch {unset _marked}	    return        }        add {            foreach node $args {                set _marked($node) 1                catch {                    $itk_component(list) tag add lowlite \			    "$node.first" "$node.last"                }            }        }        remove {            foreach node $args {                catch {                    unset _marked($node)                    $itk_component(list) tag remove lowlite \			    "$node.first" "$node.last"                }            }        }	get {	    return [array names _marked]	}        default {            error "bad mark operation \"$op\":\                   should be add, remove, clear or get"        }    }}# ----------------------------------------------------------------------# PUBLIC METHOD: current## Returns the node that was most recently selected by the right mouse# button when the item menu was posted.  Usually used by the code# in the item menu to figure out what item is being manipulated.# ----------------------------------------------------------------------body iwidgets::Hierarchy::current {} {    return $_posted}# ----------------------------------------------------------------------# PUBLIC METHOD: expand node## Expands the hierarchy beneath the specified node.  Since this can take# a moment for large hierarchies, the cursor will be changed to a watch# during the expansion.# ----------------------------------------------------------------------body iwidgets::Hierarchy::expand {node} {    if {! [info exists _states($node)]} {	error "bad expand node argument: \"$node\", the node doesn't exist"    }    if {!$_states($node) && \	    (([lsearch $_tags($node) branch] != -1) || \	     ([llength [_contents $node]] > 0))} {        $itk_component(list) configure -state normal -cursor watch        update	#	# Get the indentation level for the node.	#        set indent $_indents($node)        set _markers ""        $itk_component(list) mark set insert "$node:start"        _drawLevel $node $indent	#	# Following the draw, all our markers need adjusting.	#        foreach {name index} $_markers {            $itk_component(list) mark set $name $index        }	#	# Set the image to be the open icon, denote the new state,	# and set the cursor back to normal along with the state.	#	$_images($node) configure -image $itk_option(-openicon)        set _states($node) 1        $itk_component(list) configure -state disabled \		-cursor $itk_option(-cursor)    }}# ----------------------------------------------------------------------# PUBLIC METHOD: collapse node## Collapses the hierarchy beneath the specified node.  Since this can # take a moment for large hierarchies, the cursor will be changed to a # watch during the expansion.# ----------------------------------------------------------------------body iwidgets::Hierarchy::collapse {node} {    if {! [info exists _states($node)]} {	error "bad collapse node argument: \"$node\", the node doesn't exist"    }    if {[info exists _states($node)] && $_states($node) && \	    (([lsearch $_tags($node) branch] != -1) || \	     ([llength [_contents $node]] > 0))} {        $itk_component(list) configure -state normal -cursor watch	update	_deselectSubNodes $node        $itk_component(list) delete "$node:start" "$node:end"	catch {$_images($node) configure -image $itk_option(-closedicon)}        set _states($node) 0        $itk_component(list) configure -state disabled \	    -cursor $itk_option(-cursor)    }}# ----------------------------------------------------------------------# PUBLIC METHOD: toggle node## Toggles the hierarchy beneath the specified node.  If the hierarchy# is currently expanded, then it is collapsed, and vice-versa.# ----------------------------------------------------------------------body iwidgets::Hierarchy::toggle {node} {    if {! [info exists _states($node)]} {	error "bad toggle node argument: \"$node\", the node doesn't exist"    }    if {$_states($node)} {        collapse $node    } else {        expand $node    }}# ----------------------------------------------------------------------# PUBLIC METHOD: prune node## Removes a particular node from the hierarchy.# ----------------------------------------------------------------------body iwidgets::Hierarchy::prune {node} {    #    # While we're working, change the state and cursor so we can    # edit the text and give a busy visual clue.    #    $itk_component(list) configure -state normal -cursor watch    #    # Recursively delete all the subnode information from our internal    # arrays and remove all the tags.      #    _deleteNodeInfo $node    #    # If the mark $node:end exists then the node has decendents so    # so we'll remove from the mark $node:start to $node:end in order     # to delete all the subnodes below it in the text.      #     if {[lsearch [$itk_component(list) mark names] $node:end] != -1} {	$itk_component(list) delete $node:start $node:end	$itk_component(list) mark unset $node:end    }     #    # Next we need to remove the node itself.  Using the ranges for    # its tag we'll remove it from line start to the end plus one    # character which takes us to the start of the next node.    #    foreach {start end} [$itk_component(list) tag ranges $node] {	$itk_component(list) delete "$start linestart" "$end + 1 char"    }    #    # Delete the tag for this node.    #    $itk_component(list) tag delete $node    #    # The node must be removed from the list of subnodes for its parent.    # We don't really have a clean way to do upwards referencing, so    # the dirty way will have to do.  We'll cycle through each node    # and if this node is in its list of subnodes, we'll remove it.    #    foreach uid [array names _nodes] {	if {[set index [lsearch $_nodes($uid) $node]] != -1} {	    set _nodes($uid) [lreplace $_nodes($uid) $index $index]	}    }    #    # We're done, so change the state and cursor back to their     # original values.    #    $itk_component(list) configure -state disabled -cursor $itk_option(-cursor)}# ----------------------------------------------------------------------# PUBLIC METHOD: draw ?when?## Performs a complete draw of the entire hierarchy.# ----------------------------------------------------------------------body iwidgets::Hierarchy::draw {{when -now}} {    if {$when == "-eventually"} {        if {$_pending == ""} {            set _pending [after idle [code $this draw -now]]        }        return    } elseif {$when != "-now"} {        error "bad when option \"$when\": should be -eventually or -now"    }    $itk_component(list) configure -state normal -cursor watch    update    $itk_component(list) delete 1.0 end    catch {unset _images}    set _markers ""    _drawLevel "" ""    foreach {name index} $_markers {        $itk_component(list) mark set $name $index    }    $itk_component(list) configure -state disabled -cursor $itk_option(-cursor)    set _pending ""}

⌨️ 快捷键说明

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