X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/b537dd42c1da03890c832e94a4f47369ca3d99af..1dfd2cd6e4b2b02f19f7b3d418f8a31e634d88ce:/mac/macdlg.c diff --git a/mac/macdlg.c b/mac/macdlg.c index bf7c1e9d..2606f0b0 100644 --- a/mac/macdlg.c +++ b/mac/macdlg.c @@ -1,4 +1,4 @@ -/* $Id: macdlg.c,v 1.4 2003/01/18 20:09:21 ben Exp $ */ +/* $Id: macdlg.c,v 1.7 2003/01/25 14:04:47 ben Exp $ */ /* * Copyright (c) 2002 Ben Harris * All rights reserved. @@ -30,11 +30,14 @@ */ #include +#include +#include #include #include #include #include +#include #include #include "putty.h" @@ -51,6 +54,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); @@ -58,21 +62,32 @@ void mac_newsession(void) ShowWindow(s->settings_window); } -void mac_opensession(void) { +static OSErr mac_opensessionfrom(FSSpec *fss) +{ + FInfo fi; Session *s; - StandardFileReply sfr; - static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; void *sesshandle; int i; + OSErr err; s = smalloc(sizeof(*s)); memset(s, 0, sizeof(*s)); - StandardGetFile(NULL, 1, sftypes, &sfr); - if (!sfr.sfGood) goto fail; + err = FSpGetFInfo(fss, &fi); + if (err != noErr) return err; + if (fi.fdFlags & kIsStationery) + s->hasfile = FALSE; + else { + s->hasfile = TRUE; + s->savefile = *fss; + } - sesshandle = open_settings_r_fsp(&sfr.sfFile); - if (sesshandle == NULL) goto fail; + sesshandle = open_settings_r_fsp(fss); + if (sesshandle == NULL) { + /* XXX need a way to pass up an error number */ + err = -9999; + goto fail; + } load_open_settings(sesshandle, TRUE, &s->cfg); close_settings_r(sesshandle); @@ -90,18 +105,34 @@ void mac_opensession(void) { fatalbox("Unsupported protocol number found"); } mac_startsession(s); - return; + return noErr; fail: sfree(s); - return; + return err; +} + +void mac_opensession(void) { + StandardFileReply sfr; + static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; + + StandardGetFile(NULL, 1, sftypes, &sfr); + if (!sfr.sfGood) return; + + mac_opensessionfrom(&sfr.sfFile); + /* XXX handle error */ } 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 +141,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 +153,72 @@ 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; +} + +pascal OSErr mac_aevt_oapp(const AppleEvent *req, AppleEvent *reply, + long refcon) +{ + DescType type; + Size size; + + if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, + &type, NULL, 0, &size) == noErr) + return errAEParamMissed; + + /* XXX we should do something here. */ + return noErr; +} + +pascal OSErr mac_aevt_odoc(const AppleEvent *req, AppleEvent *reply, + long refcon) +{ + DescType type; + AEKeyword keywd; + Size size; + AEDescList docs = { typeNull, NULL }; + OSErr err; + long ndocs, i; + FSSpec fss; + + err = AEGetParamDesc(req, keyDirectObject, typeAEList, &docs); + if (err != noErr) goto out; + + if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, + &type, NULL, 0, &size) == noErr) { + err = errAEParamMissed; + goto out; + } + + err = AECountItems(&docs, &ndocs); + if (err != noErr) goto out; + + for (i = 0; i < ndocs; i++) { + err = AEGetNthPtr(&docs, i + 1, typeFSS, + &keywd, &type, &fss, sizeof(fss), &size); + if (err != noErr) goto out; + err = mac_opensessionfrom(&fss); + if (err != noErr) goto out; + } + + out: + AEDisposeDesc(&docs); + return err; +} + +pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply, + long refcon) +{ + DescType type; + Size size; + + if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, + &type, NULL, 0, &size) == noErr) + return errAEParamMissed; + + /* We can't meaningfully do anything here. */ + return errAEEventNotHandled; } void mac_activatedlg(WindowPtr window, EventRecord *event)