public override void OnStartDragging(GraphElement ge) { if (ge is TokenDeclaration tokenDeclaration) { VseGraphView gView = GetFirstOfType <VseGraphView>(); VisualElement tokenParent = tokenDeclaration.parent; int childIndex = tokenDeclaration.FindIndexInParent(); gView.RemoveElement(tokenDeclaration); tokenDeclaration.SetClasses(); gView.AddElement(tokenDeclaration); // By removing the tokenDeclaration from the graph view, we also removed it from the selection. // We need to add the tokenDeclaration back in order to properly drag. tokenDeclaration.Select(gView, true); tokenDeclaration.BringToFront(); TokenDeclaration placeHolderTokenDeclaration = tokenDeclaration.Clone(); placeHolderTokenDeclaration.AddToClassList("placeHolder"); tokenParent.Insert(childIndex, placeHolderTokenDeclaration); placeHolderTokenDeclaration.MarkDirtyRepaint(); gView.AddPlaceholderToken(tokenDeclaration); } else { var originalWidth = ge.resolvedStyle.width; var originalHeight = ge.resolvedStyle.height; base.OnStartDragging(ge); // Revert to same width and height after element became unstacked ge.style.width = originalWidth; ge.style.height = originalHeight; } }
public TokenDeclaration Clone() { var clone = new TokenDeclaration(m_Store, Declaration, m_GraphView) { viewDataKey = Guid.NewGuid().ToString() }; if (Declaration is LoopVariableDeclarationModel loopVariableDeclarationModel) { VseUtility.AddTokenIcon(clone, loopVariableDeclarationModel.TitleComponentIcon); } return(clone); }