diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2005-03-25 17:27:07 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2005-03-25 17:27:07 +0000 |
| commit | 2ccbfdccc91c9fd139ae5a6dcb48226323381a17 (patch) | |
| tree | f9c207272d7c4086fd42e7da920de9561d000b6d /src/Fl_File_Chooser2.cxx | |
| parent | a343b0d4e40d6dd295cfea1a6bc66940b7edff34 (diff) | |
Fl_File_Chooser no longer resets the type() when choosing a
single file, and it now works when selecting multiple directories
(STR #747)
Fl_File_Icon::load_system_icons() now only loads 16x16 and 32x32
icon images to improve startup performance.
Fixed an error dialog message in FLUID.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4189 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_File_Chooser2.cxx')
| -rw-r--r-- | src/Fl_File_Chooser2.cxx | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx index 6590395ec..0544a1481 100644 --- a/src/Fl_File_Chooser2.cxx +++ b/src/Fl_File_Chooser2.cxx @@ -113,30 +113,22 @@ static void unquote_pathname(char *, const char *, int); // int // O - Number of selected files -Fl_File_Chooser::count() -{ +Fl_File_Chooser::count() { int i; // Looping var int fcount; // Number of selected files const char *filename; // Filename in input field or list - if (!(type_ & MULTI)) - { - // Check to see if the file name input field is blank... - filename = fileName->value(); - -// printf("Fl_File_Chooser::count(): filename=\"%s\"\n", filename); - - if (!filename || !filename[0]) - return (0); + filename = fileName->value(); - // Is the file name just the current directory? - return (strcmp(filename, directory_) != 0); + if (!(type_ & MULTI)) { + // Check to see if the file name input field is blank... + if (!filename || !filename[0]) return 0; + else return 1; } for (i = 1, fcount = 0; i <= fileList->size(); i ++) - if (fileList->selected(i)) - { + if (fileList->selected(i)) { // See if this file is a directory... filename = (char *)fileList->text(i); @@ -144,7 +136,9 @@ Fl_File_Chooser::count() fcount ++; } - return (fcount); + if (fcount) return fcount; + else if (!filename || !filename[0]) return 0; + else return 1; } @@ -511,11 +505,6 @@ Fl_File_Chooser::fileNameCB() #endif /* WIN32 || __EMX__ */ directory(pathname); } 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) - type(SINGLE); - // Update the preview box... update_preview(); @@ -1015,8 +1004,10 @@ Fl_File_Chooser::value(int f) // I - File number static char pathname[1024]; // Filename + directory + name = fileName->value(); + if (!(type_ & MULTI)) { - name = fileName->value(); + // Return the filename in the filename field... if (!name || !name[0]) return NULL; else if (fl_filename_isdir(name)) { if (type_ & DIRECTORY) { @@ -1029,28 +1020,40 @@ Fl_File_Chooser::value(int f) // I - File number } else return name; } + // Return a filename from the list... for (i = 1, fcount = 0; i <= fileList->size(); i ++) if (fileList->selected(i)) { - // See if this file is a directory... + // See if this file is a selected file/directory... name = fileList->text(i); - if (name[strlen(name) - 1] != '/') { - // Not a directory, see if this this is "the one"... - fcount ++; - - if (fcount == f) { - if (directory_[0]) { - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, name); - } else { - strlcpy(pathname, name, sizeof(pathname)); - } + fcount ++; - return (pathname); + if (fcount == f) { + if (directory_[0]) { + snprintf(pathname, sizeof(pathname), "%s/%s", directory_, name); + } else { + strlcpy(pathname, name, sizeof(pathname)); } + + // Strip trailing slash, if any... + strlcpy(pathname, name, sizeof(pathname)); + slash = pathname + strlen(pathname) - 1; + if (*slash == '/') *slash = '\0'; + return pathname; } } - return (NULL); + // If nothing is selected, use the filename field... + if (!name || !name[0]) return NULL; + else if (fl_filename_isdir(name)) { + 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; } @@ -1078,10 +1081,6 @@ Fl_File_Chooser::value(const char *filename) // I - Filename + directory return; } - // Switch to single-selection mode as needed - if (type_ & MULTI) - type(SINGLE); - // See if there is a directory in there... fl_filename_absolute(pathname, sizeof(pathname), filename); |
