summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--FL/Fl_File_Chooser.H3
-rw-r--r--documentation/Fl_File_Chooser.html10
-rw-r--r--src/Fl_File_Browser.cxx8
-rw-r--r--src/Fl_File_Chooser.cxx9
-rw-r--r--src/Fl_File_Chooser.fl14
-rw-r--r--src/Fl_File_Chooser2.cxx62
7 files changed, 87 insertions, 22 deletions
diff --git a/CHANGES b/CHANGES
index d040271fe..920edaabc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
CHANGES IN FLTK 1.1.0
+ - Added new filter_value() methods to Fl_File_Chooser to
+ get and set the current file filters.
+ - Added support for custom filters to Fl_File_Chooser.
- Added Borland C++ Builder IDE project files from
Alexey Parshin.
- Resource leak fixes under WIN32 from Ori Berger.
diff --git a/FL/Fl_File_Chooser.H b/FL/Fl_File_Chooser.H
index 1f214fdb5..ee99f7250 100644
--- a/FL/Fl_File_Chooser.H
+++ b/FL/Fl_File_Chooser.H
@@ -101,6 +101,8 @@ public:
char * directory();
void filter(const char *p);
const char * filter();
+ int filter_value();
+ void filter_value(int f);
void hide();
void iconsize(uchar s);
uchar iconsize();
@@ -124,6 +126,7 @@ public:
int visible();
static const char *add_favorites_label;
static const char *all_files_label;
+ static const char *custom_filter_label;
static const char *existing_file_label;
static const char *favorites_label;
static const char *filename_label;
diff --git a/documentation/Fl_File_Chooser.html b/documentation/Fl_File_Chooser.html
index b25d40870..68f81bd4d 100644
--- a/documentation/Fl_File_Chooser.html
+++ b/documentation/Fl_File_Chooser.html
@@ -45,6 +45,10 @@ dialogs:
<TD>"All Files (*)"</TD>
</TR>
<TR>
+ <TD><TT>custom_filter_label</TT></TD>
+ <TD>"Custom Filter"</TD>
+</TR>
+<TR>
<TD><TT>existing_file_label</TT></TD>
<TD>"Please choose an existing file!"</TD>
</TR>
@@ -92,6 +96,7 @@ used when loading the contents of a directory.
<LI><A HREF="#Fl_File_Chooser.count">count</A>
<LI><A HREF="#Fl_File_Chooser.directory">directory</A>
<LI><A HREF="#Fl_File_Chooser.filter">filter</A>
+ <LI><A HREF="#Fl_File_Chooser.filter_value">filter_value</A>
<LI><A HREF="#Fl_File_Chooser.hide">hide</A>
<LI><A HREF="#Fl_File_Chooser.iconsize">iconsize</A>
<LI><A HREF="#Fl_File_Chooser.label">label</A>
@@ -173,6 +178,11 @@ const char *filter()</A></H4>
<P>Sets or gets the current filename filter pattern.
+<H4><A NAME="Fl_File_Chooser.filter_value">void filter_value(int f)<BR>
+int filter_value()</A></H4>
+
+<P>Sets or gets the current filename filter selection.
+
<H4><A NAME="Fl_File_Chooser.hide">void hide()</A></H4>
<P>Hides the <CODE>Fl_File_Chooser</CODE> window.
diff --git a/src/Fl_File_Browser.cxx b/src/Fl_File_Browser.cxx
index 2c558fee4..fb11989bb 100644
--- a/src/Fl_File_Browser.cxx
+++ b/src/Fl_File_Browser.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_File_Browser.cxx,v 1.1.2.17 2002/06/13 19:35:59 easysw Exp $"
+// "$Id: Fl_File_Browser.cxx,v 1.1.2.18 2002/07/01 21:14:20 easysw Exp $"
//
// Fl_File_Browser routines.
//
@@ -582,8 +582,12 @@ Fl_File_Browser::load(const char *directory,// I - Directory to load
for (i = 0, num_dirs = 0; i < num_files; i ++)
{
+#if 0
if (strcmp(files[i]->d_name, ".") != 0 &&
strcmp(files[i]->d_name, "..") != 0)
+#else
+ if (strcmp(files[i]->d_name, ".") != 0)
+#endif // 0
{
snprintf(filename, sizeof(filename), "%s/%s", directory_,
files[i]->d_name);
@@ -639,5 +643,5 @@ Fl_File_Browser::filter(const char *pattern) // I - Pattern string
//
-// End of "$Id: Fl_File_Browser.cxx,v 1.1.2.17 2002/06/13 19:35:59 easysw Exp $".
+// End of "$Id: Fl_File_Browser.cxx,v 1.1.2.18 2002/07/01 21:14:20 easysw Exp $".
//
diff --git a/src/Fl_File_Chooser.cxx b/src/Fl_File_Chooser.cxx
index f4a57c84a..7dfdd88ef 100644
--- a/src/Fl_File_Chooser.cxx
+++ b/src/Fl_File_Chooser.cxx
@@ -283,6 +283,15 @@ const char * Fl_File_Chooser::filter() {
return (fileList->filter());
}
+int Fl_File_Chooser::filter_value() {
+ return showChoice->value();
+}
+
+void Fl_File_Chooser::filter_value(int f) {
+ showChoice->value(f);
+showChoiceCB();
+}
+
void Fl_File_Chooser::hide() {
window->hide();
}
diff --git a/src/Fl_File_Chooser.fl b/src/Fl_File_Chooser.fl
index cc8d0fa6c..50ee3f0cd 100644
--- a/src/Fl_File_Chooser.fl
+++ b/src/Fl_File_Chooser.fl
@@ -173,8 +173,7 @@ value(d);
type(t);
int e;
prefs_.get("preview", e, 1);
-preview(e);} {selected
- }
+preview(e);} {}
}
Function {~Fl_File_Chooser()} {open
} {
@@ -208,6 +207,15 @@ data_ = d;} {}
} {
code {return (fileList->filter());} {}
}
+ Function {filter_value()} {return_type int
+ } {
+ code {return showChoice->value();} {}
+ }
+ Function {filter_value(int f)} {return_type void
+ } {
+ code {showChoice->value(f);
+showChoiceCB();} {}
+ }
Function {hide()} {return_type void
} {
code {window->hide();} {}
@@ -300,6 +308,8 @@ else
}
decl {static const char *all_files_label;} {public
}
+ decl {static const char *custom_filter_label;} {selected public
+ }
decl {static const char *existing_file_label;} {public
}
decl {static const char *favorites_label;} {public
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx
index cfeb9bdd3..8a9f11489 100644
--- a/src/Fl_File_Chooser2.cxx
+++ b/src/Fl_File_Chooser2.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.17 2002/06/13 19:36:00 easysw Exp $"
+// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.18 2002/07/01 21:14:20 easysw Exp $"
//
// More Fl_File_Chooser routines.
//
@@ -78,6 +78,7 @@ Fl_Preferences Fl_File_Chooser::prefs_(Fl_Preferences::USER, "fltk.org", "filech
const char *Fl_File_Chooser::add_favorites_label = "Add to Favorites";
const char *Fl_File_Chooser::all_files_label = "All Files (*)";
+const char *Fl_File_Chooser::custom_filter_label = "Custom Filter";
const char *Fl_File_Chooser::existing_file_label = "Please choose an existing file!";
const char *Fl_File_Chooser::favorites_label = "Favorites";
const char *Fl_File_Chooser::filename_label = "Filename:";
@@ -171,12 +172,27 @@ Fl_File_Chooser::directory(const char *d)// I - Directory to change to
else
strlcpy(directory_, d, sizeof(directory_));
- // Strip any trailing slash and/or period...
+ // Strip any trailing slash...
dirptr = directory_ + strlen(directory_) - 1;
- if (*dirptr == '.')
- *dirptr-- = '\0';
if ((*dirptr == '/' || *dirptr == '\\') && dirptr > directory_)
*dirptr = '\0';
+
+ // See if we have a trailing .. or . in the filename...
+ dirptr = directory_ + strlen(directory_) - 3;
+ if (dirptr >= directory_ && strcmp(dirptr, "/..") == 0) {
+ // Yes, we have "..", so strip the trailing path...
+ *dirptr = '\0';
+ while (dirptr > directory_) {
+ if (*dirptr == '/') break;
+ dirptr --;
+ }
+
+ if (dirptr >= directory_ && *dirptr == '/')
+ *dirptr = '\0';
+ } else if ((dirptr + 1) >= directory_ && strcmp(dirptr + 1, "/.") == 0) {
+ // Strip trailing "."...
+ dirptr[1] = '\0';
+ }
}
else
directory_[0] = '\0';
@@ -352,7 +368,7 @@ Fl_File_Chooser::favoritesCB(Fl_Widget *w)
//
// 'Fl_File_Chooser::fileListCB()' - Handle clicks (and double-clicks) in the
-// Fl_File_Browser.
+// Fl_File_Browser.
//
void
@@ -366,13 +382,13 @@ Fl_File_Chooser::fileListCB()
if (!filename)
return;
- if (directory_[0] != '\0')
+ if (directory_[0] != '\0') {
snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
- else
+ } else {
strlcpy(pathname, filename, sizeof(pathname));
+ }
- if (Fl::event_clicks())
- {
+ if (Fl::event_clicks()) {
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
fl_filename_isdir(pathname))
@@ -469,13 +485,12 @@ Fl_File_Chooser::fileNameCB()
// Enter pressed - select or change directory...
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
- fl_filename_isdir(pathname))
+ fl_filename_isdir(pathname)) {
#else
- if (fl_filename_isdir(pathname))
+ if (fl_filename_isdir(pathname)) {
#endif /* WIN32 || __EMX__ */
directory(pathname);
- else if ((type_ & CREATE) || access(pathname, 0) == 0)
- {
+ } else if ((type_ & CREATE) || access(pathname, 0) == 0) {
// New file or file exists... If we are in multiple selection mode,
// switch to single selection mode...
if (type_ & MULTI)
@@ -631,6 +646,7 @@ Fl_File_Chooser::filter(const char *p) // I - Pattern(s)
*start, // Start of pattern
*end; // End of pattern
int allfiles; // Do we have a "*" pattern?
+ char temp[1024]; // Temporary pattern string
// Make sure we have a pattern...
@@ -641,8 +657,6 @@ Fl_File_Chooser::filter(const char *p) // I - Pattern(s)
// Separate the pattern string as necessary...
showChoice->clear();
- showChoice->add("bla");
- showChoice->clear();
for (start = copyp, allfiles = 0; start && *start; start = end) {
end = strchr(start, '\t');
@@ -652,7 +666,8 @@ Fl_File_Chooser::filter(const char *p) // I - Pattern(s)
showChoice->add(all_files_label);
allfiles = 1;
} else {
- showChoice->add(start);
+ quote_pathname(temp, start, sizeof(temp));
+ showChoice->add(temp);
if (strstr(start, "(*)") != NULL) allfiles = 1;
}
}
@@ -661,6 +676,8 @@ Fl_File_Chooser::filter(const char *p) // I - Pattern(s)
if (!allfiles) showChoice->add(all_files_label);
+ showChoice->add(custom_filter_label);
+
showChoice->value(0);
showChoiceCB();
}
@@ -782,11 +799,20 @@ Fl_File_Chooser::showChoiceCB()
const char *item, // Selected item
*patstart; // Start of pattern
char *patend; // End of pattern
+ char temp[1024]; // Temporary string for pattern
item = showChoice->text(showChoice->value());
- if ((patstart = strchr(item, '(')) == NULL) {
+ if (strcmp(item, custom_filter_label) == 0) {
+ if ((item = fl_input(custom_filter_label, pattern_)) != NULL) {
+ strlcpy(pattern_, item, sizeof(pattern_));
+
+ quote_pathname(temp, item, sizeof(temp));
+ showChoice->add(temp);
+ showChoice->value(showChoice->size() - 2);
+ }
+ } else if ((patstart = strchr(item, '(')) == NULL) {
strlcpy(pattern_, item, sizeof(pattern_));
} else {
strlcpy(pattern_, patstart + 1, sizeof(pattern_));
@@ -1108,5 +1134,5 @@ unquote_pathname(char *dst, // O - Destination string
//
-// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.17 2002/06/13 19:36:00 easysw Exp $".
+// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.18 2002/07/01 21:14:20 easysw Exp $".
//