From 1142e81348aae4a0d37081455da70d47b1a3384a Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 12 Nov 2023 17:06:11 +1100 Subject: [PATCH] [darwin] fix CATransaction errors. Update docs. --- mkdocs-website/docs/en/roadmap.md | 9 -- mkdocs-website/docs/zh/roadmap.md | 8 -- mkdocs-website/shared/status.csv | 4 +- v3/pkg/application/dialogs_darwin.go | 208 +++++++++++++-------------- 4 files changed, 103 insertions(+), 126 deletions(-) diff --git a/mkdocs-website/docs/en/roadmap.md b/mkdocs-website/docs/en/roadmap.md index 04cc012b..3cec59f8 100644 --- a/mkdocs-website/docs/en/roadmap.md +++ b/mkdocs-website/docs/en/roadmap.md @@ -22,15 +22,6 @@ examples working on all platforms. {{ read_csv("status.csv") }} -- Mac Dialogs work, however the file dialogs issue a warning that needs to be - fixed. - -#### TODO: - -- [ ] Fix `+[CATransaction synchronize] called within transaction` warnings on - Mac -- [ ] When hiding window, application terminates - ### Alpha 2 - [ ] Most examples working on Linux diff --git a/mkdocs-website/docs/zh/roadmap.md b/mkdocs-website/docs/zh/roadmap.md index d611ea58..432504ab 100644 --- a/mkdocs-website/docs/zh/roadmap.md +++ b/mkdocs-website/docs/zh/roadmap.md @@ -20,14 +20,6 @@ Alpha 1 是最初的发布版本。旨在收集关于新 API 的反馈,并让 {{ read_csv("status.csv") }} -- Mac 上的 Dialogs 可以工作,但是文件对话框会发出一个需要解决的警告。 - -#### TODO: - -- [ ] 修复 Mac 上的 `+[CATransaction synchronize] called within transaction` 警 - 告 -- [ ] 隐藏窗口时,应用程序终止 - ### Alpha 2 - [ ] 在 Linux 上使大多数示例正常工作 diff --git a/mkdocs-website/shared/status.csv b/mkdocs-website/shared/status.csv index 40638e51..f372dc65 100644 --- a/mkdocs-website/shared/status.csv +++ b/mkdocs-website/shared/status.csv @@ -3,7 +3,7 @@ binding,:material-check-bold:,:material-check-bold:,:material-check-bold: build,:material-check-bold:,:material-check-bold:,:material-check-bold: clipboard,:material-check-bold:,:material-check-bold:,:material-check-bold: context menus,:material-check-bold:,:material-check-bold:,:material-check-bold: -dialogs,:material-minus:,:material-check-bold:,:material-check-bold: +dialogs,:material-check-bold:,:material-check-bold:,:material-check-bold: drag-n-drop,:material-check-bold:,:material-check-bold:,:material-check-bold: events,:material-check-bold:,:material-check-bold:,:material-minus: frameless,:material-check-bold:,:material-check-bold:,:material-check-bold: @@ -12,5 +12,5 @@ plain,:material-check-bold:,:material-check-bold:,:material-check-bold: screen,:material-check-bold:,:material-check-bold:,:material-check-bold: systray,:material-check-bold:,:material-check-bold:,:material-check-bold: video,:material-check-bold:,:material-check-bold:,:material-check-bold: -window,:material-minus:,:material-check-bold:,:material-minus: +window,:material-check-bold:,:material-check-bold:,:material-minus: wml,:material-check-bold:,:material-check-bold:,:material-check-bold: \ No newline at end of file diff --git a/v3/pkg/application/dialogs_darwin.go b/v3/pkg/application/dialogs_darwin.go index bdd7aa28..d2cebaf7 100644 --- a/v3/pkg/application/dialogs_darwin.go +++ b/v3/pkg/application/dialogs_darwin.go @@ -163,73 +163,70 @@ static void showOpenFileDialog(unsigned int dialogID, void *window) { // run on main thread - dispatch_async(dispatch_get_main_queue(), ^{ + NSOpenPanel *panel = [NSOpenPanel openPanel]; - NSOpenPanel *panel = [NSOpenPanel openPanel]; + // print out filterPatterns if length > 0 + if (filterPatternsCount > 0) { + OpenPanelDelegate *delegate = [[OpenPanelDelegate alloc] init]; + [panel setDelegate:delegate]; + // Initialise NSString with bytes and UTF8 encoding + NSString *filterPatternsString = [[NSString alloc] initWithBytes:filterPatterns length:filterPatternsCount encoding:NSUTF8StringEncoding]; + // Convert NSString to NSArray + delegate.allowedExtensions = [filterPatternsString componentsSeparatedByString:@";"]; - // print out filterPatterns if length > 0 - if (filterPatternsCount > 0) { - OpenPanelDelegate *delegate = [[OpenPanelDelegate alloc] init]; - [panel setDelegate:delegate]; - // Initialise NSString with bytes and UTF8 encoding - NSString *filterPatternsString = [[NSString alloc] initWithBytes:filterPatterns length:filterPatternsCount encoding:NSUTF8StringEncoding]; - // Convert NSString to NSArray - delegate.allowedExtensions = [filterPatternsString componentsSeparatedByString:@";"]; - - // Use UTType if macOS 11 or higher to add file filters - if (@available(macOS 11, *)) { - NSMutableArray *filterTypes = [NSMutableArray array]; - // Iterate the filtertypes, create uti's that are limited to the file extensions then add - for (NSString *filterType in delegate.allowedExtensions) { - [filterTypes addObject:[UTType typeWithFilenameExtension:filterType]]; - } - [panel setAllowedContentTypes:filterTypes]; - } else { - [panel setAllowedFileTypes:delegate.allowedExtensions]; + // Use UTType if macOS 11 or higher to add file filters + if (@available(macOS 11, *)) { + NSMutableArray *filterTypes = [NSMutableArray array]; + // Iterate the filtertypes, create uti's that are limited to the file extensions then add + for (NSString *filterType in delegate.allowedExtensions) { + [filterTypes addObject:[UTType typeWithFilenameExtension:filterType]]; } - - // Free the memory - free(filterPatterns); - } - - - if (message != NULL) { - [panel setMessage:[NSString stringWithUTF8String:message]]; - free(message); - } - - if (directory != NULL) { - [panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:directory]]]; - free(directory); - } - - if (buttonText != NULL) { - [panel setPrompt:[NSString stringWithUTF8String:buttonText]]; - free(buttonText); - } - - [panel setCanChooseFiles:canChooseFiles]; - [panel setCanChooseDirectories:canChooseDirectories]; - [panel setCanCreateDirectories:canCreateDirectories]; - [panel setShowsHiddenFiles:showHiddenFiles]; - [panel setAllowsMultipleSelection:allowsMultipleSelection]; - [panel setResolvesAliases:resolvesAliases]; - [panel setExtensionHidden:hideExtension]; - [panel setTreatsFilePackagesAsDirectories:treatsFilePackagesAsDirectories]; - [panel setAllowsOtherFileTypes:allowsOtherFileTypes]; - - - - if (window != NULL) { - [panel beginSheetModalForWindow:(__bridge NSWindow *)window completionHandler:^(NSInteger result) { - processOpenFileDialogResults(panel, result, dialogID); - }]; + [panel setAllowedContentTypes:filterTypes]; } else { - [panel beginWithCompletionHandler:^(NSInteger result) { - processOpenFileDialogResults(panel, result, dialogID); - }]; + [panel setAllowedFileTypes:delegate.allowedExtensions]; } - }); + + // Free the memory + free(filterPatterns); + } + + + if (message != NULL) { + [panel setMessage:[NSString stringWithUTF8String:message]]; + free(message); + } + + if (directory != NULL) { + [panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:directory]]]; + free(directory); + } + + if (buttonText != NULL) { + [panel setPrompt:[NSString stringWithUTF8String:buttonText]]; + free(buttonText); + } + + [panel setCanChooseFiles:canChooseFiles]; + [panel setCanChooseDirectories:canChooseDirectories]; + [panel setCanCreateDirectories:canCreateDirectories]; + [panel setShowsHiddenFiles:showHiddenFiles]; + [panel setAllowsMultipleSelection:allowsMultipleSelection]; + [panel setResolvesAliases:resolvesAliases]; + [panel setExtensionHidden:hideExtension]; + [panel setTreatsFilePackagesAsDirectories:treatsFilePackagesAsDirectories]; + [panel setAllowsOtherFileTypes:allowsOtherFileTypes]; + + + + if (window != NULL) { + [panel beginSheetModalForWindow:(__bridge NSWindow *)window completionHandler:^(NSInteger result) { + processOpenFileDialogResults(panel, result, dialogID); + }]; + } else { + [panel beginWithCompletionHandler:^(NSInteger result) { + processOpenFileDialogResults(panel, result, dialogID); + }]; + } } static void showSaveFileDialog(unsigned int dialogID, @@ -245,57 +242,54 @@ static void showSaveFileDialog(unsigned int dialogID, char* filename, void *window) { - // run on main thread - dispatch_async(dispatch_get_main_queue(), ^{ - NSSavePanel *panel = [NSSavePanel savePanel]; + NSSavePanel *panel = [NSSavePanel savePanel]; - if (message != NULL) { - [panel setMessage:[NSString stringWithUTF8String:message]]; - free(message); - } + if (message != NULL) { + [panel setMessage:[NSString stringWithUTF8String:message]]; + free(message); + } - if (directory != NULL) { - [panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:directory]]]; - free(directory); - } + if (directory != NULL) { + [panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:directory]]]; + free(directory); + } - if (filename != NULL) { - [panel setNameFieldStringValue:[NSString stringWithUTF8String:filename]]; - free(filename); - } + if (filename != NULL) { + [panel setNameFieldStringValue:[NSString stringWithUTF8String:filename]]; + free(filename); + } - if (buttonText != NULL) { - [panel setPrompt:[NSString stringWithUTF8String:buttonText]]; - free(buttonText); - } + if (buttonText != NULL) { + [panel setPrompt:[NSString stringWithUTF8String:buttonText]]; + free(buttonText); + } - [panel setCanCreateDirectories:canCreateDirectories]; - [panel setShowsHiddenFiles:showHiddenFiles]; - [panel setCanSelectHiddenExtension:canSelectHiddenExtension]; - [panel setExtensionHidden:hideExtension]; - [panel setTreatsFilePackagesAsDirectories:treatsFilePackagesAsDirectories]; - [panel setAllowsOtherFileTypes:allowOtherFileTypes]; + [panel setCanCreateDirectories:canCreateDirectories]; + [panel setShowsHiddenFiles:showHiddenFiles]; + [panel setCanSelectHiddenExtension:canSelectHiddenExtension]; + [panel setExtensionHidden:hideExtension]; + [panel setTreatsFilePackagesAsDirectories:treatsFilePackagesAsDirectories]; + [panel setAllowsOtherFileTypes:allowOtherFileTypes]; - if (window != NULL) { - [panel beginSheetModalForWindow:(__bridge NSWindow *)window completionHandler:^(NSInteger result) { - const char *path = NULL; - if (result == NSModalResponseOK) { - NSURL *url = [panel URL]; - path = [[url path] UTF8String]; - } - saveFileDialogCallback(dialogID, (char *)path); - }]; - } else { - [panel beginWithCompletionHandler:^(NSInteger result) { - const char *path = NULL; - if (result == NSModalResponseOK) { - NSURL *url = [panel URL]; - path = [[url path] UTF8String]; - } - saveFileDialogCallback(dialogID, (char *)path); - }]; - } - }); + if (window != NULL) { + [panel beginSheetModalForWindow:(__bridge NSWindow *)window completionHandler:^(NSInteger result) { + const char *path = NULL; + if (result == NSModalResponseOK) { + NSURL *url = [panel URL]; + path = [[url path] UTF8String]; + } + saveFileDialogCallback(dialogID, (char *)path); + }]; + } else { + [panel beginWithCompletionHandler:^(NSInteger result) { + const char *path = NULL; + if (result == NSModalResponseOK) { + NSURL *url = [panel URL]; + path = [[url path] UTF8String]; + } + saveFileDialogCallback(dialogID, (char *)path); + }]; + } } */