Programmatically open FileTreeComponent

You mean this?

http://www.juce.com/forum/topic/interesting-observations

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);
2 Likes