summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2005-03-25 18:58:18 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2005-03-25 18:58:18 +0000
commitf5ed012b28231526a56e302a923d24f82a7fad2d (patch)
treed02d88f5b5584d735d8e27be36dbda1949d2a191
parent2ccbfdccc91c9fd139ae5a6dcb48226323381a17 (diff)
Updated Fl_File_Chooser to correctly deselect other items when
the user picks a file or directory in multiple selection mode (only files or directories, not both at once...) Use the fl_file_chooser_ok_label() function in FLUID. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4191 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--CHANGES2
-rw-r--r--fluid/Fl_Function_Type.cxx2
-rw-r--r--fluid/Fluid_Image.cxx2
-rw-r--r--fluid/fluid.cxx12
-rw-r--r--src/Fl_File_Chooser2.cxx30
5 files changed, 41 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index 3069cd8e1..63fca1ee8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@ CHANGES IN FLTK 1.1.7
- Documentation fixes (STR #648, STR #692, STR #730, STR
#744, STR #745)
+ - Fl_File_Chooser now correctly handles multiple
+ selections that are a mix of files and directories.
- Fl_File_Chooser no longer resets the type() when
choosing a single file, and it now works when selecting
multiple directories (STR #747)
diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx
index 67ba7fae1..9b6b06b8c 100644
--- a/fluid/Fl_Function_Type.cxx
+++ b/fluid/Fl_Function_Type.cxx
@@ -780,7 +780,9 @@ void Fl_Comment_Type::open() {
}
else if (w == comment_load) {
// load a comment from disk
+ fl_file_chooser_ok_label("Use File");
const char *fname = fl_file_chooser("Pick a comment", 0L, 0L);
+ fl_file_chooser_ok_label(NULL);
if (fname) {
if (comment_input->buffer()->loadfile(fname)) {
fl_alert("Error loading file\n%s", fname);
diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx
index 8bf90450b..dfcd74325 100644
--- a/fluid/Fluid_Image.cxx
+++ b/fluid/Fluid_Image.cxx
@@ -212,7 +212,9 @@ Fluid_Image::~Fluid_Image() {
const char *ui_find_image_name;
Fluid_Image *ui_find_image(const char *oldname) {
goto_source_dir();
+ fl_file_chooser_ok_label("Use Image");
const char *name = fl_file_chooser("Image?","Image Files (*.{bm,bmp,gif,jpg,pbm,pgm,png,ppm,xbm,xpm})",oldname,1);
+ fl_file_chooser_ok_label(NULL);
ui_find_image_name = name;
Fluid_Image *ret = (name && *name) ? Fluid_Image::find(name) : 0;
leave_source_dir();
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index 3c5f1c63d..095711a78 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -176,9 +176,9 @@ static char* cutfname(int which = 0) {
void save_cb(Fl_Widget *, void *v) {
const char *c = filename;
if (v || !c || !*c) {
- fl_ok = "Save";
+ fl_file_chooser_ok_label("Save");
c=fl_file_chooser("Save To:", "FLUID Files (*.f[ld])", c);
- fl_ok = "OK";
+ fl_file_chooser_ok_label(NULL);
if (!c) return;
if (!access(c, 0)) {
@@ -436,9 +436,9 @@ void open_cb(Fl_Widget *, void *v) {
}
const char *c;
const char *oldfilename;
- fl_ok = "Open";
+ fl_file_chooser_ok_label("Open");
c = fl_file_chooser("Open:", "FLUID Files (*.f[ld])", filename);
- fl_ok = "OK";
+ fl_file_chooser_ok_label(NULL);
if (!c) return;
oldfilename = filename;
filename = NULL;
@@ -964,9 +964,9 @@ void print_cb(Fl_Return_Button *, void *) {
outfile = popen(command, "w");
} else {
// Print to file...
- fl_ok = "Print";
+ fl_file_chooser_ok_label("Print");
const char *outname = fl_file_chooser("Print To", "PostScript (*.ps)", NULL, 1);
- fl_ok = "OK";
+ fl_file_chooser_ok_label(NULL);
if (outname && !access(outname, 0)) {
if (fl_choice("The file \"%s\" already exists.\n"
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx
index 0544a1481..c9264d7c4 100644
--- a/src/Fl_File_Chooser2.cxx
+++ b/src/Fl_File_Chooser2.cxx
@@ -415,8 +415,36 @@ Fl_File_Chooser::fileListCB()
}
else
{
- // Strip any trailing slash from the directory name...
+ // Check if the user clicks on a directory when picking files;
+ // if so, make sure only that item is selected...
filename = pathname + strlen(pathname) - 1;
+
+ if ((type_ & MULTI) && !(type_ & DIRECTORY)) {
+ if (*filename == '/') {
+ // Clicked on a directory, deselect everything else...
+ int i = fileList->value();
+ fileList->deselect();
+ fileList->select(i);
+ } else {
+ // Clicked on a file - see if there are other directories selected...
+ int i;
+ const char *temp;
+ for (i = 1; i <= fileList->size(); i ++) {
+ if (i != fileList->value() && fileList->selected(i)) {
+ temp = fileList->text(i);
+ temp += strlen(temp) - 1;
+ if (*temp == '/') break; // Yes, selected directory
+ }
+ }
+
+ if (i <= fileList->size()) {
+ i = fileList->value();
+ fileList->deselect();
+ fileList->select(i);
+ }
+ }
+ }
+ // Strip any trailing slash from the directory name...
if (*filename == '/') *filename = '\0';
// puts("Setting fileName from fileListCB...");