commit 62996d5578702fde52e309528d6a4a894a7b3997
parent b800b5275916e9e99fa4ebae0c8044f2e84df170
Author: falkTX <falktx@falktx.com>
Date: Tue, 26 Oct 2021 18:12:58 +0100
Make macOS open file dialog truly async
Diffstat:
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp
@@ -539,8 +539,8 @@ bool puglMacOSFilePanelOpen(PuglView* const view,
NSOpenPanel* const panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:NO];
- [panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
+ [panel setCanChooseFiles:YES];
[panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:startDir]]];
// TODO file filter using allowedContentTypes: [UTType]
@@ -556,19 +556,22 @@ bool puglMacOSFilePanelOpen(PuglView* const view,
encoding:NSUTF8StringEncoding];
[panel setTitle:titleString];
- [panel beginSheetModalForWindow:(impl->window ? impl->window : [view->impl->wrapperView window])
- completionHandler:^(NSInteger result)
+ dispatch_async(dispatch_get_main_queue(), ^
{
- if (result == NSModalResponseOK && [[panel URL] isFileURL])
- {
- NSString* const path = [[panel URL] path];
- callback(view, [path UTF8String]);
- }
- else
+ [panel beginSheetModalForWindow:(impl->window ? impl->window : [view->impl->wrapperView window])
+ completionHandler:^(NSModalResponse result)
{
- callback(view, nullptr);
- }
- }];
+ if (result == NSModalResponseOK && [[panel URL] isFileURL])
+ {
+ NSString* const path = [[panel URL] path];
+ callback(view, [path UTF8String]);
+ }
+ else
+ {
+ callback(view, nullptr);
+ }
+ }];
+ });
return true;
}