Fl_Native_File_Chooser
#include "FL/Fl_Native_File_Chooser.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.
Return value:
The default title varies according to the platform, so you are advised to set the title explicitly.
// EXAMPLE OPEN FILE BROWSER #include "Fl_Native_File_Chooser.H" : Fl_Native_File_Chooser *chooser = new Fl_Native_File_Chooser(); chooser->type(Fl_Native_File_Chooser::BROWSE_FILE); // let user browse a single file chooser->title("Open a file"); // optional title for chooser window chooser->directory("/var/tmp"); // optional starting directory 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 "Fl_Native_File_Chooser.H" : Fl_Native_File_Chooser *chooser = new Fl_Native_File_Chooser(); chooser->type(Fl_Native_File_Chooser::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; }