diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2006-03-28 15:24:14 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2006-03-28 15:24:14 +0000 |
| commit | 7e42a63aa6482c53e13582adf95c001f47886a52 (patch) | |
| tree | b01b6f9f27fc9e81c7f4940860a2c47dd676b25c /src/Fl_File_Chooser2.cxx | |
| parent | 37518df9b3a5634cb3e10b5a6e97acc0be209178 (diff) | |
ST 1148: a preselected filename will also be selected in the file chooser when popping up. I put a lot of effort into trying to make the chooser behave as it previously did in all other situations, e.g. to choose a directory
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4875 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_File_Chooser2.cxx')
| -rw-r--r-- | src/Fl_File_Chooser2.cxx | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx index 648d8a7ab..8de0f4d61 100644 --- a/src/Fl_File_Chooser2.cxx +++ b/src/Fl_File_Chooser2.cxx @@ -854,6 +854,57 @@ Fl_File_Chooser::rescan() update_preview(); } +// +// 'Fl_File_Chooser::rescan_keep_filename()' - Rescan the current directory +// without clearing the filename, then select the file if it is in the list +// + +void +Fl_File_Chooser::rescan_keep_filename() +{ + // if no filename was set, this is likely a diretory browser + const char *fn = fileName->value(); + if (!fn || !*fn || fn[strlen(fn) - 1]=='/') { + rescan(); + return; + } + + int i; + char pathname[1024]; // New pathname for filename field + strlcpy(pathname, fn, sizeof(pathname)); + + // Build the file list... + fileList->load(directory_, sort); + + // Update the preview box... + update_preview(); + + // and select the chosen file + char found = 0; + char *slash = strrchr(pathname, '/'); + if (slash) + slash++; + else + slash = pathname; + for (i = 1; i <= fileList->size(); i ++) +#if defined(WIN32) || defined(__EMX__) + if (strcasecmp(fileList->text(i), slash) == 0) { +#else + if (strcmp(fileList->text(i), slash) == 0) { +#endif // WIN32 || __EMX__ + fileList->topline(i); + fileList->select(i); + found = 1; + break; + } + + // update OK button activity + if (found || type_ & CREATE) + okButton->activate(); + else + okButton->deactivate(); +} + // // 'Fl_File_Chooser::showChoiceCB()' - Handle show selections. @@ -889,7 +940,7 @@ Fl_File_Chooser::showChoiceCB() if (shown()) { // Rescan the directory... - rescan(); + rescan_keep_filename(); } } |
