Let file selecor remember last used directory (GTK)
[xboard.git] / dialogs.c
index 2e63442..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;
@@ -2961,6 +2967,34 @@ 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;