1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-02 12:02:47 -05:00

Add asynchronous callback capability to the askappend() alert box.

This was harder than verify_ssh_host_key() and askalg() put
together, because:
 (a) askappend() can be called at any time, since it's a side effect
     of data-logging functions. Therefore there can be an unfinished
     askappend() alert at any time, and hence the OS X front end has
     to be prepared to _queue_ other alerts which occur during that
     time.
 (b) logging.c has to do something with data that comes in while
     it's waiting for an answer to askappend(). It buffers it until
     it knows what the user wants done with it. This involved
     something of a reorganisation of logging.c.

[originally from svn r5344]
This commit is contained in:
Simon Tatham
2005-02-18 18:33:31 +00:00
parent 775fe9eb31
commit f73fcb0424
10 changed files with 338 additions and 176 deletions

View File

@ -306,9 +306,48 @@
* Various special-purpose dialog boxes.
*/
int askappend(void *frontend, Filename filename)
struct appendstate {
void (*callback)(void *ctx, int result);
void *ctx;
};
static void askappend_callback(void *ctx, int result)
{
return 0; /* FIXME */
struct appendstate *state = (struct appendstate *)ctx;
state->callback(state->ctx, (result == NSAlertFirstButtonReturn ? 2 :
result == NSAlertSecondButtonReturn ? 1 : 0));
sfree(state);
}
int askappend(void *frontend, Filename filename,
void (*callback)(void *ctx, int result), void *ctx)
{
static const char msgtemplate[] =
"The session log file \"%s\" already exists. "
"You can overwrite it with a new session log, "
"append your session log to the end of it, "
"or disable session logging for this session.";
char *text;
SessionWindow *win = (SessionWindow *)frontend;
struct appendstate *state;
NSAlert *alert;
text = dupprintf(msgtemplate, filename.path);
state = snew(struct appendstate);
state->callback = callback;
state->ctx = ctx;
alert = [[NSAlert alloc] init];
[alert setInformativeText:[NSString stringWithCString:text]];
[alert addButtonWithTitle:@"Overwrite"];
[alert addButtonWithTitle:@"Append"];
[alert addButtonWithTitle:@"Disable"];
[win startAlert:alert withCallback:askappend_callback andCtx:state];
return -1;
}
struct algstate {