fltk::FileChooser Class Reference

List of all members.

Public Member Functions

int count ()
void directory (const char *d)
void filter (const char *p)
void preview (bool e)
void rescan ()
int sort_visible () const
void sort_visible (int e)
void value (const char *filename)
const char * value (int f=1)

Private Member Functions

void activate_okButton_if_file ()
void directory (const char *d, bool)
void favoritesButtonCB ()
void favoritesCB (fltk::Widget *w)
void fileListCB ()
void fileNameCB ()
void newdir ()
void showChoiceCB ()
void update_favorites ()
void update_preview ()
void update_sort ()

Static Private Member Functions

static void previewCB (FileChooser *fc)

Detailed Description

The fltk::FileChooser widget displays a standard file selection dialogue that supports various selection modes.

FileChooser.jpg

The fltk::FileChooser class also exports several static values that may be used to localise or customise the appearance of all file chooser dialogues:

Member Default value
add_favorites_label "Add to Favorites"
all_files_label "All Files (*)"
custom_filter_label "Custom Filter"
existing_file_label "Please choose an existing file!"
favorites_label "Favorites"
filename_label "Filename:"
filesystems_label "My Computer" (WIN32)
"File Systems" (all others)
hidden_label "Show hidden files:"
manage_favorites_label "Manage Favorites"
new_directory_label "New Directory?"
new_directory_tooltip "Create a new directory."
preview_label "Preview"
save_label "Save"
show_label "Show:"
sort casenumericsort
sort_menu_label "Sort Method"

The fltk::FileChooser::sort member specifies the sort function that is used when loading the contents of a directory and can be customised at run-time.

For more complex customisation, considering copying the fltk::FileChooser code and modifying it accordingly.


Member Function Documentation

void FileChooser::activate_okButton_if_file ( ) [private]

Activates the OK button if a file is selected.

Returns:
void
int FileChooser::count ( )

Calculate the number of selected files.

Returns:
the number of selected files.
void FileChooser::directory ( const char *  d,
bool  f 
) [private]

Modifies the FileChooser's directory, with the option to modify the displayed "name" field

Updates the FileChooser's current directory by making the filename absolute, stripping trailing '..' or '.'. This also keeps the 'suggested filename' of a file as directories are traversed.

Parameters:
dA const char* containing the FileChooser's new directory
fA boolean representing whether or not to update the displayed filename
Returns:
void
void FileChooser::directory ( const char *  d)

Set the directory in the file chooser.

Modify the FileChooser's current directory.

Parameters:
dThe directory to change to
Returns:
void
See also:
directory(const char* d, bool f)
void FileChooser::favoritesButtonCB ( ) [private]

Handle favorites selections.

This function deals with adding and/or removing favorites from the FileChooser's drop down menu. It allows a user to quickly navigate amongst pre-set or personalised favorite directories.

Returns:
void
void FileChooser::favoritesCB ( fltk::Widget w) [private]

Handle the favorites window

This function creates, populates and navigates the favorites window, opened when a user clicks "Manage Favorites". It allows users to shuffle their favorites in the order of most-used or remove favorites.

Parameters:
wThe clicked-on (or used) widget
See also:
update_favorites()
Returns:
void
void FileChooser::fileListCB ( ) [private]

Handle clicks (and double-clicks) in the FileBrowser.

This function interprets single clicks and double clicks - a single click selects a file whereas a double click either traverses into a directory or assumes the user has selected the file they want

Returns:
void
void FileChooser::fileNameCB ( ) [private]

Handle text entry in the FileChooser.

If a user tries to manually enter a path into the FileChooser's input box, instead of using the FileChooser to navigate, this function will make sure what is entered is in line with what is required by the FileChooser - for instance, it expands ~ to the user's home directory. It also attempts to offer tabcompletion for paths and files.

Returns:
void
void FileChooser::filter ( const char *  p)

Set the filter(s) for the FileChooser.

This function allows the FileChooser to use globs and (eventually) regular expressions to select multiple files of the same filetype or same filename.

Parameters:
pThis const char* represents the pattern to match files against.
Todo:
Full Regex matchings
Returns:
void
void FileChooser::newdir ( ) [private]

Make a new directory.

This function creates a new directory on the user's computer from inside the FileChooser. It also allows the user to name this directory. After this directory is created, the user is moved into this directory.

Returns:
void
void FileChooser::preview ( bool  e)

Enable or disable the preview tile.

The preview tile allows a user to view a 'snapshot' of the file they have currently selected. This loads all forms of files, from images to source code to pdf documents, but requires a SharedImage handler to correctly decypher the file data and then display it as an image.

Parameters:
eA boolean flag representing whether or not to turn previews on. False turns them off, true turns them on.
See also:
SharedImage::add_handler()
Returns:
void
void FileChooser::previewCB ( FileChooser fc) [static, private]

Timeout handler for the preview box.

This function calls update_preview on the FileChooser after a time lapse of half a second from when a file is first selected

Parameters:
fcWhich FileChooser to use
See also:
update_preview()
Returns:
void
void FileChooser::rescan ( )

Rescan the current directory.

This function re-loads the current directory, scanning for new files or folders

Returns:
void
void FileChooser::showChoiceCB ( ) [private]

Handle "Show" menu selections.

This function handles all the options in the drop-down "Show" menu. This also allows users to enter their own manual filename patterns or select from ones previously used.

See also:
filter(const char* p)
Returns:
void
void FileChooser::sort_visible ( int  e)

Toggle the visibility of the sort menu

Parameters:
edetermines whether or not to show the menu
int FileChooser::sort_visible ( ) const

Tests the visility of the sort menu

Returns:
whether or not the sort menu is visible.
void FileChooser::update_favorites ( ) [private]

Update the favorites menu.

This function allows users to add or remove from the favorites menu

See also:
favoritesCB()
Returns:
void
void FileChooser::update_preview ( ) [private]

Update the preview box

This function updates the contents of the preview box with an image, or failing that attempts to load the first 1 kilobyte of a file (if it contains printable characters). Failing this, the function just prints a large "?" in the place of the file to be previewed.

Returns:
void
void FileChooser::update_sort ( ) [private]

Update the sorting method

This function completely re-loads the displayed FileList. This may be slow for large directories as it rescans completely

Todo:
Only resort the contents of the directory, not rescan
const char * FileChooser::value ( int  f = 1)

Return a selected filename.

Finds and then returns the fth file in the directory, where f is the number of the file. If the value of f is higher than the amount of files in the directory, this function returns either the value in the filename field, or failing that, NULL

Parameters:
fThe 'f'th file in the directory
Returns:
The 'f'th filename in the directory. If f is too large, it returns the file listed in the filename field, or NULL if there is no file in the filename field and the 'f'th file doesn't exist.
void FileChooser::value ( const char *  filename)

Set the current filename.

Takes the passed filename and sets the current directory (and filename) to this name. If no name is passed, this function essentially just deactivates the OK button.

Parameters:
filenameThe filename and/or directory
See also:
directory(const char* d, bool f)
Returns:
void

The documentation for this class was generated from the following files: