[Bug] Juce FileChooser and browseForFileToOpen can open directory


When using the Juce (non-native) FileChooser and browseForFileToOpen, the “open” button is enabled even when a file is not selected, or when a folder is selected:

FileChooser fileChooser("Hello", File(), String(), false);
bool success = fileChooser.browseForFileToOpen();

When using the code above, the “open” button is directly enabled, whereas nothing is selected. Unless I’m wrong, the doc states “it won’t allow non-existent files or directories to be chosen”.
The getResult method returns a path to the folder in these conditions.

I’m using the latest tip on Master. Isn’t there a regression? Because I’m pretty sure it was working some times ago. It happens on Windows, but also on Linux apparently.


Can you see if this commit fixes the issue for you?

This works much better, thanks! (I tested on Windows and Linux).

However, I noticed a little flaw: the “open” button is disabled when a folder is selected. I believe the normal behavior (for the “browseForFileToOpen” method) would be to have the “open” button open a folder when one is selected, and open a file when one is selected. So in my opinion, the “open” button should not be disabled when a folder is selected. Because with your patch, the only way to enter inside a folder, is to double-click on it. Clicking on “open” should also be available.

1 Like