This subroutine runs through all the child nodes of a given entry in a Tk::Tree and hides child nodes and sets their parent node mode to 'open'. The result is a tree with all the top level nodes (with respect to the given entry) shown, but closed and with an open box for any node that has children.
To close all nodes pass an empty string for the entry path (second parameter).
Note that it is assumed that the separator is '/'.
sub closeTree { my $tree = shift; my ($entryPath, $hideChildren) = @_; my @children = $tree->info (children => $entryPath); return if ! @children; for (@children) { closeTree ($tree, $_, 1); $tree->hide ('entry' => $_) if $hideChildren; } $tree->setmode ($entryPath, 'open') if length $entryPath; }
|
|---|