summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXDialog.c
diff options
context:
space:
mode:
authormarc_culler <marc.culler@gmail.com>2020-10-27 01:25:09 (GMT)
committermarc_culler <marc.culler@gmail.com>2020-10-27 01:25:09 (GMT)
commitf7356543f35d404bef87be35b949bce5c4b168b6 (patch)
treec724464af8a6cc830b15fe0e02c060b116f0de0a /macosx/tkMacOSXDialog.c
parent7c6b70ac1a979b615ed85dd9b8382811282bd609 (diff)
parentfd9301ebb217fdc1bfc1726a2ccdb450bbfc89f7 (diff)
downloadtk-f7356543f35d404bef87be35b949bce5c4b168b6.zip
tk-f7356543f35d404bef87be35b949bce5c4b168b6.tar.gz
tk-f7356543f35d404bef87be35b949bce5c4b168b6.tar.bz2
Merge 8.6
Diffstat (limited to 'macosx/tkMacOSXDialog.c')
-rw-r--r--macosx/tkMacOSXDialog.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index 8575b10..5fef145 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -23,7 +23,7 @@
#define modalOK NSModalResponseOK
#define modalCancel NSModalResponseCancel
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090
-#define modalOther -1
+#define modalOther -1 // indicates that the -command option was used.
#define modalError -2
/*
@@ -52,6 +52,10 @@ typedef struct {
* filter. */
} filepanelFilterInfo;
+/*
+ * Only one of these is needed for the application, so they can be static.
+ */
+
static filepanelFilterInfo filterInfo;
static NSOpenPanel *openpanel;
static NSSavePanel *savepanel;
@@ -250,13 +254,13 @@ getFileURL(
} else if (returnCode == modalCancel) {
Tcl_ResetResult(callbackInfo->interp);
}
- if (panel == [NSApp modalWindow]) {
- [NSApp stopModalWithCode:returnCode];
- }
if (callbackInfo->cmdObj) {
Tcl_DecrRefCount(callbackInfo->cmdObj);
+ }
+ if (callbackInfo) {
ckfree(callbackInfo);
}
+ [NSApp stopModalWithCode:returnCode];
}
- (void) tkAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) returnCode
@@ -356,14 +360,42 @@ static NSInteger showOpenSavePanel(
contextInfo:callbackInfo ];
}];
- modalReturnCode = callbackInfo->cmdObj ? modalOther :
- [panel runModal];
+ /*
+ * 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.
+ */
+
+ if ([NSApp macOSVersion] > 101400) {
+ modalReturnCode = [panel runModal];
+ } else {
+ modalReturnCode = [NSApp runModalForWindow:panel];
+ }
} else {
- modalReturnCode = [panel runModal];
- [NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
- contextInfo:callbackInfo];
+
+ /*
+ * 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) {
+ [NSApp tkFilePanelDidEnd:panel
+ returnCode:returnCode
+ contextInfo:callbackInfo ];
+ }];
+ modalReturnCode = [panel runModal];
+ } else {
+ modalReturnCode = [panel runModal];
+ [NSApp tkFilePanelDidEnd:panel
+ returnCode:modalReturnCode
+ contextInfo:callbackInfo ];
+ [panel close];
+ }
}
- return modalReturnCode;
+ return callbackInfo->cmdObj ? modalOther : modalReturnCode;
}
/*