Skip to content

Commit

Permalink
#3213: Fix exception by ensuring SPBeginAlertSheet is always called o…
Browse files Browse the repository at this point in the history
…n the main thread.
  • Loading branch information
stuconnolly committed Oct 9, 2018
1 parent b50b180 commit c37bea8
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions Source/SPAlertSheets.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.