mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 14:52:46 +08:00
Added "Filter" field to test filter strings.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@11919 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+44
-11
@@ -17,25 +17,27 @@
|
|||||||
// http://www.fltk.org/str.php
|
// http://www.fltk.org/str.php
|
||||||
//
|
//
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h> /* strstr() */
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/fl_ask.H> // fl_beep()
|
#include <FL/fl_ask.H> /* fl_beep() */
|
||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
#include <FL/Fl_Button.H>
|
#include <FL/Fl_Button.H>
|
||||||
#include <FL/Fl_Input.H>
|
#include <FL/Fl_Input.H>
|
||||||
|
#include <FL/Fl_Multiline_Input.H>
|
||||||
#include <FL/Fl_Box.H>
|
#include <FL/Fl_Box.H>
|
||||||
#include <FL/Fl_Native_File_Chooser.H>
|
#include <FL/Fl_Native_File_Chooser.H>
|
||||||
|
#include <FL/Fl_Help_View.H>
|
||||||
|
|
||||||
// GLOBALS
|
// GLOBALS
|
||||||
Fl_Input *G_filename = NULL;
|
Fl_Input *G_filename = NULL;
|
||||||
|
Fl_Multiline_Input *G_filter = NULL;
|
||||||
|
|
||||||
void PickFile_CB(Fl_Widget*, void*) {
|
void PickFile_CB(Fl_Widget*, void*) {
|
||||||
// Create native chooser
|
// Create native chooser
|
||||||
Fl_Native_File_Chooser native;
|
Fl_Native_File_Chooser native;
|
||||||
native.title("Pick a file");
|
native.title("Pick a file");
|
||||||
native.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
native.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||||
native.filter("Text\t*.txt\n"
|
native.filter(G_filter->value()); // TODO: need to add kNavSupportPackages to non-cocoa <FNFC>_MAC.cxx
|
||||||
"C Files\t*.{cxx,h,c}\n"
|
|
||||||
"Apps\t*.{app}\n"); // TODO: need to add kNavSupportPackages to non-cocoa <FNFC>_MAC.cxx
|
|
||||||
native.preset_file(G_filename->value());
|
native.preset_file(G_filename->value());
|
||||||
// Show native chooser
|
// Show native chooser
|
||||||
switch ( native.show() ) {
|
switch ( native.show() ) {
|
||||||
@@ -89,19 +91,51 @@ int main(int argc, char **argv) {
|
|||||||
argn++;
|
argn++;
|
||||||
#endif
|
#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->size_range(300, 100, 0, 100);
|
||||||
win->begin();
|
win->begin();
|
||||||
{
|
{
|
||||||
int y = 10;
|
int x = 80, y = 10;
|
||||||
G_filename = new Fl_Input(80, y, win->w()-80-10, 25, "Filename");
|
G_filename = new Fl_Input(x, y, win->w()-80-10, 25, "Filename");
|
||||||
G_filename->value(argc <= argn ? "." : argv[argn]);
|
G_filename->value(argc <= argn ? "." : argv[argn]);
|
||||||
G_filename->tooltip("Default filename");
|
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 <FNFC>_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:<ul>\n"
|
||||||
|
" <li>A single wildcard (e.g. <tt>\"*.txt\"</tt>)</li>\n"
|
||||||
|
" <li>Multiple wildcards (e.g. <tt>\"*.{cxx,h,H}\"</tt>)</li>\n"
|
||||||
|
" <li>A descriptive name followed by a "TAB" and a wildcard (e.g. <tt>\"Text Files"TAB"*.txt\"</tt>)</li>\n"
|
||||||
|
"</ul>\n"
|
||||||
|
"In the above \"Filter\" field, you can use <b><font color=#55f face=Courier>Ctrl-I</font></b> to enter "TAB" characters as needed.<br>\n"
|
||||||
|
"Example:<pre>\n"
|
||||||
|
"\n"
|
||||||
|
" Text<font color=#55f><Ctrl-I></font>*.txt\n"
|
||||||
|
" C Files<font color=#55f><Ctrl-I></font>*.{cxx,h,c,cpp}\n"
|
||||||
|
" Tars<font color=#55f><Ctrl-I></font>*.{tar,tar.gz}\n"
|
||||||
|
" Apps<font color=#55f><Ctrl-I></font>*.app\n");
|
||||||
|
|
||||||
|
Fl_Button *but = new Fl_Button(win->w()-x-10, win->h()-25-10, 80, 25, "Pick File");
|
||||||
but->callback(PickFile_CB);
|
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);
|
butdir->callback(PickDir_CB);
|
||||||
|
|
||||||
Fl_Box *dummy = new Fl_Box(80, 0, 430, 100);
|
Fl_Box *dummy = new Fl_Box(80, 0, 430, 100);
|
||||||
dummy->hide();
|
dummy->hide();
|
||||||
win->resizable(dummy);
|
win->resizable(dummy);
|
||||||
@@ -114,4 +148,3 @@ int main(int argc, char **argv) {
|
|||||||
//
|
//
|
||||||
// End of "$Id$".
|
// End of "$Id$".
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user