Permalink
Browse files

#3213: Fix exception by ensuring SPBeginAlertSheet is always called o…

…n the main thread.
  • Loading branch information...
stuconnolly committed Oct 9, 2018
1 parent b50b180 commit c37bea80c8871ed8092da9152b89d2dc3607c6fd
Showing with 25 additions and 21 deletions.
  1. +25 −21 Source/SPAlertSheets.m
View
@@ -207,30 +207,34 @@ void SPBeginAlertSheet(
void *contextInfo,
NSString *msg)
{
NSButton *aButton;
dispatch_sync(dispatch_get_main_queue(), ^{
// Set up an NSAlert with the supplied details
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
// Set up an NSAlert with the supplied details
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:title];
aButton = [alert addButtonWithTitle:defaultButton];
[aButton setTag:NSAlertDefaultReturn];
[alert setMessageText:title];
// Add 'alternate' and 'other' buttons as appropriate
if (alternateButton) {
aButton = [alert addButtonWithTitle:alternateButton];
[aButton setTag:NSAlertAlternateReturn];
}
if (otherButton) {
aButton = [alert addButtonWithTitle:otherButton];
[aButton setTag:NSAlertOtherReturn];
}
NSButton *aButton = [alert addButtonWithTitle:defaultButton];
// Set the informative message if supplied
if (msg) [alert setInformativeText:msg];
[aButton setTag:NSAlertDefaultReturn];
// Run the alert on the main thread
[[alert onMainThread] beginSheetModalForWindow:docWindow modalDelegate:modalDelegate didEndSelector:didEndSelector contextInfo:contextInfo];
// Add 'alternate' and 'other' buttons as appropriate
if (alternateButton) {
aButton = [alert addButtonWithTitle:alternateButton];
[aButton setTag:NSAlertAlternateReturn];
}
// Ensure the alerting window is frontmost
[[docWindow onMainThread] makeKeyWindow];
if (otherButton) {
aButton = [alert addButtonWithTitle:otherButton];
[aButton setTag:NSAlertOtherReturn];
}
// Set the informative message if supplied
if (msg) [alert setInformativeText:msg];
// Run the alert on the main thread
[alert beginSheetModalForWindow:docWindow modalDelegate:modalDelegate didEndSelector:didEndSelector contextInfo:contextInfo];
// Ensure the alerting window is frontmost
[docWindow makeKeyWindow];
});
}

0 comments on commit c37bea8

Please sign in to comment.