mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Support for saving sessions on the Mac. This is slightly useful even in the
absence of a config dialogue, since it allows me to get Default Settings out. [originally from svn r2646]
This commit is contained in:
parent
c66d95c0b1
commit
99c1029649
16
mac/mac.c
16
mac/mac.c
@ -1,4 +1,4 @@
|
||||
/* $Id: mac.c,v 1.32 2003/01/15 23:30:21 ben Exp $ */
|
||||
/* $Id: mac.c,v 1.33 2003/01/18 20:09:21 ben Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1999 Ben Harris
|
||||
* All rights reserved.
|
||||
@ -485,6 +485,12 @@ static void mac_menucommand(long result) {
|
||||
case iClose:
|
||||
mac_closewindow(window);
|
||||
goto done;
|
||||
case iSave:
|
||||
mac_savesession();
|
||||
goto done;
|
||||
case iSaveAs:
|
||||
mac_savesessionas();
|
||||
goto done;
|
||||
case iQuit:
|
||||
cleanup_exit(0);
|
||||
goto done;
|
||||
@ -581,10 +587,18 @@ static void mac_adjustmenus(void) {
|
||||
EnableItem(menu, iQuit);
|
||||
|
||||
switch (mac_windowtype(window)) {
|
||||
case wSettings:
|
||||
DisableItem(menu, iSave); /* XXX enable if modified */
|
||||
EnableItem(menu, iSaveAs);
|
||||
menu = GetMenuHandle(mEdit);
|
||||
DisableItem(menu, 0);
|
||||
break;
|
||||
case wTerminal:
|
||||
mac_adjusttermmenus(window);
|
||||
break;
|
||||
default:
|
||||
DisableItem(menu, iSave);
|
||||
DisableItem(menu, iSaveAs);
|
||||
menu = GetMenuHandle(mEdit);
|
||||
DisableItem(menu, 0);
|
||||
break;
|
||||
|
@ -15,6 +15,11 @@
|
||||
|
||||
#include "charset.h"
|
||||
|
||||
#define PUTTY_CREATOR FOUR_CHAR_CODE('pTTY')
|
||||
#define INTERNAL_CREATOR FOUR_CHAR_CODE('pTTI')
|
||||
#define SESS_TYPE FOUR_CHAR_CODE('Sess')
|
||||
#define SEED_TYPE FOUR_CHAR_CODE('Seed')
|
||||
|
||||
struct mac_gestalts {
|
||||
long sysvers;
|
||||
long qdvers;
|
||||
@ -81,6 +86,8 @@ extern Session *sesslist;
|
||||
|
||||
/* from macdlg.c */
|
||||
extern void mac_newsession(void);
|
||||
extern void mac_savesession(void);
|
||||
extern void mac_savesessionas(void);
|
||||
extern void mac_clickdlg(WindowPtr, EventRecord *);
|
||||
extern void mac_activatedlg(WindowPtr, EventRecord *);
|
||||
/* from macterm.c */
|
||||
@ -100,6 +107,7 @@ extern void mac_closeterm(WindowPtr);
|
||||
extern OSErr get_putty_dir(Boolean makeit, short *pVRefNum, long *pDirID);
|
||||
extern OSErr get_session_dir(Boolean makeit, short *pVRefNum, long *pDirID);
|
||||
extern void *open_settings_r_fsp(FSSpec *);
|
||||
extern void *open_settings_w_fsp(FSSpec *);
|
||||
/* from macucs.c */
|
||||
extern void init_ucs(Session *);
|
||||
/* from mtcpnet.c */
|
||||
|
29
mac/macdlg.c
29
mac/macdlg.c
@ -1,4 +1,4 @@
|
||||
/* $Id: macdlg.c,v 1.3 2003/01/18 16:54:25 ben Exp $ */
|
||||
/* $Id: macdlg.c,v 1.4 2003/01/18 20:09:21 ben Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2002 Ben Harris
|
||||
* All rights reserved.
|
||||
@ -31,6 +31,7 @@
|
||||
|
||||
#include <MacTypes.h>
|
||||
#include <Dialogs.h>
|
||||
#include <Resources.h>
|
||||
#include <StandardFile.h>
|
||||
#include <Windows.h>
|
||||
|
||||
@ -96,6 +97,32 @@ void mac_opensession(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
void mac_savesession(void)
|
||||
{
|
||||
|
||||
/* Don't remember which file a session goes with yet, so... */
|
||||
mac_savesessionas();
|
||||
}
|
||||
|
||||
void mac_savesessionas(void)
|
||||
{
|
||||
Session *s = (Session *)GetWRefCon(FrontWindow());
|
||||
StandardFileReply sfr;
|
||||
void *sesshandle;
|
||||
|
||||
StandardPutFile("\pSave session as:", "\puntitled", &sfr);
|
||||
if (!sfr.sfGood) return;
|
||||
|
||||
if (!sfr.sfReplacing) {
|
||||
FSpCreateResFile(&sfr.sfFile, PUTTY_CREATOR, SESS_TYPE, sfr.sfScript);
|
||||
if (ResError() != noErr) return; /* XXX report error */
|
||||
}
|
||||
sesshandle = open_settings_w_fsp(&sfr.sfFile);
|
||||
if (sesshandle == NULL) return; /* XXX report error */
|
||||
save_open_settings(sesshandle, TRUE, &s->cfg);
|
||||
close_settings_w(sesshandle);
|
||||
}
|
||||
|
||||
void mac_activatedlg(WindowPtr window, EventRecord *event)
|
||||
{
|
||||
DialogItemType itemtype;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: macstore.c,v 1.10 2003/01/18 16:10:21 ben Exp $ */
|
||||
/* $Id: macstore.c,v 1.11 2003/01/18 20:09:21 ben Exp $ */
|
||||
|
||||
/*
|
||||
* macstore.c: Macintosh-specific impementation of the interface
|
||||
@ -11,6 +11,7 @@
|
||||
#include <Resources.h>
|
||||
#include <TextUtils.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "putty.h"
|
||||
@ -18,11 +19,6 @@
|
||||
#include "mac.h"
|
||||
#include "macresid.h"
|
||||
|
||||
#define PUTTY_CREATOR FOUR_CHAR_CODE('pTTY')
|
||||
#define INTERNAL_CREATOR FOUR_CHAR_CODE('pTTI')
|
||||
#define SESS_TYPE FOUR_CHAR_CODE('Sess')
|
||||
#define SEED_TYPE FOUR_CHAR_CODE('Seed')
|
||||
|
||||
|
||||
OSErr FSpGetDirID(FSSpec *f, long *idp, Boolean makeit);
|
||||
|
||||
@ -123,30 +119,45 @@ struct write_settings {
|
||||
};
|
||||
|
||||
void *open_settings_w(char const *sessionname) {
|
||||
short sessVRefNum, tmpVRefNum;
|
||||
long sessDirID, tmpDirID;
|
||||
short sessVRefNum;
|
||||
long sessDirID;
|
||||
OSErr error;
|
||||
Str255 psessionname;
|
||||
struct write_settings *ws;
|
||||
FSSpec dstfile;
|
||||
|
||||
ws = safemalloc(sizeof *ws);
|
||||
error = get_session_dir(kCreateFolder, &sessVRefNum, &sessDirID);
|
||||
if (error != noErr) goto out;
|
||||
if (error != noErr) return NULL;
|
||||
|
||||
c2pstrcpy(psessionname, sessionname);
|
||||
error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &ws->dstfile);
|
||||
if (error != noErr && error != fnfErr) goto out;
|
||||
error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &dstfile);
|
||||
if (error == fnfErr) {
|
||||
FSpCreateResFile(&ws->dstfile, PUTTY_CREATOR, SESS_TYPE,
|
||||
smSystemScript);
|
||||
if ((error = ResError()) != noErr) goto out;
|
||||
}
|
||||
FSpCreateResFile(&dstfile, PUTTY_CREATOR, SESS_TYPE, smSystemScript);
|
||||
if ((error = ResError()) != noErr) return NULL;
|
||||
} else if (error != noErr) return NULL;
|
||||
|
||||
return open_settings_w_fsp(&dstfile);
|
||||
}
|
||||
|
||||
/*
|
||||
* NB: Destination file must exist.
|
||||
*/
|
||||
void *open_settings_w_fsp(FSSpec *dstfile)
|
||||
{
|
||||
short tmpVRefNum;
|
||||
long tmpDirID;
|
||||
struct write_settings *ws;
|
||||
OSErr error;
|
||||
Str255 tmpname;
|
||||
|
||||
ws = smalloc(sizeof *ws);
|
||||
ws->dstfile = *dstfile;
|
||||
|
||||
/* Create a temporary file to save to first. */
|
||||
error = FindFolder(sessVRefNum, kTemporaryFolderType, kCreateFolder,
|
||||
&tmpVRefNum, &tmpDirID);
|
||||
error = FindFolder(ws->dstfile.vRefNum, kTemporaryFolderType,
|
||||
kCreateFolder, &tmpVRefNum, &tmpDirID);
|
||||
if (error != noErr) goto out;
|
||||
error = FSMakeFSSpec(tmpVRefNum, tmpDirID, psessionname, &ws->tmpfile);
|
||||
c2pstrcpy(tmpname, tmpnam(NULL));
|
||||
error = FSMakeFSSpec(tmpVRefNum, tmpDirID, tmpname, &ws->tmpfile);
|
||||
if (error != noErr && error != fnfErr) goto out;
|
||||
if (error == noErr) {
|
||||
error = FSpDelete(&ws->tmpfile);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: macterm.c,v 1.51 2003/01/18 16:54:25 ben Exp $ */
|
||||
/* $Id: macterm.c,v 1.52 2003/01/18 20:09:21 ben Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1999 Simon Tatham
|
||||
* Copyright (c) 1999, 2002 Ben Harris
|
||||
@ -400,6 +400,9 @@ void mac_adjusttermmenus(WindowPtr window) {
|
||||
long offset;
|
||||
|
||||
s = (Session *)GetWRefCon(window);
|
||||
menu = GetMenuHandle(mFile);
|
||||
DisableItem(menu, iSave); /* XXX enable if modified */
|
||||
EnableItem(menu, iSaveAs);
|
||||
menu = GetMenuHandle(mEdit);
|
||||
EnableItem(menu, 0);
|
||||
DisableItem(menu, iUndo);
|
||||
|
1
putty.h
1
putty.h
@ -474,6 +474,7 @@ void random_destroy_seed(void);
|
||||
* Exports from settings.c.
|
||||
*/
|
||||
void save_settings(char *section, int do_host, Config * cfg);
|
||||
void save_open_settings(void *sesskey, int do_host, Config *cfg);
|
||||
void load_settings(char *section, int do_host, Config * cfg);
|
||||
void load_open_settings(void *sesskey, int do_host, Config *cfg);
|
||||
void get_sesslist(struct sesslist *, int allocate);
|
||||
|
11
settings.c
11
settings.c
@ -127,13 +127,19 @@ static void wprefs(void *sesskey, char *name,
|
||||
|
||||
void save_settings(char *section, int do_host, Config * cfg)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
void *sesskey;
|
||||
|
||||
sesskey = open_settings_w(section);
|
||||
if (!sesskey)
|
||||
return;
|
||||
save_open_settings(sesskey, do_host, cfg);
|
||||
close_settings_w(sesskey);
|
||||
}
|
||||
|
||||
void save_open_settings(void *sesskey, int do_host, Config *cfg)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
write_setting_i(sesskey, "Present", 1);
|
||||
if (do_host) {
|
||||
@ -327,7 +333,6 @@ void save_settings(char *section, int do_host, Config * cfg)
|
||||
write_setting_i(sesskey, "ScrollbarOnLeft", cfg->scrollbar_on_left);
|
||||
write_setting_s(sesskey, "BoldFont", cfg->boldfont);
|
||||
write_setting_i(sesskey, "ShadowBoldOffset", cfg->shadowboldoffset);
|
||||
close_settings_w(sesskey);
|
||||
}
|
||||
|
||||
void load_settings(char *section, int do_host, Config * cfg)
|
||||
|
Loading…
Reference in New Issue
Block a user