Skip to content

Commit

Permalink
add openFile directory selection for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
xplane authored and xplane committed Jun 8, 2024
1 parent f609a65 commit dbb3814
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Utils/PlatformUtils.lin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 9 additions & 4 deletions src/Utils/PlatformUtils.mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ int GetFilePathFromUserInternal(
const char * inDefaultFileName,
int inID,
int inMulti,
vector<string>& outFiles)
vector<string>& outFiles,
const char * initialPath)
{
if(inType == getFile_Open || inType == getFile_PickFolder)
{
Expand All @@ -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)
Expand Down Expand Up @@ -114,7 +119,7 @@ int GetFilePathFromUser(
const char * initialPath)
{
vector<string> 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;
Expand All @@ -129,7 +134,7 @@ int GetFilePathFromUser(
const char * initialPath)
{
vector<string> 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;
Expand Down

0 comments on commit dbb3814

Please sign in to comment.