75
77
-textvariable => \$w->{'selectPath'},
76
78
-command => ['SetPath', $w]);
77
79
my $upBtn = $f1->Button;
78
if (!defined $updirImage) {
79
$updirImage = $w->Bitmap(-data => "#define updir_width 28\n" .
80
"#define updir_height 16\n" .
80
if (!defined $updirImage->{$w->MainWindow}) {
81
$updirImage->{$w->MainWindow} = $w->Bitmap(-data => <<EOF);
82
#define updir_width 28
83
#define updir_height 16
82
84
static char updir_bits[] = {
83
85
0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00,
84
86
0x20, 0x40, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x01, 0x10, 0x00, 0x00, 0x01,
88
90
0xf0, 0xff, 0xff, 0x01};
91
$upBtn->configure(-image => $updirImage);
93
$upBtn->configure(-image => $updirImage->{$w->MainWindow});
92
94
$dirMenu->configure(-takefocus => 1, -highlightthickness => 2);
93
95
$upBtn->pack(-side => 'right', -padx => 4, -fill => 'both');
94
96
$lab->pack(-side => 'left', -padx => 4, -fill => 'both');
128
130
-relief => $f2_lab->cget(-relief),
129
131
-padx => $f2_lab->cget(-padx),
130
132
-pady => $f2_lab->cget(-pady),
132
135
$typeMenuLab->bindtags([$typeMenuLab, 'Label',
133
136
$typeMenuLab->toplevel, 'all']);
198
201
$w->SetPath(_cwd());
200
203
$w->ConfigSpecs(-defaultextension => ['PASSIVE', undef, undef, undef],
201
-filetypes => ['PASSIVE', undef, undef, undef],
202
-initialdir => ['PASSIVE', undef, undef, undef],
203
-initialfile => ['PASSIVE', undef, undef, undef],
204
-title => ['PASSIVE', undef, undef, undef],
205
-type => ['PASSIVE', undef, undef, 'open'],
206
-filter => ['PASSIVE', undef, undef, '*'],
207
-force => ['PASSIVE', undef, undef, 0],
208
'DEFAULT' => [$icons],
204
-filetypes => ['PASSIVE', undef, undef, undef],
205
-initialdir => ['PASSIVE', undef, undef, undef],
206
-initialfile => ['PASSIVE', undef, undef, undef],
207
# -sortcmd => ['PASSIVE', undef, undef, sub { lc($a) cmp lc($b) }],
208
-sortcmd => ['PASSIVE', undef, undef, sub { lc($_[0]) cmp lc($_[1]) }],
209
-title => ['PASSIVE', undef, undef, undef],
210
-type => ['PASSIVE', undef, undef, 'open'],
211
-filter => ['PASSIVE', undef, undef, '*'],
212
-force => ['PASSIVE', undef, undef, 0],
213
'DEFAULT' => [$icons],
210
215
# So-far-failed attempt to break reference loops ...
211
216
$w->_OnDestroy(qw(dirMenu icons typeMenuLab typeMenuBtn okBtn ent updateId));
220
# -initialdir fix with ResolveFile
226
231
my $initialdir = $w->cget(-initialdir);
227
232
if (defined $initialdir) {
228
if (-d $initialdir) {
229
$w->{'selectPath'} = $initialdir;
233
my ($flag, $path, $file) = ResolveFile($initialdir, 'junk');
234
if ($flag eq 'OK' or $flag eq 'FILE') {
235
$w->{'selectPath'} = $path;
231
237
$w->Error("\"$initialdir\" is not a valid directory");
286
292
my $ent = $w->{'ent'};
288
294
$ent->delete(0, 'end');
289
$ent->insert(0, $w->{'selectFile'});
290
$ent->selectionFrom(0);
291
$ent->selectionTo('end');
292
$ent->icursor('end');
295
if (defined $w->{'selectFile'} && $w->{'selectFile'} ne '') {
296
$ent->insert(0, $w->{'selectFile'});
297
$ent->selectionFrom(0);
298
$ent->selectionTo('end');
299
$ent->icursor('end');
294
302
# 8. Wait for the user to respond, then restore the focus and
295
303
# return the index of the selected button. Restore the focus
296
304
# before deleting the window, since otherwise the window manager
297
305
# may take the focus away so we can't redirect it. Finally,
298
306
# restore any grab that was in effect.
299
$w->waitVariable(\$selectFilePath);
307
$w->waitVariable(\$w->{'selectFilePath'});
301
309
$oldFocus->focus if $oldFocus;
348
356
delete $w->{'updateId'};
350
unless (defined $folderImage) {
358
unless (defined $folderImage->{$w->MainWindow}) {
351
359
require Tk::Pixmap;
352
$folderImage = $w->Pixmap(-file => Tk->findINC('folder.xpm'));
353
$fileImage = $w->Pixmap(-file => Tk->findINC('file.xpm'));
360
$folderImage->{$w->MainWindow} = $w->Pixmap(-file => Tk->findINC('folder.xpm'));
361
$fileImage->{$w->MainWindow} = $w->Pixmap(-file => Tk->findINC('file.xpm'));
355
my $folder = $folderImage;
356
my $file = $fileImage;
363
my $folder = $folderImage->{$w->MainWindow};
364
my $file = $fileImage->{$w->MainWindow};
357
365
my $appPWD = _cwd();
358
366
if (!ext_chdir($w->{'selectPath'})) {
359
367
# We cannot change directory to $data(selectPath). $data(selectPath)
381
389
$icons->DeleteAll;
383
391
# Make the dir & file list
384
my $flt = join('|', split(' ', $w->cget(-filter)) );
385
$flt =~ s!([\.\+])!\\$1!g;
388
if( opendir( FDIR, _cwd() )) {
390
foreach my $f (sort { lc($a) cmp lc($b) } readdir FDIR) {
391
next if $f eq '.' or $f eq '..';
392
if (-d $f) { $icons->Add($folder, $f); }
393
elsif( $f =~ m!$flt$! ) { push( @files, $f ); }
396
foreach my $f ( @files ) { $icons->Add($file, $f); }
394
if (opendir(FDIR, $cwd)) {
396
# my $sortcmd = $w->cget(-sortcmd);
397
my $sortcmd = sub { $w->cget(-sortcmd)->($a,$b) };
398
my $flt = $w->cget(-filter);
400
if (ref $flt eq 'CODE') {
403
$flt = _rx_to_glob($flt);
405
foreach my $f (sort $sortcmd readdir(FDIR)) {
406
next if $f eq '.' or $f eq '..';
408
next if !$fltcb->($w, $f, $cwd);
410
next if -f $f && $f !~ m!$flt!;
413
$icons->Add($folder, $f);
419
foreach my $f (@files) {
420
$icons->Add($file, $f);
752
778
$w->SetPath($file);
755
$w->{'selectFile'} = $file;
781
my($flag, $path, $file) = ResolveFile($w->{'selectPath'}, $text);
783
$w->messageBox(-type => 'OK',
784
-message => "Cannot resolve $w->{'selectPath'}/$text.",
787
$path = JoinFile($path, $file);