Browse Source

Fix for FileTreeComponent::setSelectedFile

tags/2021-05-28
jules 13 years ago
parent
commit
655468a380
1 changed files with 27 additions and 15 deletions
  1. +27
    -15
      modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp

+ 27
- 15
modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp View File

@@ -104,6 +104,27 @@ public:
newList->addChangeListener (this);
}
bool selectFile (const File& target)
{
if (file == target)
{
setSelected (true, true);
return true;
}
if (target.isAChildOf (file))
{
setOpen (true);
for (int i = 0; i < getNumSubItems(); ++i)
if (FileListTreeItem* f = dynamic_cast <FileListTreeItem*> (getSubItem (i)))
if (f->selectFile (target))
return true;
}
return false;
}
void changeListenerCallback (ChangeBroadcaster*)
{
clearSubItems();
@@ -231,10 +252,10 @@ void FileTreeComponent::refresh()
//==============================================================================
File FileTreeComponent::getSelectedFile (const int index) const
{
const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
if (const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index)))
return item->file;
return item != nullptr ? item->file
: File::nonexistent;
return File::nonexistent;
}
void FileTreeComponent::deselectAllFiles()
@@ -254,16 +275,7 @@ void FileTreeComponent::setDragAndDropDescription (const String& description)
void FileTreeComponent::setSelectedFile (const File& target)
{
for (int i = getNumSelectedItems(); --i >= 0;)
{
FileListTreeItem* t = dynamic_cast <FileListTreeItem*> (getSelectedItem (i));
if (t != nullptr && t->file == target)
{
t->setSelected (true, true);
return;
}
}
clearSelectedItems();
if (FileListTreeItem* t = dynamic_cast <FileListTreeItem*> (getRootItem()))
if (! t->selectFile (target))
clearSelectedItems();
}

Loading…
Cancel
Save