Add file-browser option to just return name
authorH.G. Muller <h.g.muller@hccnet.nl>
Sun, 3 Apr 2011 09:34:21 +0000 (11:34 +0200)
committerArun Persaud <apersaud@lbl.gov>
Thu, 7 Apr 2011 05:21:39 +0000 (22:21 -0700)
By passing mode "f" the file browser dialog will not open the selected
file at all, so it can be used to retreive the name for the benefit of a
file-browser button to a -file option. A mode "p" will limit the
selection to directories only, to browse for a path.

filebrowser/dir.c
filebrowser/selfile.c
filebrowser/selfile.h

index 2ff5307..123d329 100644 (file)
@@ -142,6 +142,10 @@ SFgetDir(dir)
                        maxChars = len;
                }
                result[i].shown = result[i].real;
+               if(SFpathFlag) { // [HGM] only show directories
+                       struct stat statBuf;
+                       if (stat(str, &statBuf) || SFstatChar(&statBuf) != '/') continue;
+               }
                i++;
        }
 
index a858e34..2e34955 100644 (file)
@@ -139,6 +139,8 @@ XtIntervalId SFdirModTimerId;
 
 int (*SFfunc)();
 
+Boolean SFpathFlag; // [HGM]
+
 static char *oneLineTextEditTranslations = "\
        <Key>Return:    redraw-display()\n\
        Ctrl<Key>M:     redraw-display()\n\
@@ -676,6 +678,12 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed,
                cancel = "Cancel";
        }
 
+       if(SFpathFlag != (mode && mode[0] == 'p')) { // [HGM] ignore everything that is not a directory
+               if(SFdirs) XtFree(SFdirs);
+               SFdirs = NULL; // kludge to throw away all cached info
+               SFpathFlag = !SFpathFlag;
+       }
+
        if (firstTime) {
                firstTime = 0;
                SFdisplay = XtDisplay(toplevel);
@@ -749,6 +757,10 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed,
                        break;
                case SEL_FILE_OK:
                        *name_return = SFgetText();
+                       if(mode && (mode[0] == 'p' || mode[0] == 'f')) { // [HGM] for use in file-option browse button
+                               SFprepareToReturn();
+                               return stderr;
+                       }
                        if (fp = SFopenFile(*name_return, mode,
                                            prompt, failed)) {
                                SFprepareToReturn();
index 558175e..9b905cf 100644 (file)
@@ -147,3 +147,6 @@ extern char SFstatChar();
 extern XtIntervalId SFdirModTimerId;
 
 extern int (*SFfunc)();
+
+extern Boolean SFpathFlag; // [HGM]
+