Skip to content

Commit

Permalink
macos fix reset focus to main window when finished
Browse files Browse the repository at this point in the history
  • Loading branch information
mlabbe committed Dec 31, 2018
1 parent bba0f1b commit 51ad1b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/nfd_cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
if ( !*outPath )
{
[pool release];
[keyWindow makeKeyAndOrderFront:nil];
return NFD_ERROR;
}
memcpy( *outPath, utf8Path, len+1 ); /* copy null term */
Expand All @@ -163,6 +164,7 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
nfdpathset_t *outPaths )
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];

NSOpenPanel *dialog = [NSOpenPanel openPanel];
[dialog setAllowsMultipleSelection:YES];
Expand All @@ -181,19 +183,22 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
if ( [urls count] == 0 )
{
[pool release];
[keyWindow makeKeyAndOrderFront:nil];
return NFD_CANCEL;
}

if ( AllocPathSet( urls, outPaths ) == NFD_ERROR )
{
[pool release];
[keyWindow makeKeyAndOrderFront:nil];
return NFD_ERROR;
}

nfdResult = NFD_OKAY;
}
[pool release];

[keyWindow makeKeyAndOrderFront:nil];
return nfdResult;
}

Expand All @@ -203,7 +208,8 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
nfdchar_t **outPath )
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];

NSSavePanel *dialog = [NSSavePanel savePanel];
[dialog setExtensionHidden:NO];

Expand All @@ -225,14 +231,15 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
if ( !*outPath )
{
[pool release];
[keyWindow makeKeyAndOrderFront:nil];
return NFD_ERROR;
}
memcpy( *outPath, utf8Path, byteLen );
nfdResult = NFD_OKAY;
}

[pool release];

[keyWindow makeKeyAndOrderFront:nil];
return nfdResult;
}

Expand All @@ -241,7 +248,7 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath,
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
NSOpenPanel *dialog = [NSOpenPanel openPanel];
[dialog setAllowsMultipleSelection:NO];
[dialog setCanChooseDirectories:YES];
Expand All @@ -264,6 +271,7 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath,
if ( !*outPath )
{
[pool release];
[keyWindow makeKeyAndOrderFront:nil];
return NFD_ERROR;
}
memcpy( *outPath, utf8Path, len+1 ); /* copy null term */
Expand Down
2 changes: 0 additions & 2 deletions test/test_opendialogmultiple.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

int main( void )
{
nfdchar_t *outPath = NULL;

nfdpathset_t pathSet;
nfdresult_t result = NFD_OpenDialogMultiple( "png,jpg;pdf", NULL, &pathSet );
if ( result == NFD_OKAY )
Expand Down

0 comments on commit 51ad1b4

Please sign in to comment.