From dbb3814ba252457b6f87b19282ce9058ac50e1f8 Mon Sep 17 00:00:00 2001 From: xplane Date: Sat, 8 Jun 2024 01:17:05 -0700 Subject: [PATCH] add openFile directory selection for macOS --- src/Utils/PlatformUtils.lin.cpp | 4 ++-- src/Utils/PlatformUtils.mac.mm | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Utils/PlatformUtils.lin.cpp b/src/Utils/PlatformUtils.lin.cpp index 4841ae4d3..9c3c98720 100644 --- a/src/Utils/PlatformUtils.lin.cpp +++ b/src/Utils/PlatformUtils.lin.cpp @@ -134,14 +134,14 @@ char * GetMultiFilePathFromUser( const char * inPrompt, const char * inAction, int inID, - const char * initalPath) + const char * initialPath) { char * ret = NULL; Fl_Native_File_Chooser * mFileDialog = new Fl_Native_File_Chooser(); mFileDialog->title(inPrompt); mFileDialog->type(Fl_Native_File_Chooser::BROWSE_MULTI_FILE); - if (initalPath) mFileDialog->directory(initialPath); + if (initialPath) mFileDialog->directory(initialPath); if(mFileDialog->show() == 0) { diff --git a/src/Utils/PlatformUtils.mac.mm b/src/Utils/PlatformUtils.mac.mm index 39395523e..e0c5df0d7 100644 --- a/src/Utils/PlatformUtils.mac.mm +++ b/src/Utils/PlatformUtils.mac.mm @@ -66,7 +66,8 @@ int GetFilePathFromUserInternal( const char * inDefaultFileName, int inID, int inMulti, - vector& outFiles) + vector& outFiles, + const char * initialPath) { if(inType == getFile_Open || inType == getFile_PickFolder) { @@ -77,7 +78,11 @@ int GetFilePathFromUserInternal( [panel setCanCreateDirectories:(inType == getFile_PickFolder || inType == getFile_Save)]; [panel setPrompt:[NSString stringWithUTF8String:inAction]]; // NOT A TYPO: NSOpenPanel calls the button text the "prompt" and the text on the window the "message" [panel setMessage:[NSString stringWithUTF8String:inPrompt]]; // NOT A TYPO: NSOpenPanel calls the button text the "prompt" and the text on the window the "message" - if([panel runModal] == NSFileHandlingPanelOKButton) + if(initialPath) + { + [panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:initialPath] isDirectory:true]]; + } + if([panel runModal] == NSFileHandlingPanelOKButton) { NSArray * urls = [panel URLs]; for(NSURL * url in urls) @@ -114,7 +119,7 @@ int GetFilePathFromUser( const char * initialPath) { vector files; - if(!GetFilePathFromUserInternal(inType,inPrompt,inAction, outFileName, inID, 0, files)) + if(!GetFilePathFromUserInternal(inType,inPrompt,inAction, outFileName, inID, 0, files, initialPath)) return 0; if(files.size() != 1) return 0; @@ -129,7 +134,7 @@ int GetFilePathFromUser( const char * initialPath) { vector files; - if(!GetFilePathFromUserInternal(getFile_Open,inPrompt,inAction, "", inID, 1, files)); + if(!GetFilePathFromUserInternal(getFile_Open,inPrompt,inAction, "", inID, 1, files, initialPath)) return NULL; if(files.size() < 1) return NULL;