| 1 |
#!/usr/bin/perl -w |
| 2 |
# -*- perl -*- |
| 3 |
|
| 4 |
use strict; |
| 5 |
|
| 6 |
use Tk; |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
if (!eval q{ |
| 10 |
use Cwd 'getcwd'; |
| 11 |
use File::Spec; |
| 12 |
use Test::More; |
| 13 |
1; |
| 14 |
}) { |
| 15 |
print "1..0 # skip: no Test::More, Cwd and/or File::Spec modules\n"; |
| 16 |
exit; |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
plan tests => 8; |
| 21 |
|
| 22 |
if (!defined $ENV{BATCH}) { $ENV{BATCH} = 1 } |
| 23 |
|
| 24 |
use_ok('Tk::DirTree'); |
| 25 |
|
| 26 |
my $mw = new MainWindow; |
| 27 |
$mw->geometry("+10+10"); |
| 28 |
$mw->Button( |
| 29 |
-text => 'exit', |
| 30 |
-command => sub { $mw->destroy; }, |
| 31 |
)->pack(qw( -side bottom -pady 6 )); |
| 32 |
my $f = $mw->Scrolled('DirTree', |
| 33 |
-width => 55, |
| 34 |
-height => 33, |
| 35 |
-directory => File::Spec->rootdir(), |
| 36 |
-browsecmd => sub { |
| 37 |
my $currdir = shift; |
| 38 |
diag "You are browsing through <$currdir>"; |
| 39 |
}, |
| 40 |
)->pack(qw( -fill both -expand 1 )); |
| 41 |
pass('after create, with -directory option'); |
| 42 |
my $tree = $f->Subwidget('scrolled'); |
| 43 |
isa_ok($tree, 'Tk::DirTree'); |
| 44 |
|
| 45 |
my $testdir; |
| 46 |
if (eval { require File::Temp; require File::Spec; 1 }) { |
| 47 |
$testdir = File::Temp::tempdir("dirtree-XXXXXX", TMPDIR => 1, CLEANUP => 1); |
| 48 |
if ($testdir) { |
| 49 |
for my $chr (65..90, 97..122, 192..255) { |
| 50 |
my $testsubdir = File::Spec->catfile($testdir, chr($chr)); |
| 51 |
mkdir $testsubdir, 0777; |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
$testdir = getcwd if !$testdir; |
| 56 |
|
| 57 |
$f->configure(-directory => $testdir); |
| 58 |
$mw->update; |
| 59 |
pass("After setting directory to " . $testdir); |
| 60 |
|
| 61 |
{ |
| 62 |
my $d = $mw->DirTreeDialog(-initialdir => getcwd); |
| 63 |
isa_ok($d, "Tk::DirTreeDialog"); |
| 64 |
$mw->after(100, sub { $d->{ok} = 1 }); |
| 65 |
my $got_dir = $d->Show; |
| 66 |
is($got_dir, getcwd, "DirTreeDialog returned expected directory"); |
| 67 |
} |
| 68 |
|
| 69 |
if ($ENV{BATCH}) { |
| 70 |
$mw->after(300, sub { $mw->destroy }); |
| 71 |
} |
| 72 |
pass('before MainLoop'); |
| 73 |
MainLoop; |
| 74 |
pass('after MainLoop'); |
| 75 |
|
| 76 |
__END__ |