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
This commit is contained in:
Matthias Melcher 2006-03-28 15:24:14 +00:00
parent 37518df9b3
commit 7e42a63aa6
5 changed files with 64 additions and 9 deletions

View File

@ -145,6 +145,7 @@ public:
void preview(int e);
int preview() const { return previewButton->value(); };
void rescan();
void rescan_keep_filename();
void show();
int shown();
void textcolor(Fl_Color c);

View File

@ -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);

View File

@ -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();
}

View File

@ -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
} {

View File

@ -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();
}
}