| 7913 | } |
| 7914 | |
| 7915 | void ScriptingApi::Content::Helpers::duplicateSelection(Content* c, ReferenceCountedArray<ScriptComponent> selection, int deltaX, int deltaY, UndoManager* undoManager) |
| 7916 | { |
| 7917 | Array<Identifier> newIds; |
| 7918 | newIds.ensureStorageAllocated(selection.size()); |
| 7919 | |
| 7920 | Array<var> duplicationValues; |
| 7921 | duplicationValues.ensureStorageAllocated(selection.size()); |
| 7922 | |
| 7923 | for (auto b : selection) |
| 7924 | duplicationValues.add(b->getValue()); |
| 7925 | |
| 7926 | static const Identifier x("x"); |
| 7927 | static const Identifier y("y"); |
| 7928 | |
| 7929 | ValueTreeUpdateWatcher::ScopedDelayer sd(c->getUpdateWatcher()); |
| 7930 | |
| 7931 | for (auto sc : selection) |
| 7932 | { |
| 7933 | int newX = sc->getPosition().getX() + deltaX; |
| 7934 | int newY = sc->getPosition().getY() + deltaY; |
| 7935 | |
| 7936 | |
| 7937 | |
| 7938 | auto cTree = c->getValueTreeForComponent(sc->name); |
| 7939 | |
| 7940 | ValueTree sibling = cTree.createCopy(); |
| 7941 | |
| 7942 | sibling.setProperty(x, newX, undoManager); |
| 7943 | sibling.setProperty(y, newY, undoManager); |
| 7944 | |
| 7945 | |
| 7946 | |
| 7947 | cTree.getParent().addChild(sibling, -1, undoManager); |
| 7948 | |
| 7949 | auto tmp = &newIds; |
| 7950 | |
| 7951 | auto setUniqueId = [c, undoManager, tmp](ValueTree& v) |
| 7952 | { |
| 7953 | auto newId = getUniqueIdentifier(c, v.getProperty("id")); |
| 7954 | |
| 7955 | tmp->add(newId); |
| 7956 | |
| 7957 | v.setProperty("id", newId.toString(), undoManager); |
| 7958 | return true; |
| 7959 | }; |
| 7960 | |
| 7961 | callRecursive(sibling, setUniqueId); |
| 7962 | |
| 7963 | auto updateParentComponentId = [c, undoManager](ValueTree& v) |
| 7964 | { |
| 7965 | auto pId = v.getParent().getProperty("id"); |
| 7966 | |
| 7967 | if (pId.isUndefined()) |
| 7968 | { |
| 7969 | jassertfalse; |
| 7970 | return false; |
| 7971 | } |
| 7972 |
nothing calls this directly
no test coverage detected