char
SFstartDir[MAXPATHLEN],
SFcurrentPath[MAXPATHLEN],
+ SFlastPath[MAXPATHLEN],
SFcurrentDir[MAXPATHLEN];
Widget
selFile,
selFileCancel,
selFileField,
+ selFileMess,
+ filterField,
selFileForm,
selFileHScroll,
selFileHScrolls[3],
char SFtextBuffer[MAXPATHLEN];
+char SFfilterBuffer[MAXPATHLEN];
+
XtIntervalId SFdirModTimerId;
int (*SFfunc)();
SFdrawList((int)(intptr_t)n, SF_DO_NOT_SCROLL);
}
+void
+SFpurge()
+{
+ if(SFdirs) XtFree((XtPointer) SFdirs);
+ SFdirs = NULL; // kludge to throw away all cached info
+}
+
/* ARGSUSED */
static void
SFmodVerifyCallback(w, client_data, event, cont)
if (
(XLookupString(&(event->xkey), buf, 2, NULL, NULL) == 1) &&
- ((*buf) == '\r')
+ ((*buf) == '\r' || *buf == 033)
) {
- SFstatus = SEL_FILE_OK;
+ if(client_data) {
+ Arg args[10]; char *p;
+ if(*buf == 033) { // [HGM] esc in filter: restore and give focus to path
+ XtSetArg(args[0], XtNstring, SFfilterBuffer);
+ XtSetValues(filterField, args, 1);
+ XtSetKeyboardFocus(selFileForm, selFileField);
+ SFstatus = SEL_FILE_TEXT;
+ return;
+ } else
+ if(!SFpathFlag) // [HGM] cr: fetch current extenson filter
+ {
+ XtSetArg(args[0], XtNstring, &p);
+ XtGetValues(filterField, args, 1);
+ if(strcmp(SFfilterBuffer, p)) SFpurge();
+ strncpy(SFfilterBuffer, p, 40);
+ SFstatus = SEL_FILE_TEXT;
+ }
+ return;
+ }
+ SFstatus = (*buf == 033 ? SEL_FILE_CANCEL : SEL_FILE_OK);
} else {
- SFstatus = SEL_FILE_TEXT;
+ if(!client_data) SFstatus = SEL_FILE_TEXT;
}
}
{"SelFileDismiss", SFdismissAction},
};
+void SFsetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
+{
+ XtSetKeyboardFocus((Widget) data, w);
+}
+
static void
SFcreateWidgets(toplevel, prompt, ok, cancel)
Widget toplevel;
XtSetArg(arglist[i], XtNborderColor, SFfore); i++;
XtSetArg(arglist[i], XtNfromVert, selFilePrompt); i++;
- XtSetArg(arglist[i], XtNvertDistance, 10); i++;
+ XtSetArg(arglist[i], XtNvertDistance, 5); i++;
XtSetArg(arglist[i], XtNresizable, True); i++;
XtSetArg(arglist[i], XtNtop, XtChainTop); i++;
XtSetArg(arglist[i], XtNbottom, XtChainTop); i++;
XtOverrideTranslations(selFileField,
XtParseTranslationTable(oneLineTextEditTranslations));
- XtSetKeyboardFocus(selFileForm, selFileField);
+ XtAddEventHandler(selFileField, ButtonPressMask, False, SFsetFocus, (XtPointer) selFileForm);
+
+ i = 0;
+ XtSetArg(arglist[i], XtNlabel, "Filter on extensions:"); i++;
+ XtSetArg(arglist[i], XtNvertDistance, 5); i++;
+ XtSetArg(arglist[i], XtNfromVert, selFileField); i++;
+ XtSetArg(arglist[i], XtNresizable, True); i++;
+ XtSetArg(arglist[i], XtNtop, XtChainTop); i++;
+ XtSetArg(arglist[i], XtNbottom, XtChainTop); i++;
+ XtSetArg(arglist[i], XtNleft, XtChainLeft); i++;
+ XtSetArg(arglist[i], XtNright, XtChainLeft); i++;
+ XtSetArg(arglist[i], XtNborderWidth, 0); i++;
+ selFileMess = XtCreateManagedWidget("selFileMess",
+ labelWidgetClass, selFileForm, arglist, i);
+
+ i = 0;
+ XtSetArg(arglist[i], XtNwidth, NR * listWidth + (NR - 1) * listSpacing + 4);
+ i++;
+ XtSetArg(arglist[i], XtNborderColor, SFfore); i++;
+ XtSetArg(arglist[i], XtNvertDistance, 5); i++;
+ XtSetArg(arglist[i], XtNfromVert, selFileMess); i++;
+ XtSetArg(arglist[i], XtNresizable, True); i++;
+ XtSetArg(arglist[i], XtNtop, XtChainTop); i++;
+ XtSetArg(arglist[i], XtNbottom, XtChainTop); i++;
+ XtSetArg(arglist[i], XtNleft, XtChainLeft); i++;
+ XtSetArg(arglist[i], XtNright, XtChainLeft); i++;
+ XtSetArg(arglist[i], XtNlength, MAXPATHLEN); i++;
+ XtSetArg(arglist[i], XtNeditType, XawtextEdit); i++;
+ XtSetArg(arglist[i], XtNwrap, XawtextWrapWord); i++;
+ XtSetArg(arglist[i], XtNresize, XawtextResizeHeight); i++;
+ XtSetArg(arglist[i], XtNuseStringInPlace, False); i++;
+ filterField = XtCreateManagedWidget("filterField",
+ asciiTextWidgetClass, selFileForm, arglist, i);
+
+ XtOverrideTranslations(filterField,
+ XtParseTranslationTable(oneLineTextEditTranslations));
+ XtAddEventHandler(filterField, ButtonPressMask, False, SFsetFocus, (XtPointer) selFileForm);
i = 0;
XtSetArg(arglist[i], XtNorientation, XtorientHorizontal); i++;
XtSetArg(arglist[i], XtNwidth, SFpathScrollWidth); i++;
XtSetArg(arglist[i], XtNheight, scrollThickness); i++;
XtSetArg(arglist[i], XtNborderColor, SFfore); i++;
- XtSetArg(arglist[i], XtNfromVert, selFileField); i++;
- XtSetArg(arglist[i], XtNvertDistance, 30); i++;
+ XtSetArg(arglist[i], XtNfromVert, filterField); i++;
+ XtSetArg(arglist[i], XtNvertDistance, 10); i++;
XtSetArg(arglist[i], XtNtop, XtChainTop); i++;
XtSetArg(arglist[i], XtNbottom, XtChainTop); i++;
XtSetArg(arglist[i], XtNleft, XtChainLeft); i++;
XDefineCursor(SFdisplay, XtWindow(selFileForm), xtermCursor);
XDefineCursor(SFdisplay, XtWindow(selFileField), xtermCursor);
+ XDefineCursor(SFdisplay, XtWindow(filterField), xtermCursor);
for (n = 0; n < NR; n++) {
XDefineCursor(SFdisplay, XtWindow(selFileLists[n]),
XtAddEventHandler(selFileField, KeyPressMask, False,
SFmodVerifyCallback, (XtPointer) NULL);
+ XtAddEventHandler(filterField, KeyReleaseMask, False,
+ SFmodVerifyCallback, (XtPointer) 1);
+ XtSetKeyboardFocus(selFileForm, selFileField);
SFapp = XtWidgetToApplicationContext(selFile);
FILE *
XsraSelFile(toplevel, prompt, ok, cancel, failed,
- init_path, mode, show_entry, name_return)
+ init_path, filter, mode, show_entry, name_return)
Widget toplevel;
char *prompt;
char *ok;
char *cancel;
char *failed;
char *init_path;
+ char *filter;
char *mode;
int (*show_entry)();
char **name_return;
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(SFpathFlag != (mode && mode[0] == 'p') || strcmp(SFfilterBuffer, filter)) {
+ SFpurge();
+ SFpathFlag = (mode && mode[0] == 'p'); // [HGM] ignore everything that is not a directory
}
if (firstTime) {
XtSetValues(selFileCancel, arglist, i);
}
+ i = 0;
+ XtSetArg(arglist[i], XtNstring, filter); i++;
+ XtSetValues(filterField, arglist, i);
+
+ safeStrCpy(SFfilterBuffer, filter, MAXPATHLEN);
+ safeStrCpy(SFlastPath, SFtextBuffer, MAXPATHLEN); // remember for cancel
+
SFpositionWidget(selFile);
XtMapWidget(selFile);
break;
case SEL_FILE_CANCEL:
SFprepareToReturn();
+ SFsetText(SFlastPath);
return NULL;
case SEL_FILE_NULL:
break;
int main P((int argc, char **argv));
FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed,
- char *init_path, char *mode, int (*show_entry)(), char **name_return));
+ char *init_path, char *filter, char *mode, int (*show_entry)(), char **name_return));
RETSIGTYPE CmailSigHandler P((int sig));
RETSIGTYPE IntSigHandler P((int sig));
RETSIGTYPE TermSizeSigHandler P((int sig));
XtPointer call_data));
void ICSInputBoxPopUp P((void));
void ICSInputBoxPopDown P((void));
-void FileNamePopUp P((char *label, char *def,
+void FileNamePopUp P((char *label, char *def, char *filter,
FileProc proc, char *openMode));
void FileNamePopDown P((void));
void FileNameCallback P((Widget w, XtPointer client_data,
commentUp = False;
}
-void FileNamePopUp(label, def, proc, openMode)
+void FileNamePopUp(label, def, filter, proc, openMode)
char *label;
char *def;
+ char *filter;
FileProc proc;
char *openMode;
{
int index; // this is not supported yet
FILE *f;
if(f = XsraSelFile(shellWidget, label, NULL, NULL, "could not open: ",
- def, openMode, NULL, &name))
+ (def[0] ? def : NULL), filter, openMode, NULL, &name))
(void) (*fileProc)(f, index=0, name);
}
}
if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
Reset(FALSE, TRUE);
}
- FileNamePopUp(_("Load game file name?"), "", LoadGamePopUp, "rb");
+ FileNamePopUp(_("Load game file name?"), "", ".pgn .game", LoadGamePopUp, "rb");
}
void LoadNextGameProc(w, event, prms, nprms)
if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
Reset(FALSE, TRUE);
}
- FileNamePopUp(_("Load position file name?"), "", LoadPosition, "rb");
+ FileNamePopUp(_("Load position file name?"), "", ".fen .epd .pos", LoadPosition, "rb");
}
void SaveGameProc(w, event, prms, nprms)
{
FileNamePopUp(_("Save game file name?"),
DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"),
+ appData.oldSaveStyle ? ".game" : ".pgn",
SaveGame, "a");
}
{
FileNamePopUp(_("Save position file name?"),
DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"),
+ appData.oldSaveStyle ? ".pos" : ".fen",
SavePosition, "a");
}
ShowThinkingProc(w,event,prms,nprms);
#endif
AnalyzeFileEvent();
- FileNamePopUp(_("File to analyze"), "", LoadGamePopUp, "rb");
+ FileNamePopUp(_("File to analyze"), "", ".pgn .game", LoadGamePopUp, "rb");
AnalysisPeriodicEvent(1);
}