ComboBox / PopupMenu for showing presets in a directory

Is there a component in JUCE that shows all of the files in a directory in a drop down list where sub-directories appear as sub-menus of the list? The ComboBox doesn’t seem to support sub-menus but only grouping under headers. The FileTreeComponent doesn’t have a drop down list like interface… At the moment I’m thinking that I need to create my own pop-up menu with sub-menus for the sub-directories, but I thought I might as well ask in the forums if there is another way to do this, because usually in JUCE, there is a component that does what I want; I just don’t know what it’s called…

Doesn’t the JUCE demo have something like that?

Oh, don’t do that! Imagine the horrible cascade of menus you’d get for a big folder structure! Not to mention that you’d have to iterate all the folders recursively before you create the menu, so could block for an unlimited amount of time before your menu appears. Seriously: re-think your design!

I guess the JUCE demo doesn’t do that then :stuck_out_tongue:

Hi,
Is there a simple way to do like a progressive scan?
I mean create the non-recursive popup menu and then scan a subdirectory only if the user hovers it.
Thanks

It would be great to have a popup menu that could display a recursive file structure and is able to have more than one subMenu. Its not that bad as it looks at a first sight. People like to save their presets in a file system and not in memory. This way they can arrange the presets in sub folders and its transparent. Its really fast also with 1500 presets. No noticeable lag. A PopupMenu is a fast way to select presets with a few clicks.

edit: ok, the drawing of the PopUp menu begins to lag if you have 1500 items… :slight_smile:

JUCE doesn’t have that but you could easily write it yourself.

I think this is definitely a valid use-case, for presets as you described. You’ll probably want to put some sort of limit on the total number of items though, so the menu does not become unmanageable.

JUCE doesn’t have that but you could easily write it yourself.

I think this is definitely a valid use-case, for presets as you described. You’ll probably want to put some sort of limit on the total number of items though, so the menu does not become unmanageable.[/quote]

Thanks for the feedback. I will try it then…

EDIT: it looks as you already can create a sub menu of a sub menu, but you have to add the elements in the right order. The code will look something like this:

[code] String getFilePath(int menuNumber)
{
return menuMap[menuNumber];
}

void addFilesToMenu(PopupMenu *menu, String currentFolder)
{
    currentFolder = File::addTrailingSeparator(currentFolder);
    File presetsDirectory = File(currentFolder);

    Array<File> directories;
    presetsDirectory.findChildFiles(directories, File::findDirectories, false);

    for (int i = 0; i < directories.size(); i++)
    {
        File dir = directories.getReference(i);
        PopupMenu popupMenu;
        String fileName = dir.getFileName();

        Array<File> files;
        dir.findChildFiles(files, File::findFiles, false, "*.pjunoxl");
        for (int i = 0; i < files.size(); i++)
        {
            File file = files.getReference(i);
            String filename = file.getFileNameWithoutExtension();
            int menuNumber = PRESETS_OFFSET + presetNumber++;
            popupMenu.addItem(menuNumber, filename);
            this->menuMap[menuNumber] = file.getFullPathName();
        }

        this->addFilesToMenu(&popupMenu, dir.getFullPathName());
        menu->addSubMenu(fileName, popupMenu);
    }
}[/code]