I am working with the juce demo code to make a mp3 player. I want to save the file selected and open to that place when started next time it is opened. The code uses a FileTreeComponent, to display directoryList. So after the FileTreeComponent is opened I try to use setSelectedFile to do this but does not work. I must be misunderstanding. Here is a clipe of my code:
directoryList.setDirectory (g_Properties->getValue("PlayDirectory", ""), true, true);// set the directory last opened
thread.startThread (3);
fileTreeComp.setSelectedFile(g_Properties->getValue("LastPlayed", ""));
The play directory is "E:\\" and LastPlayed is somethinglike "E:\\album\\song.mp3"". These were saved like this:
g_Properties->setValue("PlayDirectory", directoryList.getDirectory().getFullPathName());
g_Properties->setValue("LastPlayed", fileTreeComp.getSelectedFile().getFullPathName());
The setDirectory works correctly, the setSelectedFile does nothing. Stepping through I get here:
void FileTreeComponent::setSelectedFile (const File& target)
{
if (FileListTreeItem* t = dynamic_cast <FileListTreeItem*> (getRootItem()))
if (! t->selectFile (target))
clearSelectedItems();
}
selectFile does this:
if (file == target)
{
setSelected (true, true);
return true;
}
if (target.isAChildOf (file))
{ ...
}
return false;
|
Of course my file does not match "" so it falls to the second if. The next if calls:
bool File::isAChildOf (const File& potentialParent) const
{
if (potentialParent.fullPath.isEmpty())
return false;
This returns false.
I assume that the getRootItem is the problem. Do I need to setup the rootItem somehow or am I going about this in the wrong way?