When you need undoable actions, being able to simply provide a ValueTree
with an UndoManager
makes it incredibly simple. However, when you don’t need undoable actions it makes the code look a mess to have to pass nullptr
in every method of a ValueTree
.
Could the arguments simply all be defaulted to nullptr
?
In addition, could we have a ValueTree
use a “global” UndoManager
since in 99% of cases you’d only use the one undo manager so it’s unnecessary to constantly pass it into every call.
So instead of explicitly passing an UndoManager
to every method when I want it to be undoable, I could just call tree.setUndoManager(&myUndoManager);
and all the methods will use that one, unless specified?
juce::ValueTree tree{ "Tree" };
tree.setProperty("value", 12); // Can't be undone
juce::UndoManager undoManager;
tree.setUndoManager(&undoManager);
tree.setProperty("value", 14); // Can be undone by undoManager
juce::UndoManager anotherUndoer;
tree.setProperty("value", 37, &anotherUndoer); // Can only be undone by anotherUndoer