Fix backspace "bug" in file chooser - now treat delete and backspace the

same, eliminating any filename completion value.

Added relative argument to fl_file_chooser() and fl_dir_chooser(); both
default to 0 (return absolute paths)

Give focus to the filename field in the chooser when show() is called.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2157 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet
2002-05-01 12:41:21 +00:00
parent 3a33fc7d81
commit 94a9fb879f
7 changed files with 99 additions and 32 deletions
+6
View File
@@ -1,5 +1,11 @@
CHANGES IN FLTK 1.1.0rc1 CHANGES IN FLTK 1.1.0rc1
- The fl_file_chooser() and fl_dir_chooser() functions
now support an optional "relative" argument to get
relative pathnames; the default is to return absolute
pathnames.
- The backspace and delete keys now work as expected in
the file chooser when doing filename completion.
- FLUID now supports running shell commands. - FLUID now supports running shell commands.
- New Fl_File_Input widget that shows directory - New Fl_File_Input widget that shows directory
separators with filename in input field. separators with filename in input field.
+2 -2
View File
@@ -84,7 +84,7 @@ public:
static const char *filename_label; static const char *filename_label;
static const char *filter_label; static const char *filter_label;
}; };
extern FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname); extern FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname,int relative=0);
extern FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname); extern FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname,int relative=0);
extern FL_EXPORT void fl_file_chooser_callback(void (*cb)(const char*)); extern FL_EXPORT void fl_file_chooser_callback(void (*cb)(const char*));
#endif #endif
+45 -1
View File
@@ -17,6 +17,7 @@ A</A>.
<LI><A HREF="#fl_choice2"><TT>fl_choice</TT></A></LI> <LI><A HREF="#fl_choice2"><TT>fl_choice</TT></A></LI>
<LI><A HREF="#fl_color_chooser_func"><TT>fl_color_chooser</TT></A></LI> <LI><A HREF="#fl_color_chooser_func"><TT>fl_color_chooser</TT></A></LI>
<LI><A HREF="#fl_color_cube"><TT>fl_color_cube</TT></A></LI> <LI><A HREF="#fl_color_cube"><TT>fl_color_cube</TT></A></LI>
<LI><A HREF="#fl_dir_chooser"><TT>fl_dir_chooser</TT></A></LI>
<LI><A HREF="#fl_file_chooser2"><TT>fl_file_chooser</TT></A></LI> <LI><A HREF="#fl_file_chooser2"><TT>fl_file_chooser</TT></A></LI>
<LI><A HREF="#fl_file_chooser_callback"><TT>fl_file_chooser_callback</TT></A></LI> <LI><A HREF="#fl_file_chooser_callback"><TT>fl_file_chooser_callback</TT></A></LI>
<LI><A HREF="#fl_filename_absolute"><TT>fl_filename_absolute</TT></A></LI> <LI><A HREF="#fl_filename_absolute"><TT>fl_filename_absolute</TT></A></LI>
@@ -50,6 +51,7 @@ A</A>.
<LI><A HREF="#fl_beep"><TT>fl_beep</TT></A></LI> <LI><A HREF="#fl_beep"><TT>fl_beep</TT></A></LI>
<LI><A HREF="#fl_choice2"><TT>fl_choice</TT></A></LI> <LI><A HREF="#fl_choice2"><TT>fl_choice</TT></A></LI>
<LI><A HREF="#fl_color_chooser_func"><TT>fl_color_chooser</TT></A></LI> <LI><A HREF="#fl_color_chooser_func"><TT>fl_color_chooser</TT></A></LI>
<LI><A HREF="#fl_dir_chooser"><TT>fl_dir_chooser</TT></A></LI>
<LI><A HREF="#fl_file_chooser2"><TT>fl_file_chooser</TT></A></LI> <LI><A HREF="#fl_file_chooser2"><TT>fl_file_chooser</TT></A></LI>
<LI><A HREF="#fl_file_chooser_callback"><TT>fl_file_chooser_callback</TT></A></LI> <LI><A HREF="#fl_file_chooser_callback"><TT>fl_file_chooser_callback</TT></A></LI>
<LI><A HREF="#fl_input2"><TT>fl_input</TT></A></LI> <LI><A HREF="#fl_input2"><TT>fl_input</TT></A></LI>
@@ -326,6 +328,44 @@ fl_color_cube(R * (FL_NUM_RED - 1) / 255,
</PRE></UL> </PRE></UL>
<!-- NEED 4in -->
<H2><A NAME="fl_dir_chooser">fl_dir_chooser</A></H2>
<HR>
<H3>Include Files</H3>
<UL><PRE>
#include &lt;FL/Fl_File_Chooser.H&gt;
</PRE></UL>
<H3>Prototype</H3>
<UL><PRE>
char *fl_dir_chooser(const char * message, const char *fname, int relative = 0);
</PRE></UL>
<H3>Description</H3>
<P>The <tt>fl_dir_chooser()</tt> function displays a <A
HREF="Fl_File_Chooser.html"><tt>Fl_File_Chooser</tt></A> dialog
so that the user can choose a directory.
<P><tt>message</tt> is a string used to title the window.
<P><tt>fname</tt> is a default filename to fill in the chooser
with. If this is <tt>NULL</tt> then the last filename that was
choosen is used. The first time the file chooser is called this
defaults to a blank string.
<P><tt>relative</tt> specifies whether the returned filename
should be relative (any non-zero value) or absolute (0). The
default is to return absolute paths.
<P>The returned value points at a static buffer that is only
good until the next time <tt>fl_dir_chooser()</tt> is called.
<!-- NEED 4in --> <!-- NEED 4in -->
<H2><A NAME="fl_file_chooser2">fl_file_chooser</A></H2> <H2><A NAME="fl_file_chooser2">fl_file_chooser</A></H2>
@@ -340,7 +380,7 @@ fl_color_cube(R * (FL_NUM_RED - 1) / 255,
<H3>Prototype</H3> <H3>Prototype</H3>
<UL><PRE> <UL><PRE>
char *fl_file_chooser(const char * message, const char *pattern, const char *fname); char *fl_file_chooser(const char * message, const char *pattern, const char *fname, int relative = 0);
</PRE></UL> </PRE></UL>
<H3>Description</H3> <H3>Description</H3>
@@ -371,6 +411,10 @@ choosen is used (unless that had a different pattern, in which
case just the last directory with no name is used). The first case just the last directory with no name is used). The first
time the file chooser is called this defaults to a blank string. time the file chooser is called this defaults to a blank string.
<P><tt>relative</tt> specifies whether the returned filename
should be relative (any non-zero value) or absolute (0). The
default is to return absolute paths.
<P>The returned value points at a static buffer that is only <P>The returned value points at a static buffer that is only
good until the next time <tt>fl_file_chooser()</tt> is called. good until the next time <tt>fl_file_chooser()</tt> is called.
+3 -2
View File
@@ -211,6 +211,7 @@ const char * Fl_File_Chooser::label() {
void Fl_File_Chooser::show() { void Fl_File_Chooser::show() {
window->hotspot(fileList); window->hotspot(fileList);
window->show(); window->show();
fileName->take_focus();
} }
int Fl_File_Chooser::shown() { int Fl_File_Chooser::shown() {
@@ -264,6 +265,6 @@ int Fl_File_Chooser::type() {
int Fl_File_Chooser::visible() { int Fl_File_Chooser::visible() {
return window->visible(); return window->visible();
} }
FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname); FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname,int relative=0);
FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname); FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname,int relative=0);
FL_EXPORT void fl_file_chooser_callback(void (*cb)(const char*)); FL_EXPORT void fl_file_chooser_callback(void (*cb)(const char*));
+4 -4
View File
@@ -150,8 +150,8 @@ rescan();} {}
Function {show()} {open return_type void Function {show()} {open return_type void
} { } {
code {window->hotspot(fileList); code {window->hotspot(fileList);
window->show();} {selected window->show();
} fileName->take_focus();} {}
} }
Function {shown()} {return_type int Function {shown()} {return_type int
} { } {
@@ -217,10 +217,10 @@ else
} }
} }
decl {FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname);} {public decl {FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname,int relative=0);} {public
} }
decl {FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname);} {public decl {FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname,int relative=0);} {selected public
} }
decl {FL_EXPORT void fl_file_chooser_callback(void (*cb)(const char*));} {public decl {FL_EXPORT void fl_file_chooser_callback(void (*cb)(const char*));} {public
+10 -10
View File
@@ -1,5 +1,5 @@
// //
// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.10 2002/05/01 08:51:59 easysw Exp $" // "$Id: Fl_File_Chooser2.cxx,v 1.1.2.11 2002/05/01 12:41:21 easysw Exp $"
// //
// More Fl_File_Chooser routines. // More Fl_File_Chooser routines.
// //
@@ -575,7 +575,8 @@ Fl_File_Chooser::fileNameCB()
fl_alert("Please choose an existing file!"); fl_alert("Please choose an existing file!");
} }
} }
else if (Fl::event_key() != FL_Delete) else if (Fl::event_key() != FL_Delete &&
Fl::event_key() != FL_BackSpace)
{ {
// Check to see if the user has entered a directory... // Check to see if the user has entered a directory...
if ((slash = strrchr(pathname, '/')) == NULL) if ((slash = strrchr(pathname, '/')) == NULL)
@@ -673,15 +674,9 @@ Fl_File_Chooser::fileNameCB()
fileName->replace(filename - pathname, filename - pathname + min_match, fileName->replace(filename - pathname, filename - pathname + min_match,
matchname); matchname);
// Highlight it; if the user just pressed the backspace // Highlight it with the cursor at the end of the selection so
// key, position the cursor at the start of the selection.
// Otherwise, put the cursor at the end of the selection so
// s/he can press the right arrow to accept the selection // s/he can press the right arrow to accept the selection
// (Tab and End also do this for both cases.) // (Tab and End also do this for both cases.)
if (Fl::event_key() == FL_BackSpace)
fileName->position(filename - pathname + min_match - 1,
filename - pathname + max_match);
else
fileName->position(filename - pathname + max_match, fileName->position(filename - pathname + max_match,
filename - pathname + min_match); filename - pathname + min_match);
} }
@@ -696,10 +691,15 @@ Fl_File_Chooser::fileNameCB()
okButton->activate(); okButton->activate();
else else
okButton->deactivate(); okButton->deactivate();
} else {
// FL_Delete or FL_BackSpace
fileList->deselect(0);
fileList->redraw();
okButton->deactivate();
} }
} }
// //
// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.10 2002/05/01 08:51:59 easysw Exp $". // End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.11 2002/05/01 12:41:21 easysw Exp $".
// //
+27 -11
View File
@@ -1,5 +1,5 @@
// //
// "$Id: fl_file_dir.cxx,v 1.1.2.9 2002/04/28 08:42:33 easysw Exp $" // "$Id: fl_file_dir.cxx,v 1.1.2.10 2002/05/01 12:41:21 easysw Exp $"
// //
// File chooser widget for the Fast Light Tool Kit (FLTK). // File chooser widget for the Fast Light Tool Kit (FLTK).
// //
@@ -43,9 +43,16 @@ void fl_file_chooser_callback(void (*cb)(const char*)) {
} }
char* fl_file_chooser(const char* message, const char* pat, const char* fname) //
{ // 'fl_file_chooser()' - Show a file chooser dialog and get a filename.
static char retname[1024]; //
char * // O - Filename or NULL
fl_file_chooser(const char *message, // I - Message in titlebar
const char *pat, // I - Filename pattern
const char *fname, // I - Initial filename selection
int relative) { // I - 0 for absolute path
static char retname[1024]; // Returned filename
if (!fc) { if (!fc) {
if (!fname || !*fname) fname = "."; if (!fname || !*fname) fname = ".";
@@ -88,17 +95,25 @@ char* fl_file_chooser(const char* message, const char* pat, const char* fname)
while (fc->shown()) while (fc->shown())
Fl::wait(); Fl::wait();
if (fc->value()) { if (fc->value() && relative) {
fl_filename_relative(retname, sizeof(retname), fc->value()); fl_filename_relative(retname, sizeof(retname), fc->value());
return retname; return retname;
} else return 0; } else if (fc->value()) return fc->value();
else return 0;
} }
char* fl_dir_chooser(const char* message, const char* fname) //
// 'fl_dir_chooser()' - Show a file chooser dialog and get a directory.
//
char * // O - Directory or NULL
fl_dir_chooser(const char *message, // I - Message for titlebar
const char *fname, // I - Initial directory name
int relative) // I - 0 for absolute
{ {
static char retname[1024]; static char retname[1024]; // Returned directory name
if (!fname || !*fname) fname = "."; if (!fname || !*fname) fname = ".";
@@ -118,14 +133,15 @@ char* fl_dir_chooser(const char* message, const char* fname)
while (fc->shown()) while (fc->shown())
Fl::wait(); Fl::wait();
if (fc->value()) { if (fc->value() && relative) {
fl_filename_relative(retname, sizeof(retname), fc->value()); fl_filename_relative(retname, sizeof(retname), fc->value());
return retname; return retname;
} else return 0; } else if (fc->value) return fc->value();
else return 0;
} }
// //
// End of "$Id: fl_file_dir.cxx,v 1.1.2.9 2002/04/28 08:42:33 easysw Exp $". // End of "$Id: fl_file_dir.cxx,v 1.1.2.10 2002/05/01 12:41:21 easysw Exp $".
// //