示例#1
0
        protected override void PerformAction(VisualElement destination, DestinationPane pane, Vector2 localMousePosition, int index = -1)
        {
            if (pane == DestinationPane.Viewport && !IsPickedElementValid(m_TargetElementToReparent))
            {
                return;
            }

            base.PerformAction(destination, pane, localMousePosition, index);

            m_TargetElementToReparent.RemoveFromClassList(s_DragPreviewElementClassName);

            // Remove temporary min-size element.
            destination.RemoveMinSizeSpecialElement();

            var newParent = destination;

            // We already have the correct index from the preview element that is
            // already inserted in the hierarchy. The index we get from the arguments
            // is actually incorrect (off by one) because it will count the
            // preview element.
            index = m_DragPreviewLastParent.IndexOf(m_TargetElementToReparent);

            bool undo = true;

            foreach (var elementToReparent in m_ElementsToReparent)
            {
                var element = elementToReparent.element;

                if (newParent == element || newParent.HasAncestor(element))
                {
                    continue;
                }

                BuilderAssetUtilities.ReparentElementInAsset(
                    paneWindow.document, element, newParent, index, undo);

                undo = false;
            }

            BuilderAssetUtilities.SortElementsByTheirVisualElementInAsset(newParent);

            selection.NotifyOfHierarchyChange(null);
            selection.NotifyOfStylingChange(null);
            selection.ForceReselection(null);
        }