Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cocoa: Fix opening dialogs from another thread #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/nfd_cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version,
// We haven't needed to bump the interface version yet.
(void)version;

nfdresult_t result = NFD_CANCEL;
@autoreleasepool {
__block nfdresult_t result = NFD_CANCEL;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow);
if (keyWindow) {
[keyWindow makeKeyAndOrderFront:nil];
Expand All @@ -261,7 +263,9 @@ nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version,

// return focus to the key window (i.e. main window)
[keyWindow makeKeyAndOrderFront:nil];
}

[pool release];
});
return result;
}

Expand Down Expand Up @@ -295,8 +299,10 @@ nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version,
// We haven't needed to bump the interface version yet.
(void)version;

nfdresult_t result = NFD_CANCEL;
@autoreleasepool {
__block nfdresult_t result = NFD_CANCEL;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow);
if (keyWindow) {
[keyWindow makeKeyAndOrderFront:nil];
Expand Down Expand Up @@ -326,7 +332,9 @@ nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version,

// return focus to the key window (i.e. main window)
[keyWindow makeKeyAndOrderFront:nil];
}

[pool release];
});
return result;
}

Expand Down Expand Up @@ -362,8 +370,10 @@ nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version,
// We haven't needed to bump the interface version yet.
(void)version;

nfdresult_t result = NFD_CANCEL;
@autoreleasepool {
__block nfdresult_t result = NFD_CANCEL;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow);
if (keyWindow) {
[keyWindow makeKeyAndOrderFront:nil];
Expand Down Expand Up @@ -394,7 +404,9 @@ nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version,

// return focus to the key window (i.e. main window)
[keyWindow makeKeyAndOrderFront:nil];
}

[pool release];
});
return result;
}

Expand Down Expand Up @@ -424,8 +436,10 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version,
// We haven't needed to bump the interface version yet.
(void)version;

nfdresult_t result = NFD_CANCEL;
@autoreleasepool {
__block nfdresult_t result = NFD_CANCEL;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow);
if (keyWindow) {
[keyWindow makeKeyAndOrderFront:nil];
Expand All @@ -450,7 +464,9 @@ nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version,

// return focus to the key window (i.e. main window)
[keyWindow makeKeyAndOrderFront:nil];
}

[pool release];
});
return result;
}

Expand All @@ -476,8 +492,10 @@ nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version,
// We haven't needed to bump the interface version yet.
(void)version;

nfdresult_t result = NFD_CANCEL;
@autoreleasepool {
__block nfdresult_t result = NFD_CANCEL;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow);
if (keyWindow) {
[keyWindow makeKeyAndOrderFront:nil];
Expand Down Expand Up @@ -507,7 +525,9 @@ nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version,

// return focus to the key window (i.e. main window)
[keyWindow makeKeyAndOrderFront:nil];
}

[pool release];
});
return result;
}

Expand Down
Loading