| 1 |
# Copyright (c) 1998-2000 by Scriptics Corporation. |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# RCS: @(#) $Id: chooseDirectory.n,v 1.1 2000/01/27 00:23:10 ericm Exp $ |
| 5 |
# |
| 6 |
|
| 7 |
=head1 NAME |
| 8 |
|
| 9 |
Tk::chooseDirectory - pops up a dialog box for the user to select a directory. |
| 10 |
|
| 11 |
=for category Tk Generic Methods |
| 12 |
|
| 13 |
=head1 SYNOPSIS |
| 14 |
|
| 15 |
I<$widget>-E<gt>B<chooseDirectory>( ?I<option value ...>? ); |
| 16 |
|
| 17 |
=head1 DESCRIPTION |
| 18 |
|
| 19 |
The method B<chooseDirectory> is implemented as a perl wrapper on the |
| 20 |
core tk "command" B<tk_chooseDirectory>, and I<$widget> is passed as |
| 21 |
the argument to the hidden B<-parent> option. |
| 22 |
|
| 23 |
The B<chooseDirectory> |
| 24 |
method pops up a dialog box for the user to select a directory. The |
| 25 |
following I<option-value> pairs are possible as command line |
| 26 |
arguments: |
| 27 |
|
| 28 |
=over 4 |
| 29 |
|
| 30 |
=item B<-initialdir> I<dirname> |
| 31 |
|
| 32 |
Specifies that the directories in I<directory> should be displayed |
| 33 |
when the dialog pops up. If this parameter is not specified, then |
| 34 |
the directories in the current working directory are displayed. If the |
| 35 |
parameter specifies a relative path, the return value will convert the |
| 36 |
relative path to an absolute path. This option may not always work on |
| 37 |
the Macintosh. This is not a bug. Rather, the I<General Controls> |
| 38 |
control panel on the Mac allows the end user to override the |
| 39 |
application default directory. |
| 40 |
|
| 41 |
=item B<-parent> $widget |
| 42 |
|
| 43 |
Makes $widget the logical parent of the dialog. The dialog |
| 44 |
is displayed on top of its parent window. |
| 45 |
|
| 46 |
=item B<-title> I<titleString> |
| 47 |
|
| 48 |
Specifies a string to display as the title of the dialog box. If this |
| 49 |
option is not specified, then a default title will be displayed. |
| 50 |
|
| 51 |
=item B<-mustexist> I<boolean> |
| 52 |
|
| 53 |
Specifies whether the user may specify non-existant directories. If |
| 54 |
this parameter is true, then the user may only select directories that |
| 55 |
already exist. The default value is I<false>. |
| 56 |
|
| 57 |
=back |
| 58 |
|
| 59 |
=head1 CAVEATS |
| 60 |
|
| 61 |
Perl does not have a concept of encoded filesystems yet. This means |
| 62 |
that operations on filenames like C<opendir> and C<open> still use |
| 63 |
byte semantics. Tk however uses character semantics internally, which |
| 64 |
means that you can get filenames with the UTF-8 flag set in functions |
| 65 |
like C<chooseDirectory>, C<getOpenFile> and similar. It's the user's |
| 66 |
responsibility to determine the encoding of the underlying filesystem |
| 67 |
and convert the result into bytes, e.g. |
| 68 |
|
| 69 |
use Encode; |
| 70 |
... |
| 71 |
my $dir = $mw->chooseDirectory; |
| 72 |
$dir = encode("windows-1252", $dir); |
| 73 |
opendir DIR, $dir or die $!; |
| 74 |
... |
| 75 |
|
| 76 |
See also L<perlunicode/When Unicode Does Not Happen> and |
| 77 |
L<perltodo/Unicode in Filenames>. |
| 78 |
|
| 79 |
=head1 EXAMPLE |
| 80 |
|
| 81 |
my $dir = $mw->chooseDirectory(-initialdir => '~', |
| 82 |
-title => 'Choose a directory'); |
| 83 |
if (!defined $dir) { |
| 84 |
warn 'No directory selected'; |
| 85 |
} else { |
| 86 |
warn "Selected $dir"; |
| 87 |
} |
| 88 |
|
| 89 |
=head1 SEE ALSO |
| 90 |
|
| 91 |
L<Tk::getOpenFile>, L<Tk::getOpenFile> |
| 92 |
|
| 93 |
=head1 KEYWORDS |
| 94 |
|
| 95 |
directory selection dialog |