MCPcopy Create free account
hub / github.com/christophhart/HISE / duplicateSelection

Method duplicateSelection

hi_scripting/scripting/api/ScriptingApiContent.cpp:7915–8008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7913}
7914
7915void 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

Callers

nothing calls this directly

Calls 15

getUpdateWatcherMethod · 0.80
clearSelectionMethod · 0.80
callRecursiveFunction · 0.50
sizeMethod · 0.45
addMethod · 0.45
getValueMethod · 0.45
getXMethod · 0.45
getPositionMethod · 0.45
getYMethod · 0.45
createCopyMethod · 0.45

Tested by

no test coverage detected