FileBasedDocument::saveAsInteractive seems wrong


Hello Jules,

the portion of code that checks for a file name without extension is AFTER any warning concerning overwriting.

So, if FileBasedDocument::fileExtension is ‘.txt’, the user enters ‘dummy’ as the file name and a file ‘dummy.txt’ already exists, it is overwritten without any warning.

Moreover, I believe that it would be better to append, and not substitute, the default document extension to the name entered by the user.

Finally, the extension management could be improved. The document should have the chance to save data in different formats, hence the need to manage more than a single extension.

But I like JUCE anyway!



I would like to add that if FileBasedDocument::fileExtension and FileBasedDocument::fileWildcard were declared protected instead of private, the document could at least change them on the fly before showing the save dialog.

Of course this would still be a worse solution compared to a proper file filter management.



Yes… It does actually set the extension before showing the dialog, but if the user edits it in the dialog, then you’re right, it should ask again before overwriting it - I’ll sort that out. Ideally, the dialog would have a way to prevent the user from changing the extension, but I don’t think that’s possible on all platforms.

And yes, I know it could do with better extension support!


Concerning the Windows platform, I think I’ve found an easy way to manage filters properly. Let’s say we have format *.one and format *.two.

  1. In the FileBasedDocument derived class constructor, initialize the parent class ‘fileWildcard’ member passing a string like:

You could pass something more elaborate, following Microsoft specification, like “Manuals (.pdf,.txt,.chm)|.pdf;.txt;.chm”.

  1. Add to the ‘FileChooser::showPlatformDialog’ method inside ‘juce_win32_FileChooser.cpp’ (line #275) the following code:

// converts the separator char to properly manage Windows file filters for(int i = 0; i < 1024; i++) if(filters[i] == '|') filters[i] = '\0';

  1. Check the incoming file extension inside the ‘loadDocument’ and ‘saveDocument’ methods of the FileBasedDocument derived class and behave accordingly.

This should solve the problem raised by Warmonger in the ‘FileChooser filters’ topic.



Yes, it’s straightforward to do, just time-consuming to make it work the same on all platforms. On my to-do-list!