diff options
author | marc_culler <marc.culler@gmail.com> | 2020-10-25 19:45:08 (GMT) |
---|---|---|
committer | marc_culler <marc.culler@gmail.com> | 2020-10-25 19:45:08 (GMT) |
commit | 9a4cae2ef7fa38418385bd4d35e0095f3e59cdc2 (patch) | |
tree | d3b6de3eefb28101381f44aaa447f57673cd91b1 | |
parent | 9be66cd1af6db0fad2e35ff761f35f69f13d77f4 (diff) | |
download | tk-9a4cae2ef7fa38418385bd4d35e0095f3e59cdc2.zip tk-9a4cae2ef7fa38418385bd4d35e0095f3e59cdc2.tar.gz tk-9a4cae2ef7fa38418385bd4d35e0095f3e59cdc2.tar.bz2 |
Fix [5cc72e002c]: file dialogs return an empty string on older macOS systems.
-rw-r--r-- | macosx/tkMacOSXDialog.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 42cb4a5..05cdd95 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 = [NSApp runModalForWindow:panel]; + [NSApp tkFilePanelDidEnd:panel + returnCode:modalReturnCode + contextInfo:callbackInfo ]; + [panel close]; + } } - return modalReturnCode; + return callbackInfo->cmdObj ? modalOther : modalReturnCode; } /* |