Native FileChooser : Most Recently Used Directory with Pre-populated Filename

Hello all,

I am using a Native FileChooser to save and load files. I want to open the FileChooser in the most recently used directory by any previous FileChoosers AND pre-populate the FileChooser file name field. I have been able to satisfy both of these constraints separately but not together.

1. FileChooser opens most recently used directory

FileChooser myChooser ("Save a File");
if (myChooser.browseForFileToSave(true))
   // Save the file . . .

In this instance, the constructor for FileChooser chooses a “sensible default directory” (as explained in the constructor documentation) and has the most recent directory behavior I want. The next FileChooser I open will open in the last directory used by the previous FileChooser. This is the behavior I want for directory placement.

2. FileChooser has pre-populated file name

File filePath;
filePath = filePath.getChildFile ("MyFile.txt");
FileChooser myChooser ("Save a File", filePath);
if (myChooser.browseForFileToSave(true))
   // Save the file . . .

In this instance, my FileChooser always shows the root directory with the pre-populated file name “MyFile.txt”. So the full path is /MyFile.txt. This behavior totally makes sense to me, because that is the path that I gave to the FileChooser. But, is there a way for me to load a FileChooser to have a pre-populated file name in the most recently used directory?


I have only run my JUCE program on Mac.

In the JUCE source code, I was unable to find where the FileChooser's constructor parameter initialFileOrDirectory gets converted from a default File() to this magical recently used directory that I am looking for. I thought there might be a File::SpecialLocationType for this, but was unable to find it.

Thanks for any help on this!

Best,
Tim

Keep track of the most recently used directory, and use that. I think your experience with it doing what you want was by chance, not by design.

Okay, thanks for the help! This is the solution I am now using where I keep a File object around which I update with the most recently used directory.

I thought the behavior of the most recently used directory was some kind of automatic JUCE feature I could access, but that may not be the case.