Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow daisy-chaining when adding children to ValueTrees #1332

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions modules/juce_data_structures/values/juce_ValueTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class ValueTree::SharedObject final : public ReferenceCountedObject
return children.indexOf (child.object);
}

void addChild (SharedObject* child, int index, UndoManager* undoManager)
ValueTree& addChild (SharedObject* child, int index, UndoManager* undoManager)
{
if (child != nullptr && child->parent != this)
{
Expand Down Expand Up @@ -283,9 +283,11 @@ class ValueTree::SharedObject final : public ReferenceCountedObject
jassertfalse;
}
}

return *this;
}

void removeChild (int childIndex, UndoManager* undoManager)
ValueTree& removeChild (int childIndex, UndoManager* undoManager)
{
if (auto child = Ptr (children.getObjectPointer (childIndex)))
{
Expand All @@ -301,6 +303,8 @@ class ValueTree::SharedObject final : public ReferenceCountedObject
undoManager->perform (new AddOrRemoveChildAction (*this, childIndex, {}));
}
}

return *this;
}

void removeAllChildren (UndoManager* undoManager)
Expand Down
6 changes: 4 additions & 2 deletions modules/juce_data_structures/values/juce_ValueTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,16 @@ class JUCE_API ValueTree final
If the undoManager parameter is not nullptr, its UndoManager::perform() method will be used,
so that this change can be undone. Be very careful not to mix undoable and non-undoable changes!
@see appendChild, removeChild
@returns a reference to the value tree, so that you can daisy-chain calls to this method.
*/
void addChild (const ValueTree& child, int index, UndoManager* undoManager);
ValueTree& addChild (const ValueTree& child, int index, UndoManager* undoManager);

/** Appends a new child sub-tree to this tree.
This is equivalent to calling addChild() with an index of -1. See addChild() for more details.
@see addChild, removeChild
@returns a reference to the value tree, so that you can daisy-chain calls to this method.
*/
void appendChild (const ValueTree& child, UndoManager* undoManager);
ValueTree& appendChild (const ValueTree& child, UndoManager* undoManager);

/** Removes the specified child from this tree's child-list.
If the undoManager parameter is not nullptr, its UndoManager::perform() method will be used,
Expand Down