summaryrefslogtreecommitdiff
path: root/test/native-filechooser.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'test/native-filechooser.cxx')
-rw-r--r--test/native-filechooser.cxx26
1 files changed, 24 insertions, 2 deletions
diff --git a/test/native-filechooser.cxx b/test/native-filechooser.cxx
index a652a1cfd..2f6266391 100644
--- a/test/native-filechooser.cxx
+++ b/test/native-filechooser.cxx
@@ -28,7 +28,7 @@
// GLOBALS
Fl_Input *G_filename = NULL;
-void Butt_CB(Fl_Widget*, void*) {
+void PickFile_CB(Fl_Widget*, void*) {
// Create native chooser
Fl_Native_File_Chooser native;
native.title("Pick a file");
@@ -51,6 +51,26 @@ void Butt_CB(Fl_Widget*, void*) {
}
}
+void PickDir_CB(Fl_Widget*, void*) {
+ // Create native chooser
+ Fl_Native_File_Chooser native;
+ native.title("Pick a Directory");
+ native.directory(G_filename->value());
+ native.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
+ // Show native chooser
+ switch ( native.show() ) {
+ case -1: fprintf(stderr, "ERROR: %s\n", native.errmsg()); break; // ERROR
+ case 1: fprintf(stderr, "*** CANCEL\n"); fl_beep(); break; // CANCEL
+ default: // PICKED DIR
+ if ( native.filename() ) {
+ G_filename->value(native.filename());
+ } else {
+ G_filename->value("NULL");
+ }
+ break;
+ }
+}
+
int main(int argc, char **argv) {
//// For a nicer looking browser under linux, call Fl_File_Icon::load_system_icons();
//// (If you do this, you'll need to link with fltk_images)
@@ -79,7 +99,9 @@ int main(int argc, char **argv) {
G_filename->tooltip("Default filename");
y += G_filename->h() + 5;
Fl_Button *but = new Fl_Button(win->w()-80-10, win->h()-25-10, 80, 25, "Pick File");
- but->callback(Butt_CB);
+ but->callback(PickFile_CB);
+ Fl_Button *butdir = new Fl_Button(but->x()-80-10, win->h()-25-10, 80, 25, "Pick Dir");
+ butdir->callback(PickDir_CB);
Fl_Box *dummy = new Fl_Box(80, 0, 430, 100);
dummy->hide();
win->resizable(dummy);