FileBrowserComponent losing file selections


#1

I'm having a problem where my FileBrowserComponent periodically loses the current selection of files. I believe it may be related to this commit - when it refreshes the file list, the current selection is lost. Is there any way around this? I'd like my selections to persist!

https://github.com/julianstorer/JUCE/commit/6baf778e41d15fe3e23f32b7a8fe82e695f7477e 


#2

That seems to be a broken link...


#3

Oops, not sure how that happened:

https://github.com/julianstorer/JUCE/commit/6baf778e41d15fe3e23f32b7a8fe82e695f7477


#4

Just to clarify (and bump), if the user makes a selection, then switches to another program and back, the FileBrowserComponent refreshes itself and the selection is lost. Is there any way to keep the selection if nothing has changed, or is that too complex to acheive?


#5

Not sure - can't look into it right now but if you want to investigate, would be interested in hearing more.


#6

OK, I'll have a look and see if there's any simple way to accomplish this.


#7

Hmm, this is pretty tricky because of the time-sliced model of populating the list. For my own purposes (it's a way to browse filter presets) this works ok, because I never expect to have 1000s of files, but it obviously disables the continuous update of the list as it's populated. Also the selection gets offset if a file is deleted or added in between refreshes. I can live with those constraints, but it obviously wouldn't be suitable for the general case. To do it properly I think you'd need to cache the selections, then re-apply them when the refresh is finished. I may look into doing that tomorrow as a practice excercise in programming something robust enough for a library.

void FileListComponent::changeListenerCallback (ChangeBroadcaster* source)
{
    const auto list = dynamic_cast<DirectoryContentsList*>(source);
    
    if (list == nullptr || !list->isStillLoading())
        updateContent ();

    if (lastDirectory != fileList.getDirectory())
    {
        lastDirectory = fileList.getDirectory();
        deselectAllRows();
    }
}