summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2021-10-28 17:30:38 (GMT)
committerculler <culler>2021-10-28 17:30:38 (GMT)
commit1b792f679cd4121f0ba1d7b919dc2b0d9b54b821 (patch)
tree6e0e780f0ab360e08b9900096ff8cf98a31deae4
parentede363592c3c712976122d329e548eb1dddf6976 (diff)
parent554073edbdc9a4d3ac707404b7b78f76eb5e46ba (diff)
downloadtk-1b792f679cd4121f0ba1d7b919dc2b0d9b54b821.zip
tk-1b792f679cd4121f0ba1d7b919dc2b0d9b54b821.tar.gz
tk-1b792f679cd4121f0ba1d7b919dc2b0d9b54b821.tar.bz2
Final fix for the macOS file dialog issues.
-rw-r--r--macosx/tkMacOSXDialog.c66
1 files changed, 26 insertions, 40 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index 08998bc..b6f4503 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;
}