A couple JUCE modules that are useful for representing and interacting with files and directories through juce::ValueTree.
It allows displaying a directory's contents in a tree view and allowing the user to make selections and open/close directories with their mouse or arrow keys.
All of this library's functionality is based on juce::ValueTree properties.
This means you can receive listener callbacks whenever a new item is selected or a directory is opened/closed.
This code was originally written for the preset browser in PFT. I added some minor improvements and expansions mostly aimed at making the library more flexible.
DirectoryModel: A class that models files and directories usingjuce::ValueTree.DirectoryModel::IUpdateHandler: Choose which data to populate the tree with.DirectoryModelSync: Update aDirectoryModelwhen files on the disk change.SelectionModel: Custom selection logic for the tree.TreeView: Simple tree view class that optionally integrates withDirectoryModel.JuceTreeView: Some classes that can be used to display aDirectoryModelin an existingjuce::TreeView.
The main purpose of this library is to maintain a juce::ValueTree that models a directory on the disk and updates it as disk contents change.
Generally speaking, it is structured with building blocks so that pieces of functionality can be added and removed as needed.
Create a DirectoryModel to model the directory and a DirectoryModelSync to keep it up to date.
Add IUpdateHandlers to the DirectoryModel to populate juce::ValueTrees with desired properties.
It's probably best to create a model class that encapsulates all of this:
class MyDirectoryModel
{
public:
MyDirectoryModel()
{
model.addUpdateHandler(nameUpdateHandler);
model.initialize('/root/directory/');
sync.syncModel(model);
juce::ValueTree rootTree = model.getValueTree();
}
private:
vdm::DirectoryModel model;
vdm::DirectoryModelSync sync;
vdm::NameUpdateHandler nameUpdateHandler; // writes the file name to the ValueTree
};The vdm_ui module has a TreeView base class.
The motivation for creating it is that I don't like juce::TreeView.
I think it does too much.
The vdm::TreeView only handles creating and laying out child components.
class MyTreeView : public vdm::TreeView
{
private:
std::unique_ptr<juce::Component> createTreeViewItem(juce::ValueTree tree) override;
};
vdm::DirectoryModel model;
model.initialize('/root/directory/');
juce::ValueTree rootTree = model.getValueTree();
MyTreeView treeView;
treeView.setValueTree(rootTree);