Remember which file a session was opened from, so it can be the default one
authorben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sat, 18 Jan 2003 20:52:59 +0000 (20:52 +0000)
committerben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sat, 18 Jan 2003 20:52:59 +0000 (20:52 +0000)
to save back to.

git-svn-id: svn://svn.tartarus.org/sgt/putty@2648 cda61777-01e9-0310-a592-d414129be87e

mac/mac.h
mac/macdlg.c

index b93fd03..591919d 100644 (file)
--- a/mac/mac.h
+++ b/mac/mac.h
@@ -80,6 +80,8 @@ typedef struct Session {
     int                        raw_mouse;
     UnicodeToTextInfo  uni_to_font;  /* Only one of uni_to_font and     */
     charset_t          font_charset; /* font_charset is used at a time. */
+    int                        hasfile;
+    FSSpec             savefile;
 } Session;
 
 extern Session *sesslist;
index bf7c1e9..95f634e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macdlg.c,v 1.4 2003/01/18 20:09:21 ben Exp $ */
+/* $Id: macdlg.c,v 1.5 2003/01/18 20:52:59 ben Exp $ */
 /*
  * Copyright (c) 2002 Ben Harris
  * All rights reserved.
@@ -35,6 +35,7 @@
 #include <StandardFile.h>
 #include <Windows.h>
 
+#include <assert.h>
 #include <string.h>
 
 #include "putty.h"
@@ -51,6 +52,7 @@ void mac_newsession(void)
     memset(s, 0, sizeof(*s));
     do_defaults(NULL, &s->cfg);
     s->back = &loop_backend;
+    s->hasfile = FALSE;
 
     s->settings_window = GetNewDialog(wSettings, NULL, (WindowPtr)-1);
 
@@ -75,6 +77,12 @@ void mac_opensession(void) {
     if (sesshandle == NULL) goto fail;
     load_open_settings(sesshandle, TRUE, &s->cfg);
     close_settings_r(sesshandle);
+    if (sfr.sfFlags & kIsStationery)
+       s->hasfile = FALSE;
+    else {
+       s->hasfile = TRUE;
+       s->savefile = sfr.sfFile;
+    }
 
     /*
      * Select protocol. This is farmed out into a table in a
@@ -99,9 +107,14 @@ void mac_opensession(void) {
 
 void mac_savesession(void)
 {
+    Session *s = (Session *)GetWRefCon(FrontWindow());
+    void *sesshandle;
 
-    /* Don't remember which file a session goes with yet, so... */
-    mac_savesessionas();
+    assert(s->hasfile);
+    sesshandle = open_settings_w_fsp(&s->savefile);
+    if (sesshandle == NULL) return; /* XXX report error */
+    save_open_settings(sesshandle, TRUE, &s->cfg);
+    close_settings_w(sesshandle);
 }
 
 void mac_savesessionas(void)
@@ -110,7 +123,8 @@ void mac_savesessionas(void)
     StandardFileReply sfr;
     void *sesshandle;
 
-    StandardPutFile("\pSave session as:", "\puntitled", &sfr);
+    StandardPutFile("\pSave session as:",
+                   s->hasfile ? s->savefile.name : "\puntitled", &sfr);
     if (!sfr.sfGood) return;
 
     if (!sfr.sfReplacing) {
@@ -121,6 +135,8 @@ void mac_savesessionas(void)
     if (sesshandle == NULL) return; /* XXX report error */
     save_open_settings(sesshandle, TRUE, &s->cfg);
     close_settings_w(sesshandle);
+    s->hasfile = TRUE;
+    s->savefile = sfr.sfFile;
 }
 
 void mac_activatedlg(WindowPtr window, EventRecord *event)