- alert_callback = callback;
- alert_ctx = ctx; /* NB this is assumed to need freeing! */
- [alert beginSheetModalForWindow:self modalDelegate:self
- didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:)
- contextInfo:NULL];
+ if (alert_ctx || alert_qhead) {
+ /*
+ * Queue this alert to be shown later.
+ */
+ struct alert_queue *qitem = snew(struct alert_queue);
+ qitem->next = NULL;
+ qitem->alert = alert;
+ qitem->callback = callback;
+ qitem->ctx = ctx;
+ if (alert_qtail)
+ alert_qtail->next = qitem;
+ else
+ alert_qhead = qitem;
+ alert_qtail = qitem;
+ } else {
+ alert_callback = callback;
+ alert_ctx = ctx; /* NB this is assumed to need freeing! */
+ [alert beginSheetModalForWindow:self modalDelegate:self
+ didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:)
+ contextInfo:NULL];
+ }