NAME

Tk::FileBrowser - Advanced file system explorer

SYNOPSIS

require Tk::FileBrowser;
my $b = $window->FileBrowser(@options)->pack;
$b->load($folder);

DESCRIPTION

A multicolumn file browser widget. Columns are configurable, sortable and resizable.

if you left-click the header bar, you will get a popup menu to configure case dependant sort, directories first and show hidden.

if you left-click the tree widget, you will get a popup menu to open the current selected entry.

CONFIG VARIABLES

Switch: -casedependantsort

Default value 0;

If you change the value you have to call refresh to see your changes.

Switch: -columns

Specify a list of column names to display. Only available at create time. Allowed values are 'Accessed', 'Created', 'Link', 'Modified', 'Size' and any you have defined through the -columntypes option.

Default value ['Size', 'Modified'].

The 'Name' column is always present and always first.

Switch: -columntypes

Specify a list of column types you ish to define. Here is an example we use in our test file. I adds the colun 'Big', which marks every entry that is geater than 2048 with an 'X', and sorts on size.

my $fb = $app->FileBrowser(
   -columns => [qw[Size Modified Big]],
   -columntypes => [
      Big => {
         display => sub {
            my ($data) = @_;
             return 'X' if $data->size > 2048;
            return '';
         },
         test => sub {
            my ($data1, $data2) = @_;
            return $fb->testSize($data1, $data2);
         },
      },
   ],
)->pack(
   -expand => 1,
  -fill => 'both',
);
Switch: -compactimage

Icon used to represent the compact view mode on it's button.

Switch -createfolderbutton

Default value 0. If set a button is displayed on top right allowing the user to create a new folder.

Switch: -detailsimage

Icon used to represent the detailed view mode on it's button.

Switch -dateformat

Defaultvalue: "%Y-%m-%d %H:%M". Specifies how time stamps should be represented.

Switch: -directoriesfirst

Default value 1.

If you change the value you have to call refresh to see your changes.

Switch: -diriconcall

Callback for obtaining the dir icon. By default it is set to a call that returns the default folder.xpm in the Perl/Tk distribution.

Switch: -fileiconcall

Callback for obtaining the file icon. By default it is set to a call that returns the default file.xpm in the Perl/Tk distribution.

Switch: -headermenu

Specifies a list of menuitems for the context menu of the header. By default it is set to a list with checkbuttons entries for -sortcase, -directoriesfirst and -showhidden.

Switch: -iconviewimage

Icon used to represent the icon view mode on it's button.

Switch: -invokefile

This callback is executed when a user double clicks a file.

Switch: -linkiconcall

Callback for obtaining the link icon. By default it is set to a call that returns an xpm inside this module.

Switch: -listmenu

Specifies a list of menuitems for the context menu of the file list. By default it returns a list with a an Open command.

Switch: -loadfilter

Filter applied during load. Default value ''.

Switch: -loadfilterfolders

Specifies if filters are applied to folders during load. Default value 0.

If you change the value you have to call reload to see your changes.

Switch -msgimage

Image displayed in message pop ups. By default set to the Tk info pixmap.

Switch -newfolderimage

Image for the create folder button. By default set to the Tk info pixmap.

Switch -postloadcall

Callback called after a call to load

Switch: -reloadimage

Image for the reload button.

Switch: -showfiles

Default value 1;

If you change the value you have to call reload to see your changes.

Switch: -showfolders

Default value 1;

If you change the value you have to call reload to see your changes.

Switch: -showhidden

Default value 0;

If you change the value you have to call reload to see your changes.

Switch: -sorton

Can be any valid column name. Default value 'Name'.

If you change the value you have to call refresh to see your changes.

Switch: -sortorder

Can be 'ascending' or 'descending'. Default value 'ascending'.

If you change the value you have to call refresh to see your changes.

Switch: -viewmode

Default value 'detailed'. Can be 'compact', 'detailed' or 'icon'. Sets the view mode for displaying list entries.

Switch: -warnimage

Image displayed in warning dialogs. By default set to the 'warning' Pixmap of Tk.

ADVERTISED SUBWIDGETS

Entry

Class Tk::ListEntry.

Tree

Class Tk::ListBrowser.

KEYBINDINGS

CTRL+A

Selects all entries in the root of the list.

CTRL+F

Shows the filter bar.

CTRL+P

Pops a properties window with details about the current selection. A selection must be present.

F5

Reload.

METHODS

collect

Returns a list of all selected files and folders.

folder

Returns the name of the folder loaded. Returns undef if nothing is loaded.

load($folder)

loads $folder into memory and refreshes the display if succesfull.

openFile($file)

Opens $file in the default application of your desktop.

reload

Reloads the current folder, if one is loaded.

COLUMN DEFINITIONS

The -columntypes options allows you to define your own column types. The structure is like this:

my $fb = $app->FileBrowser(
   -columns => [qw[Size Modified MyColumn]],
   -columntypes => [
      MyColumn => {
         display => sub { ... },
         test => sub { ... },
      },
   ],
);

MyColumn is followed by a reference to a hash with the keys display and test. Both keys hold a reference to an anonymous sub.

The display sub receives one argument, a Tk::FirleBrowser::Item object. It should return the string to be displayed in the column.

The test sub receives two arguments, Both a Tk::FirleBrowser::Item object. It should test both objects against each other, taking -sortorder into account. It should return the boolean result of the test.

The methods below can help you writing your own column definitions. Whenever you see $data here, it refers to a Tk::FirleBrowser::Item object.

dateString($type, $data)

Returns the formatted date string of one of the date items in $data; $type can be 'Accessed', 'Created' or 'Modified'.

linkString($data)

Returns the formatted size string to be displayed for $data.

nameString($data)

Returns the name to be displayed for $data.

sizeString($data)

Returns the formatted size string to be displayed for $data.

testDate($type, $data1, $data2)

$type can be 'Accessed', 'Created' or 'Modified'.

Compares the date stamps in $data1 and $data2 and returns true if $data1 wins.

testLink($data1, $data2)

Checks if both $data1 and $data2 represent symbolic links and returns true if $data1 target wins.

testName($data1, $data2)

Compares the names of $data1 and $data2 and returns true if $data1 wins.

testSize($data1, $data2)

Compares the sizes of $data1 and $data2 and returns true if $data1 wins.

testType($data1, $data2)

Compares the mime types of $data1 and $data2 and returns true if $data1 wins.

LICENSE

Same as Perl.

AUTHOR

Hans Jeuken (hanje at cpan dot org)

BUGS AND CAVEATS

Loading and sorting large folders takes ages.

If you find any bugs, please contact the author.

SEE ALSO

Tk::ListBrowser