# DirTree -- TixDirTree widget
# Derived from DirTree.tcl in Tix 4.1
# Chris Dean <ctdean@cogit.com>
$VERSION = '3.023'; # $Id: //depot/Tk8/Tixish/DirTree.pm#23 $
use base qw(Tk::Derived Tk::Tree);
Construct Tk
::Widget
'DirTree';
$cw->SUPER::Populate
( $args );
-dircmd
=> [qw
/CALLBACK dirCmd DirCmd DirCmd/],
-showhidden
=> [qw
/PASSIVE showHidden ShowHidden 0/],
-image
=> [qw
/PASSIVE image Image folder/],
-directory
=> [qw
/SETMETHOD directory Directory ./],
-value
=> '-directory' );
$cw->configure( -separator
=> '/', -itemtype
=> 'imagetext' );
my( $w, $dir, $showhidden ) = @_;
my $h = DirHandle
->new( $dir ) or return();
my @names = grep( $_ ne '.' && $_ ne '..', $h->read );
@names = grep( ! /^[.]/, @names ) unless $showhidden;
chdir($cwd) || die "Cannot cd back to $cwd:$!";
warn "Cannot cd to $path:$!"
if (defined $w->cget('-image'))
# We have a default for -image, so its being undefined
# is probably caused by order of handling config defaults
$w->afterIdle([$w, 'chdir' => $val]);
my $fulldir = fullpath
( $val );
if ($fulldir =~ s/^([a-z]:)//i)
$w->add_to_tree( $parent, $parent) unless $w->infoExists($parent);
foreach my $name (split( /[\/\\]/, $fulldir )) {
next unless length $name;
my $dir = join( '/', @dirs );
$w->add_to_tree( $dir, $name, $parent )
unless $w->infoExists( $dir );
$w->setmode( $parent, 'close' );
$dir = '' if $dir eq '/';
foreach my $name ($w->dirnames( $parent )) {
next if ($name eq '.' || $name eq '..');
my $subdir = "$dir/$name";
if( $w->infoExists( $subdir ) ) {
$w->show( -entry
=> $subdir );
$w->add_to_tree( $subdir, $name, $parent );
my( $w, $dir, $name, $parent ) = @_;
my $image = $w->Getimage( $w->cget('-image') );
$mode = 'open' if $w->has_subdir( $dir );
my @args = (-image
=> $image, -text
=> $name);
if( $parent ) { # Add in alphabetical order.
foreach my $sib ($w->infoChildren( $parent )) {
push @args, (-before
=> $sib);
$w->setmode( $dir, $mode );
foreach my $name ($w->dirnames( $dir )) {
next if ($name eq '.' || $name eq '..');
next if ($name =~ /^\.+$/);
return( 1 ) if -d
"$dir/$name";
my @names = $w->Callback( '-dircmd', $dir, $w->cget( '-showhidden' ) );
# Copyright (c) 1996, Expert Interface Technologies
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# The file man.macros and some of the macros used by this file are
# copyrighted: (c) 1990 The Regents of the University of California.
# (c) 1994-1995 Sun Microsystems, Inc.
# The license terms of the Tcl/Tk distrobution are in the file