| 1 |
package Tk::FileSelect; |
| 2 |
|
| 3 |
use vars qw($VERSION @EXPORT_OK); |
| 4 |
$VERSION = '4.018'; # was: sprintf '4.%03d', q$Revision: #15 $ =~ /\D(\d+)\s*$/; |
| 5 |
@EXPORT_OK = qw(glob_to_re); |
| 6 |
|
| 7 |
use Tk qw(Ev); |
| 8 |
use strict; |
| 9 |
use Carp; |
| 10 |
use base qw(Tk::Toplevel); |
| 11 |
use Tk::widgets qw(LabEntry Button Frame Listbox Scrollbar); |
| 12 |
use File::Basename; |
| 13 |
|
| 14 |
Construct Tk::Widget 'FileSelect'; |
| 15 |
|
| 16 |
use vars qw(%error_text); |
| 17 |
%error_text = ( |
| 18 |
'-r' => 'is not readable by effective uid/gid', |
| 19 |
'-w' => 'is not writeable by effective uid/gid', |
| 20 |
'-x' => 'is not executable by effective uid/gid', |
| 21 |
'-R' => 'is not readable by real uid/gid', |
| 22 |
'-W' => 'is not writeable by real uid/gid', |
| 23 |
'-X' => 'is not executable by real uid/gid', |
| 24 |
'-o' => 'is not owned by effective uid/gid', |
| 25 |
'-O' => 'is not owned by real uid/gid', |
| 26 |
'-e' => 'does not exist', |
| 27 |
'-z' => 'is not of size zero', |
| 28 |
'-s' => 'does not exists or is of size zero', |
| 29 |
'-f' => 'is not a file', |
| 30 |
'-d' => 'is not a directory', |
| 31 |
'-l' => 'is not a link', |
| 32 |
'-S' => 'is not a socket', |
| 33 |
'-p' => 'is not a named pipe', |
| 34 |
'-b' => 'is not a block special file', |
| 35 |
'-c' => 'is not a character special file', |
| 36 |
'-u' => 'is not setuid', |
| 37 |
'-g' => 'is not setgid', |
| 38 |
'-k' => 'is not sticky', |
| 39 |
'-t' => 'is not a terminal file', |
| 40 |
'-T' => 'is not a text file', |
| 41 |
'-B' => 'is not a binary file', |
| 42 |
'-M' => 'has no modification date/time', |
| 43 |
'-A' => 'has no access date/time', |
| 44 |
'-C' => 'has no inode change date/time', |
| 45 |
); |
| 46 |
|
| 47 |
# Documentation after __END__ |
| 48 |
|
| 49 |
sub import { |
| 50 |
if (defined $_[1] and $_[1] eq 'as_default') { |
| 51 |
local $^W = 0; |
| 52 |
package Tk; |
| 53 |
if ($Tk::VERSION < 804) { |
| 54 |
*FDialog = \&Tk::FileSelect::FDialog; |
| 55 |
*MotifFDialog = \&Tk::FileSelect::FDialog; |
| 56 |
} else { |
| 57 |
*tk_getOpenFile = sub { |
| 58 |
Tk::FileSelect::FDialog("tk_getOpenFile", @_); |
| 59 |
}; |
| 60 |
*tk_getSaveFile = sub { |
| 61 |
Tk::FileSelect::FDialog("tk_getSaveFile", @_); |
| 62 |
}; |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
sub Cancel |
| 68 |
{ |
| 69 |
my ($cw) = @_; |
| 70 |
$cw->{Selected} = undef; |
| 71 |
$cw->withdraw unless $cw->cget('-transient'); |
| 72 |
} |
| 73 |
|
| 74 |
sub Accept { |
| 75 |
|
| 76 |
# Accept the file or directory name if possible. |
| 77 |
|
| 78 |
my ($cw) = @_; |
| 79 |
|
| 80 |
my($path, $so) = ($cw->cget('-directory'), $cw->SelectionOwner); |
| 81 |
my $leaf = undef; |
| 82 |
my $leaves; |
| 83 |
|
| 84 |
if (defined $so and |
| 85 |
$so == $cw->Subwidget('dir_list')->Subwidget('listbox')) { |
| 86 |
$leaves = [$cw->Subwidget('dir_list')->getSelected]; |
| 87 |
$leaves = [$cw->Subwidget('dir_entry')->get] if !scalar(@$leaves); |
| 88 |
} else { |
| 89 |
$leaves = [$cw->Subwidget('file_list')->getSelected]; |
| 90 |
$leaves = [$cw->Subwidget('file_entry')->get] if !scalar(@$leaves); |
| 91 |
} |
| 92 |
|
| 93 |
foreach $leaf (@$leaves) |
| 94 |
{ |
| 95 |
if (defined $leaf and $leaf ne '') { |
| 96 |
if (!$cw->cget('-create') || -e "$path/$leaf") |
| 97 |
{ |
| 98 |
foreach (@{$cw->cget('-verify')}) { |
| 99 |
my $r = ref $_; |
| 100 |
if (defined $r and $r eq 'ARRAY') { |
| 101 |
#local $_ = $leaf; # use strict var problem here |
| 102 |
return if not &{$_->[0]}($cw, $path, $leaf, @{$_}[1..$#{$_}]); |
| 103 |
} else { |
| 104 |
my $path_leaf = "$path/$leaf"; |
| 105 |
my $s = eval "$_ \$path_leaf"; |
| 106 |
warn "Error while eval'ing $_ \$path_leaf: $@" if $@; |
| 107 |
if (not $s) { |
| 108 |
my $err; |
| 109 |
if (substr($_,0,1) eq '!') |
| 110 |
{ |
| 111 |
my $t = substr($_,1); |
| 112 |
if (exists $error_text{$t}) |
| 113 |
{ |
| 114 |
$err = $error_text{$t}; |
| 115 |
$err =~ s/\b(?:no|not) //; |
| 116 |
} |
| 117 |
} |
| 118 |
$err = $error_text{$_} unless defined $err; |
| 119 |
$err = "failed '$_' test" unless defined $err; |
| 120 |
$cw->Error("'$leaf' $err."); |
| 121 |
return; |
| 122 |
} |
| 123 |
} |
| 124 |
} # forend |
| 125 |
} |
| 126 |
else |
| 127 |
{ |
| 128 |
unless (-w $path) |
| 129 |
{ |
| 130 |
$cw->Error("Cannot write to $path"); |
| 131 |
return; |
| 132 |
} |
| 133 |
} |
| 134 |
$leaf = $path . '/' . $leaf; |
| 135 |
} else { |
| 136 |
$leaf = undef; |
| 137 |
} |
| 138 |
} |
| 139 |
if (scalar(@$leaves)) |
| 140 |
{ |
| 141 |
my $sm = $cw->Subwidget('file_list')->cget(-selectmode); |
| 142 |
$cw->{Selected} = $leaves; |
| 143 |
my $command = $cw->cget('-command'); |
| 144 |
$command->Call(@{$cw->{Selected}}) if defined $command; |
| 145 |
} |
| 146 |
|
| 147 |
} # end Accept |
| 148 |
|
| 149 |
sub Accept_dir |
| 150 |
{ |
| 151 |
my ($cw,$new) = @_; |
| 152 |
return if !defined $new; |
| 153 |
my $dir = $cw->cget('-directory'); |
| 154 |
$cw->configure(-directory => "$dir/$new"); |
| 155 |
} |
| 156 |
|
| 157 |
sub Populate { |
| 158 |
|
| 159 |
my ($w, $args) = @_; |
| 160 |
|
| 161 |
require Tk::Listbox; |
| 162 |
require Tk::Button; |
| 163 |
require Tk::Dialog; |
| 164 |
require Tk::Toplevel; |
| 165 |
require Tk::LabEntry; |
| 166 |
require Cwd; |
| 167 |
|
| 168 |
$w->SUPER::Populate($args); |
| 169 |
$w->protocol('WM_DELETE_WINDOW' => ['Cancel', $w ]); |
| 170 |
|
| 171 |
$w->{'reread'} = 0; |
| 172 |
$w->withdraw; |
| 173 |
|
| 174 |
# Create directory/filter entry, place at the top. |
| 175 |
my $e = $w->Component( |
| 176 |
LabEntry => 'dir_entry', |
| 177 |
-textvariable => \$w->{DirectoryString}, |
| 178 |
-labelVariable => \$w->{Configure}{-dirlabel}, |
| 179 |
); |
| 180 |
$e->pack(-side => 'top', -expand => 0, -fill => 'x'); |
| 181 |
$e->bind('<Return>' => [$w => 'validateDir', Ev(['get'])]); |
| 182 |
|
| 183 |
# Create file entry, place at the bottom. |
| 184 |
$e = $w->Component( |
| 185 |
LabEntry => 'file_entry', |
| 186 |
-textvariable => \$w->{Configure}{-initialfile}, |
| 187 |
-labelVariable => \$w->{Configure}{-filelabel}, |
| 188 |
); |
| 189 |
$e->pack(-side => 'bottom', -expand => 0, -fill => 'x'); |
| 190 |
$e->bind('<Return>' => [$w => 'validateFile', Ev(['get'])]); |
| 191 |
$e->bind('<FocusIn>' => [$w => 'SelectionClear']); |
| 192 |
|
| 193 |
# Create directory scrollbox, place at the left-middle. |
| 194 |
my $b = $w->Component( |
| 195 |
ScrlListbox => 'dir_list', |
| 196 |
-labelVariable => \$w->{Configure}{-dirlistlabel}, |
| 197 |
-scrollbars => 'se', |
| 198 |
); |
| 199 |
$b->pack(-side => 'left', -expand => 1, -fill => 'both'); |
| 200 |
$b->bind('<Double-Button-1>' => [$w => 'Accept_dir', Ev(['getSelected'])]); |
| 201 |
|
| 202 |
# Add a label. |
| 203 |
|
| 204 |
my $f = $w->Frame(); |
| 205 |
$f->pack(-side => 'right', -fill => 'y', -expand => 0); |
| 206 |
$b = $f->Button('-textvariable' => \$w->{'Configure'}{'-acceptlabel'}, |
| 207 |
-command => [ 'Accept', $w ], |
| 208 |
); |
| 209 |
$b->pack(-side => 'top', -fill => 'x', -expand => 1); |
| 210 |
$b = $f->Button('-textvariable' => \$w->{'Configure'}{'-cancellabel'}, |
| 211 |
-command => [ 'Cancel', $w ], |
| 212 |
); |
| 213 |
$b->pack(-side => 'top', -fill => 'x', -expand => 1); |
| 214 |
$b = $f->Button('-textvariable' => \$w->{'Configure'}{'-resetlabel'}, |
| 215 |
-command => [$w => 'configure','-directory','.'], |
| 216 |
); |
| 217 |
$b->pack(-side => 'top', -fill => 'x', -expand => 1); |
| 218 |
$b = $f->Button('-textvariable' => \$w->{'Configure'}{'-homelabel'}, |
| 219 |
-command => [$w => 'configure','-directory',$ENV{'HOME'}], |
| 220 |
); |
| 221 |
$b->pack(-side => 'top', -fill => 'x', -expand => 1); |
| 222 |
|
| 223 |
# Create file scrollbox, place at the right-middle. |
| 224 |
|
| 225 |
$b = $w->Component( |
| 226 |
ScrlListbox => 'file_list', |
| 227 |
-labelVariable => \$w->{Configure}{-filelistlabel}, |
| 228 |
-scrollbars => 'se', |
| 229 |
); |
| 230 |
$b->pack(-side => 'right', -expand => 1, -fill => 'both'); |
| 231 |
$b->bind('<Double-1>' => [$w => 'Accept']); |
| 232 |
|
| 233 |
# Create -very dialog. |
| 234 |
|
| 235 |
my $v = $w->Component( |
| 236 |
Dialog => 'dialog', |
| 237 |
-title => 'Verify Error', |
| 238 |
-bitmap => 'error', |
| 239 |
-buttons => ['Dismiss'], |
| 240 |
); |
| 241 |
|
| 242 |
$w->ConfigSpecs( |
| 243 |
-width => [ ['file_list','dir_list'], undef, undef, 14 ], |
| 244 |
-height => [ ['file_list','dir_list'], undef, undef, 14 ], |
| 245 |
-directory => [ 'METHOD', undef, undef, '.' ], |
| 246 |
-initialdir => '-directory', |
| 247 |
-filelabel => [ 'PASSIVE', 'fileLabel', 'FileLabel', 'File' ], |
| 248 |
-initialfile => [ 'PASSIVE', undef, undef, '' ], |
| 249 |
-filelistlabel => [ 'PASSIVE', undef, undef, 'Files' ], |
| 250 |
-filter => [ 'METHOD', undef, undef, undef ], |
| 251 |
-defaultextension => [ 'METHOD', undef, undef, undef ], |
| 252 |
-regexp => [ 'METHOD', undef, undef, undef ], |
| 253 |
-dirlistlabel => [ 'PASSIVE', undef, undef, 'Directories'], |
| 254 |
-dirlabel => [ 'PASSIVE', undef, undef, 'Directory'], |
| 255 |
'-accept' => [ 'CALLBACK',undef,undef, undef ], |
| 256 |
-command => [ 'CALLBACK',undef,undef, undef ], |
| 257 |
-transient => [ 'PASSIVE', undef, undef, 1 ], |
| 258 |
-verify => [ 'PASSIVE', undef, undef, ['!-d'] ], |
| 259 |
-create => [ 'PASSIVE', undef, undef, 0 ], |
| 260 |
-acceptlabel => [ 'PASSIVE', undef, undef, 'Accept'], |
| 261 |
-cancellabel => [ 'PASSIVE', undef, undef, 'Cancel'], |
| 262 |
-resetlabel => [ 'PASSIVE', undef, undef, 'Reset'], |
| 263 |
-homelabel => [ 'PASSIVE', undef, undef, 'Home'], |
| 264 |
DEFAULT => [ 'file_list' ], |
| 265 |
); |
| 266 |
$w->Delegates(DEFAULT => 'file_list'); |
| 267 |
|
| 268 |
return $w; |
| 269 |
|
| 270 |
} # end Populate |
| 271 |
|
| 272 |
sub translate |
| 273 |
{ |
| 274 |
my ($bs,$ch) = @_; |
| 275 |
return "\\$ch" if (length $bs); |
| 276 |
return '.*' if ($ch eq '*'); |
| 277 |
return '.' if ($ch eq '?'); |
| 278 |
return "\\." if ($ch eq '.'); |
| 279 |
return "\\/" if ($ch eq '/'); |
| 280 |
return "\\\\" if ($ch eq '\\'); |
| 281 |
return $ch; |
| 282 |
} |
| 283 |
|
| 284 |
sub glob_to_re |
| 285 |
{ |
| 286 |
my $regex = shift; |
| 287 |
$regex =~ s/(\\?)(.)/&translate($1,$2)/ge; |
| 288 |
return sub { shift =~ /^${regex}$/ }; |
| 289 |
} |
| 290 |
|
| 291 |
sub filter |
| 292 |
{ |
| 293 |
my ($cw,$val) = @_; |
| 294 |
my $var = \$cw->{Configure}{'-filter'}; |
| 295 |
if (@_ > 1 || !defined($$var)) |
| 296 |
{ |
| 297 |
$val = '*' unless defined $val; |
| 298 |
$$var = $val; |
| 299 |
$cw->{'match'} = glob_to_re($val) unless defined $cw->{'match'}; |
| 300 |
unless ($cw->{'reread'}++) |
| 301 |
{ |
| 302 |
$cw->Busy; |
| 303 |
$cw->afterIdle(['reread',$cw,$cw->cget('-directory')]) |
| 304 |
} |
| 305 |
} |
| 306 |
return $$var; |
| 307 |
} |
| 308 |
|
| 309 |
sub regexp |
| 310 |
{ |
| 311 |
my ($cw,$val) = @_; |
| 312 |
my $var = \$cw->{Configure}{'-regexp'}; |
| 313 |
if (@_ > 1) |
| 314 |
{ |
| 315 |
$$var = $val; |
| 316 |
$cw->{'match'} = (defined $val) ? sub { shift =~ m|^${val}$| } : sub { 1 }; |
| 317 |
unless ($cw->{'reread'}++) |
| 318 |
{ |
| 319 |
$cw->Busy; |
| 320 |
$cw->afterIdle(['reread',$cw]) |
| 321 |
} |
| 322 |
} |
| 323 |
return $$var; |
| 324 |
} |
| 325 |
|
| 326 |
sub defaultextension |
| 327 |
{ |
| 328 |
my ($cw,$val) = @_; |
| 329 |
if (@_ > 1) |
| 330 |
{ |
| 331 |
$val = '' unless defined $val; |
| 332 |
$val = ".$val" if ($val !~ /^\./); |
| 333 |
$cw->filter("*$val"); |
| 334 |
} |
| 335 |
else |
| 336 |
{ |
| 337 |
$val = $cw->filter; |
| 338 |
my ($ext) = $val =~ /(\.[^\.]*)$/; |
| 339 |
return $ext; |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
sub directory |
| 344 |
{ |
| 345 |
my ($cw,$dir) = @_; |
| 346 |
my $var = \$cw->{Configure}{'-directory'}; |
| 347 |
if (@_ > 1 && defined $dir) |
| 348 |
{ |
| 349 |
if (substr($dir,0,1) eq '~') |
| 350 |
{ |
| 351 |
if (substr($dir,1,1) eq '/') |
| 352 |
{ |
| 353 |
$dir = (defined $ENV{'HOME'} ? $ENV{'HOME'} : '') . substr($dir,1); |
| 354 |
} |
| 355 |
else |
| 356 |
{my ($uid,$rest) = ($dir =~ m#^~([^/]+)(/.*$)#); |
| 357 |
$dir = (getpwnam($uid))[7] . $rest; |
| 358 |
} |
| 359 |
} |
| 360 |
my $revert_dir = sub |
| 361 |
{ |
| 362 |
my $message = shift; |
| 363 |
$$var = $cw->{OldDirectory}; |
| 364 |
$cw->messageBox(-message => $message, -icon => 'error'); |
| 365 |
if (!defined $$var) |
| 366 |
{ |
| 367 |
# OldDirectory was never set, so force reread... |
| 368 |
$$var = $cw->{OldDirectory} = Cwd::getcwd(); # XXX maybe use check like code below... |
| 369 |
unless ($cw->{'reread'}++) |
| 370 |
{ |
| 371 |
$cw->Busy; |
| 372 |
$cw->afterIdle(['reread',$cw]) |
| 373 |
} |
| 374 |
} |
| 375 |
$$var; |
| 376 |
}; |
| 377 |
$dir =~ s#([^/\\])[\\/]+$#$1#; |
| 378 |
if (-d $dir) |
| 379 |
{ |
| 380 |
unless (Tk::tainting()) |
| 381 |
{ |
| 382 |
my $pwd = Cwd::getcwd(); |
| 383 |
if (chdir( (defined($dir) ? $dir : '') ) ) |
| 384 |
{ |
| 385 |
my $new = Cwd::getcwd(); |
| 386 |
if ($new) |
| 387 |
{ |
| 388 |
$dir = $new; |
| 389 |
} |
| 390 |
else |
| 391 |
{ |
| 392 |
return $revert_dir->("Cannot getcwd in '$dir'"); |
| 393 |
} |
| 394 |
if (!chdir($pwd)) |
| 395 |
{ |
| 396 |
return $revert_dir->("Cannot change directory to $pwd:\n$!"); |
| 397 |
} |
| 398 |
$$var = $dir; |
| 399 |
} |
| 400 |
else |
| 401 |
{ |
| 402 |
return $revert_dir->("Cannot change directory to $dir:\n$!"); |
| 403 |
} |
| 404 |
$$var = $cw->{OldDirectory} = $dir; |
| 405 |
} |
| 406 |
unless ($cw->{'reread'}++) |
| 407 |
{ |
| 408 |
$cw->Busy; |
| 409 |
$cw->afterIdle(['reread',$cw]) |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
return $$var; |
| 414 |
} |
| 415 |
|
| 416 |
sub reread |
| 417 |
{ |
| 418 |
my ($w) = @_; |
| 419 |
my $dir = $w->cget('-directory'); |
| 420 |
if (defined $dir) |
| 421 |
{ |
| 422 |
if (!defined $w->cget('-filter') or $w->cget('-filter') eq '') |
| 423 |
{ |
| 424 |
$w->configure('-filter', '*'); |
| 425 |
} |
| 426 |
my $dl = $w->Subwidget('dir_list'); |
| 427 |
$dl->delete(0, 'end'); |
| 428 |
$dl->selectionClear(0,'end'); |
| 429 |
my $fl = $w->Subwidget('file_list'); |
| 430 |
$fl->delete(0, 'end'); |
| 431 |
local *DIR; |
| 432 |
if (opendir(DIR, $dir)) |
| 433 |
{ |
| 434 |
my $file = $w->cget('-initialfile'); |
| 435 |
my $seen = 0; |
| 436 |
my $accept = $w->cget('-accept'); |
| 437 |
foreach my $f (sort(readdir(DIR))) |
| 438 |
{ |
| 439 |
next if ($f eq '.'); |
| 440 |
my $path = "$dir/$f"; |
| 441 |
if (-d $path) |
| 442 |
{ |
| 443 |
$dl->insert('end', $f); |
| 444 |
} |
| 445 |
else |
| 446 |
{ |
| 447 |
if (&{$w->{match}}($f)) |
| 448 |
{ |
| 449 |
if (!defined($accept) || $accept->Call($path)) |
| 450 |
{ |
| 451 |
$seen = $fl->index('end') if ($file && $f eq $file); |
| 452 |
$fl->insert('end', $f) |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
} |
| 457 |
closedir(DIR); |
| 458 |
if ($seen) |
| 459 |
{ |
| 460 |
$fl->selectionSet($seen); |
| 461 |
$fl->see($seen); |
| 462 |
} |
| 463 |
else |
| 464 |
{ |
| 465 |
$w->configure(-initialfile => undef) unless $w->cget('-create'); |
| 466 |
} |
| 467 |
} |
| 468 |
$w->{DirectoryString} = $dir . ($dir ne '/' ? '/' : '') . $w->cget('-filter'); |
| 469 |
} |
| 470 |
$w->{'reread'} = 0; |
| 471 |
$w->Unbusy if $w->{'Busy'}; |
| 472 |
} |
| 473 |
|
| 474 |
sub validateDir |
| 475 |
{ |
| 476 |
my ($cw,$name) = @_; |
| 477 |
my ($leaf,$base) = fileparse($name); |
| 478 |
if ($leaf =~ /[*?]/) |
| 479 |
{ |
| 480 |
$cw->configure('-directory' => $base,'-filter' => $leaf); |
| 481 |
} |
| 482 |
else |
| 483 |
{ |
| 484 |
$cw->configure('-directory' => $name); |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
sub validateFile |
| 489 |
{ |
| 490 |
my ($cw,$name) = @_; |
| 491 |
my $i = 0; |
| 492 |
my $n = $cw->index('end'); |
| 493 |
# See if it is an existing file |
| 494 |
for ($i= 0; $i < $n; $i++) |
| 495 |
{ |
| 496 |
my $f = $cw->get($i); |
| 497 |
if ($f eq $name) |
| 498 |
{ |
| 499 |
$cw->selection('set',$i); |
| 500 |
$cw->Accept; |
| 501 |
} |
| 502 |
} |
| 503 |
# otherwise allow if -create is set, directory is writable |
| 504 |
# and it passes filter and accept criteria |
| 505 |
if ($cw->cget('-create')) |
| 506 |
{ |
| 507 |
my $path = $cw->cget('-directory'); |
| 508 |
if (-w $path) |
| 509 |
{ |
| 510 |
if (&{$cw->{match}}($name)) |
| 511 |
{ |
| 512 |
my $accept = $cw->cget('-accept'); |
| 513 |
my $full = "$path/$name"; |
| 514 |
if (!defined($accept) || $accept->Call($full)) |
| 515 |
{ |
| 516 |
$cw->{Selected} = [$full]; |
| 517 |
$cw->Callback(-command => @{$cw->{Selected}}); |
| 518 |
} |
| 519 |
else |
| 520 |
{ |
| 521 |
$cw->Error("$name is not 'acceptable'"); |
| 522 |
} |
| 523 |
} |
| 524 |
else |
| 525 |
{ |
| 526 |
$cw->Error("$name does not match '".$cw->cget('-filter').'\''); |
| 527 |
} |
| 528 |
} |
| 529 |
else |
| 530 |
{ |
| 531 |
$cw->Error("Directory '$path' is not writable"); |
| 532 |
return; |
| 533 |
} |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
sub Error |
| 538 |
{ |
| 539 |
my $cw = shift; |
| 540 |
my $msg = shift; |
| 541 |
my $dlg = $cw->Subwidget('dialog'); |
| 542 |
$dlg->configure(-text => $msg); |
| 543 |
$dlg->Show; |
| 544 |
} |
| 545 |
|
| 546 |
sub Show |
| 547 |
{ |
| 548 |
my ($cw,@args) = @_; |
| 549 |
if ($cw->cget('-transient')) { |
| 550 |
$cw->Popup(@args); |
| 551 |
$cw->focus; |
| 552 |
$cw->waitVariable(\$cw->{Selected}); |
| 553 |
$cw->withdraw; |
| 554 |
return defined($cw->{Selected}) |
| 555 |
? (wantarray) ? @{$cw->{Selected}} : $cw->{Selected}[0] |
| 556 |
: undef; |
| 557 |
} else { |
| 558 |
$cw->Popup(@args); |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
sub FDialog |
| 563 |
{ |
| 564 |
my($cmd, %args) = @_; |
| 565 |
if ($cmd =~ /Save/) |
| 566 |
{ |
| 567 |
$args{-create} = 1; |
| 568 |
$args{-verify} = [qw(!-d -w)]; |
| 569 |
} |
| 570 |
delete $args{-filetypes}; |
| 571 |
delete $args{-force}; |
| 572 |
Tk::DialogWrapper('FileSelect',$cmd, %args); |
| 573 |
} |
| 574 |
|
| 575 |
1; |
| 576 |
|
| 577 |
__END__ |
| 578 |
|