FileBrowserComponent getSelectedFile() request


#1

Hi Jules, would it be possible to add a small method the FileBrowserComponent::getSelectedFile() or getHighlightedFile() method which returns the currently highlighted file regardless of the type of FileChooserMode?

const File FileBrowserComponent::getHighlightedFile() const throw()
{
    return fileListComponent->getSelectedFile();
}

The reason I need this is that I am building a sort of Mac column view browser with wildcard filtering (as it is for an audio application) and need to get at the selected row to display the next column. As I am looking for files I need to use loadFileMode which means folders aren’t returned by the getCurrentFile() method.

Hope this doesn’t mess with the Component’s design too much.

Dave.


#2

Sorry, this is possible using a FileBrowserListener and the fileClicked() method.


#3

Ok, sorry to re-open this but after getting the basic thing working I have now moved onto navigation with the keyboard and need a way of getting at the currently selected file without the the fileClicked() callback. So would it be possible to add the suggested getHighlightedFile() method?

It could be modified to only pass a desired file type based on parameter eg.

const File FileBrowserComponent::getHighlightedFile(bool onlyInterestedFiles) const throw()
{
    const File selected (fileListComponent->getSelectedFile());

    if (!onlyInterestedFiles)
         return fileListComponent->getSelectedFile();
    else
    {
        if ((mode == chooseDirectoryMode && selected.isDirectory())
             || selected.existsAsFile())
        {
             return fileListComponent->getSelectedFile();
        }
    }

    return File::nonexistent;
} 

#4

Ok, I’m happy to add a simple method that returns the file from the list.

I don’t really understand the bool option you’re suggesting though.


#5

Cheers Jules. The bool option was to only return a File based on the current FileChooserMode mode, eg. directories for chooseDirectoryMode but it makes more sense to do without it as you have. Cheers.


#6