Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # HList, a hierarchial listbox widget. |
2 | ||
3 | use Tk::HList; | |
4 | use Cwd; | |
5 | use subs qw/show_dir/; | |
6 | use vars qw/$TOP $FILEIMG $FOLDIMG/; | |
7 | ||
8 | sub HList { | |
9 | my($demo) = @_; | |
10 | $TOP = $MW->WidgetDemo( | |
11 | -name => $demo, | |
12 | -text => 'HList - A hierarchial listbox widget.', | |
13 | -geometry_manager => 'grid', | |
14 | ); | |
15 | ||
16 | my $h = $TOP->Scrolled(qw\HList -separator / -selectmode extended -width 30 | |
17 | -height 20 -indent 35 -scrollbars se | |
18 | -itemtype imagetext \ | |
19 | )->grid(qw/-sticky nsew/); | |
20 | $h->configure(-command => sub { | |
21 | print "Double click $_[0], size=", $h->info('data', $_[0]) ,".\n"; | |
22 | }); | |
23 | ||
24 | $FILEIMG = $TOP->Bitmap(-file => Tk->findINC('file.xbm')); | |
25 | $FOLDIMG = $TOP->Bitmap(-file => Tk->findINC('folder.xbm')); | |
26 | ||
27 | my $root = Tk->findINC('demos'); | |
28 | my $olddir = cwd; | |
29 | chdir $root; | |
30 | show_dir '.', $root, $h; | |
31 | chdir $olddir; | |
32 | my $b = $TOP->Button(-text => 'Select All', -command => [\&select_all, $h]); | |
33 | Tk::grid($b); | |
34 | } | |
35 | ||
36 | sub select_all | |
37 | { | |
38 | my $h = shift; | |
39 | my @list = $h->infoChildren(@_); | |
40 | if (@list) | |
41 | { | |
42 | $h->selectionSet($list[0],$list[-1]); | |
43 | foreach my $e (@list) | |
44 | { | |
45 | select_all($h,$e); | |
46 | } | |
47 | } | |
48 | } | |
49 | ||
50 | sub show_dir { | |
51 | my($entry_path, $text, $h) = @_; | |
52 | opendir H, $entry_path; | |
53 | my(@dirent) = grep ! /^\.\.?$/, sort(readdir H); | |
54 | closedir H; | |
55 | $h->add($entry_path, -text => $text, -image => $FOLDIMG, -data => 'DIR'); | |
56 | while ($_ = shift @dirent) { | |
57 | my $file = "$entry_path/$_"; | |
58 | if (-d $file) { | |
59 | show_dir $file, $_, $h; | |
60 | } else { | |
61 | my $size = -s $file; | |
62 | $h->add($file, -text => $_, -image => $FILEIMG, -data => $size); | |
63 | } | |
64 | } | |
65 | } # end show_dir |