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!
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?
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();
}
}