################################################## ################################################## ## ## ## FileDialog - a reusable Tk-widget ## ## login screen ## ## ## ## Version 1.2 ## ## ## ## ## ## Brent B. Powers ## ## Merrill Lynch ## ## powers@swaps-comm.ml.com ## ## ## ## ## ################################################## ################################################## # Change History: # Version 1.0 - Initial implementation # 96 Jan 15 ringger@cs.rochester.edu - Fixed dialogue box creation. # 96 Jan 15 ringger - Added option for selecting directories. # 96 Feb 29 powers - Rewrote and componentized, and added a bunch of # options. Now requires perl 5.002gamma # 96 May 30 mkr- add support for single character navigation within # lists, e.g. typing G in list will navigate to first entry # starting with G # 96 May 30 mkr- fixed problem with click in empty file list # 96 May 31 powers - refixed problem with click in empty list (couldn't # click the first entry in list box) # - altered single character navigation to prevent # nudging the mouse while in an entry from grabbing # focus. # - altered single character navigation to go from # first to next to next to first (et al) # - Finished keyboard navigation with tabs # Version 1.2: # 96 Jun 3 powers - Added Version, ship # Version 1.3 # 96 Jun 9 powers - Added Version, and then fixed the Makefile.PM # # =head1 NAME Tk::FileDialog - A highly configurable File Dialog widget for Perl/Tk. =head1 DESCRIPTION The widget is composed of a number of sub-widgets, namely, a listbox for files and (optionally) directories, an entry for filename, an (optional) entry for pathname, an entry for a filter pattern, a 'ShowAll' checkbox (for enabling display of .* files and directories), and three buttons, namely OK, Rescan, and Cancel. Note that the labels for all subwidgets (including the text for the buttons and Checkbox) are configurable for foreign language support. The Listboxes will respond to characters typed over them with scrolling to the first line that starts with the given character (or next etc. if this character is not present). =head1 SYNOPSIS =over 4 =head2 Usage Description To use FileDialog, simply create your FileDialog objects during initialization (or at least before a Show). When you wish to display the FileDialog, invoke the 'Show' method on the FileDialog object; The method will return either a file name, a path name, or undef. undef is returned only if the user pressed the Cancel button. =head2 Example Code The following code creates a FileDialog and calls it. Note that perl5.002gamma is required. =over 4 =item #!/usr/local/bin/perl -w use Tk; use Tk::FileDialog; use strict; my($main) = MainWindow->new; my($Horiz) = 1; my($fname); my($LoadDialog) = $main->FileDialog(-Title =>'This is my title', -Create => 0); print "Using FileDialog Version ",$LoadDialog->Version,"\n"; $LoadDialog->configure(-FPat => '*pl', -ShowAll => 'NO'); $main->Entry(-textvariable => \$fname) ->pack(-expand => 1, -fill => 'x'); $main->Button(-text => 'Kick me!', -command => sub { $fname = $LoadDialog->Show(-Horiz => $Horiz); if (!defined($fname)) { $fname = "Fine,Cancel, but no Chdir anymore!!!"; $LoadDialog->configure(-Chdir =>'NO'); } }) ->pack(-expand => 1, -fill => 'x'); $main->Checkbutton(-text => 'Horizontal', -variable => \$Horiz) ->pack(-expand => 1, -fill => 'x'); $main->Button(-text => 'Exit', -command => sub { $main->destroy; }) ->pack(-expand => 1, -fill => 'x'); MainLoop; print "Exit Stage right!\n"; exit; =back =back =head1 METHODS =over 4 =item The following non-standard methods may be used with a FileDialog object =item =head2 Show =over 4 Displays the file dialog box for the user to operate. Additional configuration items may be passed in at Show-time In other words, this code snippet: $fd->Show(-Title => 'Ooooh, Preeeeeety!'); is the same as this code snippet: $fd->configure(-Title => 'Ooooh, Preeeeeety!'); $fd->Show; =back =item =head2 Version Returns the current Version of FileDialog =back =head1 CONFIGURATION Any of the following configuration items may be set via the configure (or Show) method, or retrieved via the cget method. =head2 I Flags may be configured with either 1,'true', or 'yes' for 1, or 0, 'false', or 'no' for 0. Any portion of 'true', 'yes', 'false', or 'no' may be used, and case does not matter. =over 4 =item =head2 -Chdir =over 8 =item Enable the user to change directories. The default is 1. If disabled, the directory list box will not be shown. =back =head2 -Create =over 8 =item Enable the user to specify a file that does not exist. If not enabled, and the user specifies a non-existent file, a dialog box will be shown informing the user of the error (This Dialog Box is configurable via the EDlg* switches, below). default: 1 =back =head2 -ShowAll =over 8 =item Determines whether hidden files (.*) are displayed in the File and Directory Listboxes. The default is 0. The Show All Checkbox reflects the setting of this switch. =back =head2 -DisableShowAll =over 8 =item Disables the ability of the user to change the status of the ShowAll flag. The default is 0 (the user is by default allowed to change the status). =back =head2 -Grab =over 8 =item Enables the File Dialog to do an application Grab when displayed. The default is 1. =back =head2 -Horiz =over 8 =item True sets the File List box to be to the right of the Directory List Box. If 0, the File List box will be below the Directory List box. The default is 1. =back =head2 -SelDir =over 8 =item If True, enables selection of a directory rather than a file, and disables the actions of the File List Box. The default is 0. =back =back =head2 I =over 4 =item =head2 -FPat =over 8 =item Sets the default file selection pattern. The default is '*'. Only files matching this pattern will be displayed in the File List Box. =back =head2 -Geometry =over 8 =item Sets the geometry of the File Dialog. Setting the size is a dangerous thing to do. If not configured, or set to '', the File Dialog will be centered. =back =head2 -SelHook =over 8 =item SelHook is configured with a reference to a routine that will be called when a file is chosen. The file is called with a sole parameter of the full path and file name of the file chosen. If the Create flag is disabled (and the user is not allowed to specify new files), the file will be known to exist at the time that SelHook is called. Note that SelHook will also be called with directories if the SelDir Flag is enabled, and that the FileDialog box will still be displayed. The FileDialog box should B be destroyed from within the SelHook routine, although it may generally be configured. SelHook routines return 0 to reject the selection and allow the user to reselect, and any other value to accept the selection. If a SelHook routine returns non-zero, the FileDialog will immediately be withdrawn, and the file will be returned to the caller. There may be only one SelHook routine active at any time. Configuring the SelHook routine replaces any existing SelHook routine. Configuring the SelHook routine with 0 removes the SelHook routine. The default SelHook routine is undef. =back =back =head2 I The following two switches may be used to set default variables, and to get final values after the Show method has returned (but has not been explicitly destroyed by the caller) =over 4 =item B<-File> The file selected, or the default file. The default is ''. B<-Path> The path of the selected file, or the initial path. The default is $ENV{'HOME'}. =back =head2 I For support of internationalization, the text on any of the subwidgets may be changed. =over 4 =item B<-Title> The Title of the dialog box. The default is 'Select File:'. B<-DirLBCaption> The Caption above the Directory List Box. The default is 'Directories'. B<-FileLBCaption> The Caption above the File List Box. The default is 'Files'. B<-FileEntryLabel> The label to the left of the File Entry. The Default is 'Filename:'. B<-PathEntryLabel> The label to the left of the Path Entry. The default is 'Pathname:'. B<-FltEntryLabel> The label to the left of the Filter entry. The default is 'Filter:'. B<-ShowAllLabel> The text of the Show All Checkbutton. The default is 'Show All'. =back =head2 I