No, it's not, it's a typo in the forum, but thanks anyway for the suggestion.
In fact I checked setSelectedFile() in the debugger, and it will recursively find the right node even when the path is very long. And set it to selected. But it won't open the tree. Maybe it's not supposed to do that, but then what's the purpose of this function?
It does open the tree if it can do, but bear in mind that opening these folders isn't trivial - it involves recursively scanning potentially huge folders for child files, so there are timeouts and background threads involved, etc. There's another whole thread about this somewhere. If it doesn't work, try debugging into the method and see what's going on.
Well, after a few monts the outcome of that thread seemed to be... inconclusive. I'm obvisouly in deep sh... uncharted code territory. I don't feel I have the mental strength to take up that thread rigth now. Instead I've decided to enter the Hack of the month competition with the following entry:
class SelectDeeplyNestedFile : public Timer
{
public:
SelectDeeplyNestedFile(FileTreeComponent *fileTreeComp_, String fileName) :
fileTreeComp(fileTreeComp_)
{
StringArray check = StringArray::fromTokens(fileName, File::separatorString, String::empty);
countDown = check.size();
file = File(fileName),
startTimer(100);
}
private:
int countDown;
File file;
FileTreeComponent *fileTreeComp;
void timerCallback() override
{
fileTreeComp->setSelectedFile(file);
TreeViewItem *tvi = fileTreeComp->getSelectedItem(0);
if (tvi)
tvi->setOpen(true);
if (--countDown <= 0)
{
if (tvi)
fileTreeComp->scrollToKeepItemVisible (tvi);
delete this;
}
}
};
String lastSelectedFile = getStringSetting("lastSelectedFile");
if (lastSelectedFile.isNotEmpty())
new SelectDeeplyNestedFile(fileTreeComp, lastSelectedFile);
Thanks for looking at it. I came to the same conclusion. It still needs a background thread that waits for it.
It would be great if there would be a way to wait async without blocking the UI thread (the function that fills the tree would return a await handle / task). I think that would be possible in C++ in the meantime.
It would be great way to handle problems like this.