I’m attempting to call TreeViewItem::getOpennessState on a FileTreeComponent object, however I’m hitting the assert in the method (“trying to save the openness for an element that has no name”).
As far as I can see, the FileListTreeItem class overrides the TreeViewItem::getUniqueName method to give it a unique name, and FileTreeComponent uses the FileListTreeItem class.
Therefore what am I likely doing wrong to result in this error?
Thanks.
I’m no closer to solving this, so thought I’d share some test code so that hopefully someone can spot what I’m missing.
Here is the code from a test FileTreeComponent project - the FileTreeComponent code is exactly the same as the ImagesDemo in the JUCE demo project:
Declarations:
//==============================================================================
// Your private member variables go here...
WildcardFileFilter imagesWildcardFilter { "*.jpeg;*.jpg;*.png;*.gif", "*", "Image File Filter"};
TimeSliceThread directoryThread { "Image File Scanner Thread" };
DirectoryContentsList imageList { &imagesWildcardFilter, directoryThread };
FileTreeComponent fileTree { imageList };
Constructor:
imageList.setDirectory (File::getSpecialLocation (File::userPicturesDirectory), true, true);
directoryThread.startThread (Thread::Priority::background);
fileTree.setTitle ("Files");
fileTree.addListener (this);
fileTree.setColour (TreeView::backgroundColourId, Colours::grey);
addAndMakeVisible (fileTree);
void MainComponent::buttonClicked (Button* button)
{
if (button == &testButton)
{
auto opennessState = fileTree.getOpennessState (true); //JUCE Assertion failure in juce_TreeView.cpp:2191
}
}
Here is the complete project:
FileTreeComponentTest.zip (6.9 KB)
Thanks.
FYI I’ve now figured out the solution / fix - the FileTreeComponent object needs to be defined after calling DirectoryContentsList::setDirectory, otherwise the root FileListTreeItem can’t get the directory from DirectoryContentsList which is used to set the unique name.
1 Like