[darwin] fix CATransaction errors. Update docs.

This commit is contained in:
Lea Anthony
2023-11-12 17:06:11 +11:00
parent ae38d1e020
commit 1142e81348
4 changed files with 103 additions and 126 deletions
-9
View File
@@ -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
-8
View File
@@ -20,14 +20,6 @@ Alpha 1 是最初的发布版本。旨在收集关于新 API 的反馈,并让
{{ read_csv("status.csv") }}
- Mac 上的 Dialogs 可以工作,但是文件对话框会发出一个需要解决的警告。
#### TODO:
- [ ] 修复 Mac 上的 `+[CATransaction synchronize] called within transaction`
- [ ] 隐藏窗口时,应用程序终止
### Alpha 2
- [ ] 在 Linux 上使大多数示例正常工作
+2 -2
View File
@@ -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:
1 Mac Windows Linux
3 build :material-check-bold: :material-check-bold: :material-check-bold:
4 clipboard :material-check-bold: :material-check-bold: :material-check-bold:
5 context menus :material-check-bold: :material-check-bold: :material-check-bold:
6 dialogs :material-minus: :material-check-bold: :material-check-bold: :material-check-bold:
7 drag-n-drop :material-check-bold: :material-check-bold: :material-check-bold:
8 events :material-check-bold: :material-check-bold: :material-minus:
9 frameless :material-check-bold: :material-check-bold: :material-check-bold:
12 screen :material-check-bold: :material-check-bold: :material-check-bold:
13 systray :material-check-bold: :material-check-bold: :material-check-bold:
14 video :material-check-bold: :material-check-bold: :material-check-bold:
15 window :material-minus: :material-check-bold: :material-check-bold: :material-minus:
16 wml :material-check-bold: :material-check-bold: :material-check-bold:
+101 -107
View File
@@ -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);
}];
}
}
*/