From f20152e5f201c70e14b2e6361e76cd5b1a2df92b Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Mon, 5 Sep 2016 16:56:10 +0000 Subject: Bringing over fix [r11919] from 1.3 current to the porting branch. Added "Filter" field to test filter strings. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11921 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- test/native-filechooser.cxx | 55 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/test/native-filechooser.cxx b/test/native-filechooser.cxx index 2f6266391..60954278c 100644 --- a/test/native-filechooser.cxx +++ b/test/native-filechooser.cxx @@ -17,25 +17,27 @@ // http://www.fltk.org/str.php // #include +#include /* strstr() */ #include -#include // fl_beep() +#include /* fl_beep() */ #include #include #include +#include #include #include +#include // GLOBALS Fl_Input *G_filename = NULL; +Fl_Multiline_Input *G_filter = NULL; void PickFile_CB(Fl_Widget*, void*) { // Create native chooser Fl_Native_File_Chooser native; native.title("Pick a file"); native.type(Fl_Native_File_Chooser::BROWSE_FILE); - native.filter("Text\t*.txt\n" - "C Files\t*.{cxx,h,c}\n" - "Apps\t*.{app}\n"); // TODO: need to add kNavSupportPackages to non-cocoa _MAC.cxx + native.filter(G_filter->value()); // TODO: need to add kNavSupportPackages to non-cocoa _MAC.cxx native.preset_file(G_filename->value()); // Show native chooser switch ( native.show() ) { @@ -89,19 +91,51 @@ int main(int argc, char **argv) { argn++; #endif - Fl_Window *win = new Fl_Window(600, 100, "Native File Chooser Test"); + Fl_Window *win = new Fl_Window(680, 400, "Native File Chooser Test"); win->size_range(300, 100, 0, 100); win->begin(); { - int y = 10; - G_filename = new Fl_Input(80, y, win->w()-80-10, 25, "Filename"); + int x = 80, y = 10; + G_filename = new Fl_Input(x, y, win->w()-80-10, 25, "Filename"); G_filename->value(argc <= argn ? "." : argv[argn]); 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"); + + y += G_filename->h() + 10; + G_filter = new Fl_Multiline_Input(x, y, G_filename->w(), 100, "Filter"); + G_filter->value("Text\t*.txt\n" + "C Files\t*.{cxx,h,c,cpp}\n" + "Tars\t*.{tar,tar.gz}\n" + "Apps\t*.app"); // TODO: need to add kNavSupportPackages to non-cocoa _MAC.cxx + G_filter->tooltip("Filter to be used for browser.\n" + "An empty string may be used.\n"); + + y += G_filter->h() + 3; + Fl_Help_View *view = new Fl_Help_View(x, y, G_filename->w(), 180); + view->box(FL_FLAT_BOX); + view->color(win->color()); +#define TAB "<Tab>" + view->textfont(FL_HELVETICA); + view->textsize(10); + view->value("The Filter can be one or more filters patterns, one per line.\n" + "Patterns can be:
    \n" + "
  • A single wildcard (e.g. \"*.txt\")
  • \n" + "
  • Multiple wildcards (e.g. \"*.{cxx,h,H}\")
  • \n" + "
  • A descriptive name followed by a "TAB" and a wildcard (e.g. \"Text Files"TAB"*.txt\")
  • \n" + "
\n" + "In the above \"Filter\" field, you can use Ctrl-I to enter "TAB" characters as needed.
\n" + "Example:
\n"
+		"\n"
+		"    Text<Ctrl-I>*.txt\n"
+		"    C Files<Ctrl-I>*.{cxx,h,c,cpp}\n"
+		"    Tars<Ctrl-I>*.{tar,tar.gz}\n"
+		"    Apps<Ctrl-I>*.app\n");
+
+    Fl_Button *but = new Fl_Button(win->w()-x-10, win->h()-25-10, 80, 25, "Pick File");
     but->callback(PickFile_CB);
-    Fl_Button *butdir = new Fl_Button(but->x()-80-10, win->h()-25-10, 80, 25, "Pick Dir");
+
+    Fl_Button *butdir = new Fl_Button(but->x()-x-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);
@@ -114,4 +148,3 @@ int main(int argc, char **argv) {
 //
 // End of "$Id$".
 //
-
-- 
cgit v1.2.3