How do I specify the initial directory and file name in a FileChooser save dialog? Suppose I want the initial text to be “MyFile.text”, and I want the initial directory to be the desktop. Here’s what I’m doing currently:
On Windows, this seems to work fine, but on the Mac this doesn’t seem to do anything. The initial directory is always whatever the user last navigated to the last time the save dialog was shown, and the initial filename is always “untitled”. This happens regardless of whether MyFile.txt already exists or not.
Well, the file does get passed into the OS code, so not sure why it’s not getting used. I need to re-write all that code in obj-C shortly anyway, so not much point me spending time debugging it now.
Blast from the past… I just looked into this a bit more. Turns out the filename is not passed to the options struct to tell the dialog to use that as the default filename in the save dialog. Here’s the fix if anyone is interested.
In juce_mac_FileChooser.cpp, in FileChooser::showPlatformDialog(), look for this:
I have the same issue, but on revision 690 so jimw’s solution won’t work. I’m sending in proper full path, and it is the default name in the save dialog on XP/Vista, but not on Mac. I’ve looked at the code vs. Apple’s documentation, but I can’t find the problem with the code.
Any ideas, or is this perhaps fixed in a later revision?
I’m wondering if this issue has ever been resolved. I am trying to populate the textfield in the Filechooser with a default filename as follows, but nothing happens. the field is blank on OS X:
StringRef sr = serverAppInterface->getSessionID().toISO8601(false) + ".mid";
FileChooser fc("Select a location",
File::getSpecialLocation(File::userMusicDirectory).getChildFile(sr),
"*.mid;",
true);
The idea is that when the FileChooser window pops up, the name of the file is already populated and selected, and if the user wants to, they can type their own, or just press Return and use the given filename.