#include <fltk/NativeFileChooser.h>Dowload latest source from here.
|
If the optional type is not specified, BROWSE_FILE (browse to open a file) is assumed. The type can also be set later with type().
The second form should be used to return multiple filenames, and is normally used inside a loop to retrieve all the files the user selected, eg:
if ( chooser->show() == 0 ) {
// HANDLE MULTIPLE FILENAMES
for (int n = 0; n < chooser->count(); n++ ) {
fprintf(stderr, "%d) '%s'\n", n, chooser->filename(n));
}
}
You can preset the directory with
directory() method, and the filename using the
preset_file() method.
The filter string can be any of:
The format of each filter is a wildcard, or an optional user description followed by '\t' and the wildcard.
On most platforms, each filter is available to the user via a pulldown menu in the file chooser. The 'All Files' option is always available to the user.
The first filter is indexed as 0. If filter_value()==filters(),
then "All Files" was chosen. If filter_value() > filters(), then
a custom filter was set.
Some platforms have file choosers with specific functions that can be enabled/disabled via this method.
Flags can be ORed together to enable several features. Flags currently supported:
Flag | Description | Win | Mac | Other |
fltk::NativeFileChooser::SAVEAS_CONFIRM | With a BROWSE_SAVEAS chooser, prompts a confirmation if file exists | Ignored | Used | Ignored |
fltk::NativeFileChooser::NEW_FOLDER | Shows the 'New Folder' button | Ignored | Used | Used |
fltk::NativeFileChooser::PREVIEW | Enables the 'Preview' mode by default | Ignored | Ignored | Used |
Return value:
The default title varies according to the platform, so you are advised to set the title explicitly.
Flag | Description |
fltk::NativeFileChooser::BROWSE_FILE | Browse for a single file |
fltk::NativeFileChooser::BROWSE_DIRECTORY | Browse for a single directory |
fltk::NativeFileChooser::BROWSE_MULTI_FILE | Browse for multiple files |
fltk::NativeFileChooser::BROWSE_MULTI_DIRECTORY | Browse for multiple directories (implementation varies) |
fltk::NativeFileChooser::BROWSE_SAVE_FILE | Browse to save a single file |
fltk::NativeFileChooser::BROWSE_SAVE_DIRECTORY | Browse for a directory, allowing creation |
These may be changed in future versions of fltk::NativeFileChooser.
#include <fltk/NativeFileChooser.h> : fltk::NativeFileChooser *chooser = new fltk::NativeFileChooser(); chooser->type(fltk::NativeFileChooser::BROWSE_FILE); // let user browse a single file chooser->title("Open a file"); // optional title chooser->preset_file("/var/tmp/somefile.txt"); // optional filename preset chooser->filter("Text Files\t*.txt"); // optional filter switch ( chooser->show() ) { case -1: // ERROR fprintf(stderr, "*** ERROR show() failed:%s\n", chooser->errmsg()); break; case 1: // CANCEL fprintf(stderr, "*** CANCEL\n"); break; default: // USER PICKED A FILE fprintf(stderr, "Filename was '%s'\n", chooser->filename()); break; }// EXAMPLE 'SAVEAS' FILE BROWSER #include <fltk/NativeFileChooser.h> : fltk::NativeFileChooser *chooser = new fltk::NativeFileChooser(); chooser->type(fltk::NativeFileChooser::BROWSE_SAVE_FILE); // 'saveas' browser chooser->title("Save As.."); // optional title for chooser window chooser->directory("/var/tmp"); // optional starting directory chooser->preset_file("untitled.txt"); // optional default filename chooser->filter("Text Files\t*.txt"); // optional filter switch ( chooser->show() ) { case -1: // ERROR fprintf(stderr, "*** ERROR show() failed:%s\n", chooser->errmsg()); break; case 1: // CANCEL fprintf(stderr, "*** CANCEL\n"); break; default: // USER PICKED A FILE fprintf(stderr, "Filename was '%s'\n", chooser->filename()); break; }