Let file selecor remember last used directory (GTK)
[xboard.git] / dialogs.c
index 45209e6..e932247 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -2544,6 +2544,12 @@ Exp (int n, int x, int y)
     static int but1, but3, oldW, oldH;
     int menuNr = -3, sizing, f, r;
     TimeMark now;
+    extern Boolean right;
+
+    if(right) {  // kludgy way to let button 1 double as button 3 when back-end requests this
+       if(but1 && n == 0) but1 = 0, but3 = 1;
+       else if(n == -1) n = -3, right = FALSE;
+    }
 
     if(n == 0) { // motion
        if(SeekGraphClick(Press, x, y, 1)) return NULL;
@@ -2724,6 +2730,7 @@ DisplayMessage (char *message, char *extMessage)
 
 #define MAXFILES 1000
 
+static DialogClass savDlg;
 static ChessProgramState *savCps;
 static FILE **savFP;
 static char *fileName, *extFilter, *savMode, **namePtr;
@@ -2806,7 +2813,7 @@ BrowseOK (int n)
                    snprintf(title, MSG_SIZ, "%s", fileName);
                else
                    snprintf(title, MSG_SIZ, "%s/%s", curDir, fileName);
-               SetWidgetText((Option*) savFP, title, TransientDlg);
+               SetWidgetText((Option*) savFP, title, savDlg);
                currentCps = savCps; // could return to Engine Settings dialog!
                return TRUE;
        }
@@ -2960,10 +2967,38 @@ DirSelProc (int n, int sel)
 }
 
 void
+StartDir (char *filter, char *newName)
+{
+    static char *gamesDir, *trnDir, *imgDir, *bookDir;
+    static char curDir[MSG_SIZ];
+    char **res = NULL;
+    if(!filter || !*filter) return;
+    if(strstr(filter, "pgn")) res = &gamesDir; else
+    if(strstr(filter, "bin")) res = &bookDir; else
+    if(strstr(filter, "png")) res = &imgDir; else
+    if(strstr(filter, "trn")) res = &trnDir; else
+    if(strstr(filter, "fen")) res = &appData.positionDir;
+    if(res) {
+       if(newName) {
+           char *p, *q;
+           if(*newName) {
+               ASSIGN(*res, newName);
+               for(p=*res; q=strchr(p, '/');) p = q + 1; *p = NULLCHAR;
+           }
+           if(*curDir) chdir(curDir);
+           *curDir = NULLCHAR;
+       } else {
+           getcwd(curDir, MSG_SIZ);
+           if(*res && **res) chdir(*res);
+       }
+    }
+}
+
+void
 Browse (DialogClass dlg, char *label, char *proposed, char *ext, Boolean pathFlag, char *mode, char **name, FILE **fp)
 {
     int j=0;
-    savFP = fp; savMode = mode, namePtr = name, savCps = currentCps, oldVal = values[9]; // save params, for use in callback
+    savFP = fp; savMode = mode, namePtr = name, savCps = currentCps, oldVal = values[9], savDlg = dlg; // save params, for use in callback
     ASSIGN(extFilter, ext);
     ASSIGN(fileName, proposed ? proposed : "");
     for(j=0; Extensions[j]; j++) // look up actual value in list of possible values, to get selection nr