diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp index 9e2f77301c..99d8a6e35e 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.cpp +++ b/modules/juce_data_structures/values/juce_ValueTree.cpp @@ -219,6 +219,16 @@ public: } } + void copyPropertiesFrom (const SharedObject& source, UndoManager* const undoManager) + { + for (int i = properties.size(); --i >= 0;) + if (! source.properties.contains (properties.getName (i))) + removeProperty (properties.getName (i), undoManager); + + for (int i = 0; i < source.properties.size(); ++i) + setProperty (source.properties.getName(i), source.properties.getValueAt(i), undoManager); + } + ValueTree getChildWithName (const Identifier& typeToMatch) const { for (int i = 0; i < children.size(); ++i) @@ -783,6 +793,14 @@ Identifier ValueTree::getPropertyName (const int index) const : object->properties.getName (index); } +void ValueTree::copyPropertiesFrom (const ValueTree& source, UndoManager* const undoManager) +{ + if (source.object == nullptr) + removeAllProperties (undoManager); + else if (object != nullptr) + object->copyPropertiesFrom (*(source.object), undoManager); +} + //============================================================================== class ValueTreePropertyValueSource : public Value::ValueSource, private ValueTree::Listener diff --git a/modules/juce_data_structures/values/juce_ValueTree.h b/modules/juce_data_structures/values/juce_ValueTree.h index 1dbb112759..25c3636b58 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.h +++ b/modules/juce_data_structures/values/juce_ValueTree.h @@ -204,6 +204,12 @@ public: */ Value getPropertyAsValue (const Identifier& name, UndoManager* undoManager); + /** Overwrites all the properties in this tree with the properties of the source tree. + Any properties that already exist will be updated; and new ones will be added, and + any that are not present in the source tree will be removed. + */ + void copyPropertiesFrom (const ValueTree& source, UndoManager* undoManager); + //============================================================================== /** Returns the number of child nodes belonging to this one. @see getChild