If something goes wrong saving a file, I'd like to show the error alert as a sheet over the save sheet, as overwrite prompt does. However, the save panel closes immediately upon the completion of the completion block, taking the error alert with it.
[panel beginSheetModalForWindow:window
completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
NSError *error;
// Do my saving here...
if (error)
[[NSAlert alertWithError:error] beginSheetModalForWindow:panel
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
}
}];
Can I cancel hiding the NSSavePanel from within the completion block? From a delegate? From anything?
I just checked in TextEdit and what it does in the case you're after—not confirmation of the save, but failure of the save—is the following:
So, if you want Apple-like behavior, show your alert sheet on the document window.
Incidentally, you may be interested in presentError:modalForWindow:delegate:didPresentSelector:contextInfo:
.