1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

FileListComponent: Fix incorrect selection when calling setSelectedFile while the directory contents are still loading

This commit is contained in:
reuk 2022-09-22 15:36:04 +01:00
parent 4fc958bcda
commit 5d1c580b15
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
2 changed files with 11 additions and 9 deletions

View file

@ -31,12 +31,11 @@ Image juce_createIconForFile (const File& file);
//==============================================================================
FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
: ListBox ({}, nullptr),
: ListBox ({}, this),
DirectoryContentsDisplayComponent (listToShow),
lastDirectory (listToShow.getDirectory())
{
setTitle ("Files");
setModel (this);
directoryContentsList.addChangeListener (this);
}
@ -67,14 +66,17 @@ void FileListComponent::scrollToTop()
void FileListComponent::setSelectedFile (const File& f)
{
for (int i = directoryContentsList.getNumFiles(); --i >= 0;)
if (! directoryContentsList.isStillLoading())
{
if (directoryContentsList.getFile (i) == f)
for (int i = directoryContentsList.getNumFiles(); --i >= 0;)
{
fileWaitingToBeSelected = File();
if (directoryContentsList.getFile (i) == f)
{
fileWaitingToBeSelected = File();
selectRow (i);
return;
selectRow (i);
return;
}
}
}

View file

@ -40,9 +40,9 @@ namespace juce
@tags{GUI}
*/
class JUCE_API FileListComponent : public ListBox,
class JUCE_API FileListComponent : private ListBoxModel,
public ListBox,
public DirectoryContentsDisplayComponent,
private ListBoxModel,
private ChangeListener
{
public: