summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2006-03-28 15:24:14 +0000
committerMatthias Melcher <fltk@matthiasm.com>2006-03-28 15:24:14 +0000
commit7e42a63aa6482c53e13582adf95c001f47886a52 (patch)
treeb01b6f9f27fc9e81c7f4940860a2c47dd676b25c /src
parent37518df9b3a5634cb3e10b5a6e97acc0be209178 (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')
-rw-r--r--src/Fl_File_Browser.cxx2
-rw-r--r--src/Fl_File_Chooser.cxx2
-rw-r--r--src/Fl_File_Chooser.fl15
-rw-r--r--src/Fl_File_Chooser2.cxx53
4 files changed, 63 insertions, 9 deletions
diff --git a/src/Fl_File_Browser.cxx b/src/Fl_File_Browser.cxx
index 7698a8083..a09a61984 100644
--- a/src/Fl_File_Browser.cxx
+++ b/src/Fl_File_Browser.cxx
@@ -467,7 +467,7 @@ Fl_File_Browser::load(const char *directory,// I - Directory to load
{
sprintf(filename, "%c:/", i);
- if (i < 'C')
+ if (i < 'C') // see also: GetDriveType and GetVolumeInformation in WIN32
add(filename, icon);
else
add(filename, icon);
diff --git a/src/Fl_File_Chooser.cxx b/src/Fl_File_Chooser.cxx
index 356e97dde..6a3397567 100644
--- a/src/Fl_File_Chooser.cxx
+++ b/src/Fl_File_Chooser.cxx
@@ -375,7 +375,7 @@ void Fl_File_Chooser::show() {
window->show();
Fl::flush();
fl_cursor(FL_CURSOR_WAIT);
-rescan();
+rescan_keep_filename();
fl_cursor(FL_CURSOR_DEFAULT);
fileName->take_focus();
}
diff --git a/src/Fl_File_Chooser.fl b/src/Fl_File_Chooser.fl
index 8cbd9f588..6dfaa315b 100644
--- a/src/Fl_File_Chooser.fl
+++ b/src/Fl_File_Chooser.fl
@@ -61,7 +61,7 @@ class FL_EXPORT Fl_File_Chooser {open
fileList->deselect();
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
window->hide();}
- private xywh {387 242 490 380} type Double resizable
+ private xywh {368 285 490 380} type Double resizable
code0 {if (title) window->label(title);}
code1 {\#include <stdio.h>}
code2 {\#include <stdlib.h>}
@@ -138,7 +138,7 @@ window->hide();}
if (callback_)
(*callback_)(this, data_);
-window->hide();} selected
+window->hide();}
private xywh {313 345 85 25}
code0 {\#include <FL/fl_ask.H>}
code1 {okButton->label(fl_ok);}
@@ -160,7 +160,7 @@ window->hide();}
}
Fl_Window favWindow {
label {Manage Favorites}
- private xywh {437 187 355 150} type Double resizable
+ private xywh {421 56 355 150} type Double resizable
code0 {favWindow->label(manage_favorites_label);} modal size_range {181 150 0 0} visible
} {
Fl_File_Browser favList {
@@ -299,15 +299,18 @@ okButton->parent()->init_sizes();} {}
}
decl {void rescan();} {public
}
- Function {show()} {return_type void
+ decl {void rescan_keep_filename();} {public
+ }
+ Function {show()} {open return_type void
} {
code {window->hotspot(fileList);
window->show();
Fl::flush();
fl_cursor(FL_CURSOR_WAIT);
-rescan();
+rescan_keep_filename();
fl_cursor(FL_CURSOR_DEFAULT);
-fileName->take_focus();} {}
+fileName->take_focus();} {selected
+ }
}
Function {shown()} {return_type int
} {
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();
}
}