From: H.G. Muller Date: Sun, 3 Apr 2011 09:34:21 +0000 (+0200) Subject: Add file-browser option to just return name X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=d2f43d6c61f76a5b3999db2f5a0c8b23b2387a42;p=xboard.git Add file-browser option to just return name 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. --- diff --git a/filebrowser/dir.c b/filebrowser/dir.c index 2ff5307..123d329 100644 --- a/filebrowser/dir.c +++ b/filebrowser/dir.c @@ -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++; } diff --git a/filebrowser/selfile.c b/filebrowser/selfile.c index a858e34..2e34955 100644 --- a/filebrowser/selfile.c +++ b/filebrowser/selfile.c @@ -139,6 +139,8 @@ XtIntervalId SFdirModTimerId; int (*SFfunc)(); +Boolean SFpathFlag; // [HGM] + static char *oneLineTextEditTranslations = "\ Return: redraw-display()\n\ CtrlM: 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(); diff --git a/filebrowser/selfile.h b/filebrowser/selfile.h index 558175e..9b905cf 100644 --- a/filebrowser/selfile.h +++ b/filebrowser/selfile.h @@ -147,3 +147,6 @@ extern char SFstatChar(); extern XtIntervalId SFdirModTimerId; extern int (*SFfunc)(); + +extern Boolean SFpathFlag; // [HGM] +