From d2f43d6c61f76a5b3999db2f5a0c8b23b2387a42 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 3 Apr 2011 11:34:21 +0200 Subject: [PATCH] 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. --- filebrowser/dir.c | 4 ++++ filebrowser/selfile.c | 12 ++++++++++++ filebrowser/selfile.h | 3 +++ 3 files changed, 19 insertions(+), 0 deletions(-) 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] + -- 1.7.0.4