diff options
Diffstat (limited to 'macosx/tkMacOSXDialog.c')
-rw-r--r-- | macosx/tkMacOSXDialog.c | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 4bcaedf..f6b8357 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -350,49 +350,42 @@ static NSInteger showOpenSavePanel( FilePanelCallbackInfo *callbackInfo) { NSInteger modalReturnCode; + int OSVersion = [NSApp macOSVersion]; - if (parent && ![parent attachedSheet]) { - [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. - */ + /* + * Use a sheet if -parent is specified (unless there is already a sheet). + */ - if ([NSApp macOSVersion] > 101400) { - 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 ]; + [parent endSheet:panel]; } + } else { + modalReturnCode = [panel runModal]; + [NSApp tkFilePanelDidEnd:panel + returnCode:modalReturnCode + contextInfo:callbackInfo ]; } return callbackInfo->cmdObj ? modalOther : modalReturnCode; } |