diff options
-rw-r--r-- | macosx/tkMacOSXDialog.c | 66 |
1 files changed, 26 insertions, 40 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 04e632d..9445b0c 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -350,55 +350,41 @@ static NSInteger showOpenSavePanel( FilePanelCallbackInfo *callbackInfo) { NSInteger modalReturnCode; + int OSVersion = [NSApp macOSVersion]; - if (parent && ![parent attachedSheet]) { - int osVersion = [NSApp macOSVersion]; - [panel beginSheetModalForWindow:parent - completionHandler:^(NSModalResponse returnCode) { - [NSApp tkFilePanelDidEnd:panel - returnCode:returnCode - contextInfo:callbackInfo ]; - }]; - - /* - * The sheet has been prepared, so now we have to run it as a modal - * window. Using [NSApp runModalForWindow:] on macOS 10.15 or later - * generates warnings on stderr. But using [NSOpenPanel runModal] or - * [NSSavePanel runModal] on 10.14 or earler does not cause the - * completion handler to run when the panel is closed. Apple apparently - * decided to go back to using runModalForWindow with the release of - * macOS 12.0. The warnings do not appear in that OS, and using - * runModal produces an error dialog that says "The open file operation - * failed to connect to the open and save panel service." along with an - * assertion error. - */ + /* + * Use a sheet if -parent is specified (unless there is already a sheet). + */ - if ( osVersion > 101400 && osVersion < 120000) { - modalReturnCode = [panel runModal]; - } else { + if (parent && ![parent attachedSheet]) { + if (OSVersion < 101500) { + [panel beginSheetModalForWindow:parent + completionHandler:^(NSModalResponse returnCode) { + [NSApp tkFilePanelDidEnd:panel + returnCode:returnCode + contextInfo:callbackInfo ]; + }]; modalReturnCode = [NSApp runModalForWindow:panel]; - } - } else { - - /* - * For the standalone file dialog, completion handlers do not work - * at all on macOS 10.14 and earlier. - */ - - if ([NSApp macOSVersion] > 101400) { - [panel beginWithCompletionHandler:^(NSModalResponse returnCode) { + } else if (OSVersion < 110000) { + [panel beginSheetModalForWindow:parent + completionHandler:^(NSModalResponse returnCode) { [NSApp tkFilePanelDidEnd:panel - returnCode:returnCode - contextInfo:callbackInfo ]; - }]; + returnCode:returnCode + contextInfo:callbackInfo ]; + }]; modalReturnCode = [panel runModal]; } else { + [parent beginSheet: panel completionHandler:nil]; modalReturnCode = [panel runModal]; [NSApp tkFilePanelDidEnd:panel - returnCode:modalReturnCode - contextInfo:callbackInfo ]; - [panel close]; + returnCode:modalReturnCode + contextInfo:callbackInfo ]; } + } else { + modalReturnCode = [panel runModal]; + [NSApp tkFilePanelDidEnd:panel + returnCode:modalReturnCode + contextInfo:callbackInfo ]; } return callbackInfo->cmdObj ? modalOther : modalReturnCode; } |