Browse Source

Fl_File_Chooser::value("foo") now checks if the pathname is a directory

and doesn't strip the trailing one if so.

Fl_File_Chooser::value(n) now returns a directory name without the
trailing slash.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2527 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/168/head
Michael R Sweet 23 years ago
parent
commit
8025bf7251
  1. 3
      CHANGES
  2. 37
      src/Fl_File_Chooser2.cxx
  3. 57
      test/file_chooser.cxx

3
CHANGES

@ -1,5 +1,8 @@ @@ -1,5 +1,8 @@
CHANGES IN FLTK 1.1.0
- Fl_File_Chooser::value() would return directories with
a trailing slash, but would not accept a directory
without a trailing slash.
- When installing shared libraries, FLUID is now linked
against the shared libraries.
- MacOS: missing compile rule for .dylib files.

37
src/Fl_File_Chooser2.cxx

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
//
// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.18 2002/07/01 21:14:20 easysw Exp $"
// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.19 2002/07/14 18:18:59 easysw Exp $"
//
// More Fl_File_Chooser routines.
//
@ -980,22 +980,26 @@ Fl_File_Chooser::value(int f) // I - File number @@ -980,22 +980,26 @@ Fl_File_Chooser::value(int f) // I - File number
int i; // Looping var
int count; // Number of selected files
const char *name; // Current filename
char *slash; // Trailing slash, if any
static char pathname[1024]; // Filename + directory
if (!(type_ & MULTI))
{
if (!(type_ & MULTI)) {
name = fileName->value();
if (name[0] == '\0') return NULL;
else if (fl_filename_isdir(name)) {
if (type_ & DIRECTORY) return name;
else return NULL;
if (type_ & DIRECTORY) {
// Strip trailing slash, if any...
strlcpy(pathname, name, sizeof(pathname));
slash = pathname + strlen(pathname) - 1;
if (*slash == '/') *slash = '\0';
return pathname;
} else return NULL;
} else return name;
}
for (i = 1, count = 0; i <= fileList->size(); i ++)
if (fileList->selected(i))
{
if (fileList->selected(i)) {
// See if this file is a directory...
name = fileList->text(i);
@ -1005,12 +1009,10 @@ Fl_File_Chooser::value(int f) // I - File number @@ -1005,12 +1009,10 @@ Fl_File_Chooser::value(int f) // I - File number
strlcpy(pathname, name, sizeof(pathname));
}
if (!fl_filename_isdir(pathname))
{
if (!fl_filename_isdir(pathname)) {
// Nope, see if this this is "the one"...
count ++;
if (count == f)
return ((const char *)pathname);
if (count == f) return (pathname);
}
}
@ -1052,14 +1054,13 @@ Fl_File_Chooser::value(const char *filename) // I - Filename + directory @@ -1052,14 +1054,13 @@ Fl_File_Chooser::value(const char *filename) // I - Filename + directory
if ((slash = strrchr(pathname, '/')) == NULL)
slash = strrchr(pathname, '\\');
if (slash != NULL)
{
if (slash != NULL) {
// Yes, change the display to the directory...
*slash++ = '\0';
if (!fl_filename_isdir(pathname)) *slash++ = '\0';
directory(pathname);
}
else
{
if (*slash == '/') slash = pathname;
} else {
directory(".");
slash = pathname;
}
@ -1134,5 +1135,5 @@ unquote_pathname(char *dst, // O - Destination string @@ -1134,5 +1135,5 @@ unquote_pathname(char *dst, // O - Destination string
//
// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.18 2002/07/01 21:14:20 easysw Exp $".
// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.19 2002/07/14 18:18:59 easysw Exp $".
//

57
test/file_chooser.cxx

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
//
// "$Id: file_chooser.cxx,v 1.4.2.3.2.7 2002/06/28 21:10:20 easysw Exp $"
// "$Id: file_chooser.cxx,v 1.4.2.3.2.8 2002/07/14 18:19:00 easysw Exp $"
//
// File chooser test program.
//
@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
#include <FL/Fl_File_Icon.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_PNM_Image.H>
#include <FL/Fl_Light_Button.H>
#include "../src/flstring.h"
@ -61,7 +62,10 @@ Fl_Shared_Image *image = 0; @@ -61,7 +62,10 @@ Fl_Shared_Image *image = 0;
//
void close_callback(void);
void create_callback(void);
void dir_callback(void);
void fc_callback(Fl_File_Chooser *, void *);
void multi_callback(void);
Fl_Image *pdf_check(const char *, uchar *, int);
Fl_Image *ps_check(const char *, uchar *, int);
void show_callback(void);
@ -84,10 +88,8 @@ main(int argc, // I - Number of command-line arguments @@ -84,10 +88,8 @@ main(int argc, // I - Number of command-line arguments
Fl::scheme(NULL);
Fl_File_Icon::load_system_icons();
fc = new Fl_File_Chooser(".", "*", Fl_File_Chooser::MULTI, "Fl_File_Chooser Test");
fc = new Fl_File_Chooser(".", "*", Fl_File_Chooser::SINGLE, "Fl_File_Chooser Test");
fc->callback(fc_callback);
// fc->type(Fl_File_Chooser::MULTI);
// fc->color((Fl_Color)196);
// Register the PS and PDF image types...
Fl_Shared_Image::add_handler(pdf_check);
@ -112,12 +114,22 @@ main(int argc, // I - Number of command-line arguments @@ -112,12 +114,22 @@ main(int argc, // I - Number of command-line arguments
icon = Fl_File_Icon::find(".", Fl_File_Icon::DIRECTORY);
icon->label(button);
files = new Fl_File_Browser(50, 45, 340, 110, "Files:");
button = new Fl_Light_Button(50, 45, 80, 25, "MULTI");
button->callback((Fl_Callback *)multi_callback);
button = new Fl_Light_Button(140, 45, 90, 25, "CREATE");
button->callback((Fl_Callback *)create_callback);
button = new Fl_Light_Button(240, 45, 115, 25, "DIRECTORY");
button->callback((Fl_Callback *)dir_callback);
files = new Fl_File_Browser(50, 80, 340, 75, "Files:");
files->align(FL_ALIGN_LEFT);
button = new Fl_Button(340, 165, 50, 25, "Close");
button->callback((Fl_Callback *)close_callback);
window->resizable(files);
window->end();
window->show();
@ -138,6 +150,28 @@ close_callback(void) @@ -138,6 +150,28 @@ close_callback(void)
}
//
// 'create_callback()' - Handle clicks on the create button.
//
void
create_callback(void)
{
fc->type(fc->type() ^ Fl_File_Chooser::CREATE);
}
//
// 'dir_callback()' - Handle clicks on the directory button.
//
void
dir_callback(void)
{
fc->type(fc->type() ^ Fl_File_Chooser::DIRECTORY);
}
//
// 'fc_callback()' - Handle choices in the file chooser...
//
@ -157,6 +191,17 @@ fc_callback(Fl_File_Chooser *fc, // I - File chooser @@ -157,6 +191,17 @@ fc_callback(Fl_File_Chooser *fc, // I - File chooser
}
//
// 'multi_callback()' - Handle clicks on the multi button.
//
void
multi_callback(void)
{
fc->type(fc->type() ^ Fl_File_Chooser::MULTI);
}
//
// 'pdf_check()' - Check for and load the first page of a PDF file.
//
@ -290,5 +335,5 @@ show_callback(void) @@ -290,5 +335,5 @@ show_callback(void)
//
// End of "$Id: file_chooser.cxx,v 1.4.2.3.2.7 2002/06/28 21:10:20 easysw Exp $".
// End of "$Id: file_chooser.cxx,v 1.4.2.3.2.8 2002/07/14 18:19:00 easysw Exp $".
//

Loading…
Cancel
Save