1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

Allow daisy-chaining when adding children to ValueTree

This commit is contained in:
James J 2024-01-23 13:39:20 +00:00
parent 6c32c4df87
commit f868969e79
2 changed files with 10 additions and 4 deletions

View file

@ -244,7 +244,7 @@ public:
return children.indexOf (child.object); 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) if (child != nullptr && child->parent != this)
{ {
@ -283,9 +283,11 @@ public:
jassertfalse; jassertfalse;
} }
} }
return *this;
} }
void removeChild (int childIndex, UndoManager* undoManager) ValueTree& removeChild (int childIndex, UndoManager* undoManager)
{ {
if (auto child = Ptr (children.getObjectPointer (childIndex))) if (auto child = Ptr (children.getObjectPointer (childIndex)))
{ {
@ -301,6 +303,8 @@ public:
undoManager->perform (new AddOrRemoveChildAction (*this, childIndex, {})); undoManager->perform (new AddOrRemoveChildAction (*this, childIndex, {}));
} }
} }
return *this;
} }
void removeAllChildren (UndoManager* undoManager) void removeAllChildren (UndoManager* undoManager)

View file

@ -323,14 +323,16 @@ public:
If the undoManager parameter is not nullptr, its UndoManager::perform() method will be used, 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! so that this change can be undone. Be very careful not to mix undoable and non-undoable changes!
@see appendChild, removeChild @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. /** 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. This is equivalent to calling addChild() with an index of -1. See addChild() for more details.
@see addChild, removeChild @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. /** Removes the specified child from this tree's child-list.
If the undoManager parameter is not nullptr, its UndoManager::perform() method will be used, If the undoManager parameter is not nullptr, its UndoManager::perform() method will be used,