FileBrowserComponent with save and directory


#1

This is a regression from 1.53.

If you create a FileBrowserComponent with saveMode + canSelectDirectories (I.E.an output path for multiple files), the ‘save’ button never becomes available because currentFileIsValid() disallows directory selections for saveMode.

bool FileBrowserComponent::currentFileIsValid() const
{
    if (isSaveMode())
    {
        if (getSelectedFile (0).exists())
        {
            if (canSelectDirectories && getSelectedFile (0).isDirectory())
                return true;
            else if (canSelectFiles) return true;
        }
        return false;
    }
    else
        return getSelectedFile (0).exists();
}

Similarly ‘save’ should be ‘choose’ under this circumstance, so:

String FileBrowserComponent::getActionVerb() const
{
    return isSaveMode() ? canSelectDirectories ? TRANS("Choose") : TRANS("Save") : TRANS("Open");
}

#2

Nice one, thanks!


#3

FYI… your suggestion contained some mistakes (canSelectDirectories is an enum, not a member! and when you’re saving, you shouldn’t return false if the file doesn’t exist). I’ve done what I think you were trying to do, but let me know if it sorts out the problem you were having.


#4

Wow, that was a pretty impressive case of ‘if it compiles ship it’. Sorry Jules! I was doing three (actually literally) things at once in an effort close up stuff ahead of the holiday, and clearly wasn’t paying attention. :oops: