void PerformActionForSelector(VisualElement destination, DestinationPane pane, int index = -1) { var newStyleSheetElement = destination; bool undo = true; foreach (var elementToReparent in m_ElementsToReparent) { var selectorElementToReparent = elementToReparent.element; var oldStyleSheetElement = elementToReparent.oldParent; if (newStyleSheetElement == oldStyleSheetElement) { continue; } BuilderSharedStyles.MoveSelectorBetweenStyleSheets( oldStyleSheetElement, newStyleSheetElement, selectorElementToReparent, undo); undo = false; } BuilderSharedStyles.MatchSelectorElementOrderInAsset(newStyleSheetElement, undo); selection.NotifyOfHierarchyChange(); selection.NotifyOfStylingChange(null); selection.ForceReselection(); }
protected override void PerformAction(VisualElement destination, DestinationPane pane, Vector2 localMousePosition, int index = -1) { // We should have an item reference here if the OnDragStart() worked. var item = m_LibraryItem; var itemVTA = item.sourceAsset; if (!paneWindow.document.WillCauseCircularDependency(itemVTA)) { BuilderDialogsUtility.DisplayDialog(BuilderConstants.InvalidWouldCauseCircularDependencyMessage, BuilderConstants.InvalidWouldCauseCircularDependencyMessageDescription, null); return; } destination.RemoveMinSizeSpecialElement(); // Determine if it applies and use Absolute Island insertion. if (BuilderProjectSettings.enableAbsolutePositionPlacement && pane == DestinationPane.Viewport && m_DragPreviewLastParent == documentRootElement && index < 0) { m_DragPreviewLastParent = BuilderPlacementUtilities.CreateAbsoluteIsland(paneWindow, documentRootElement, localMousePosition); } // Add VisualElement to Canvas. m_DragPreviewElement.RemoveFromClassList(s_DragPreviewElementClassName); if (index < 0) { m_DragPreviewLastParent.Add(m_DragPreviewElement); } else { m_DragPreviewLastParent.Insert(index, m_DragPreviewElement); } // Create equivalent VisualElementAsset. if (item.makeElementAssetCallback == null) { BuilderAssetUtilities.AddElementToAsset( paneWindow.document, m_DragPreviewElement, index); } else { BuilderAssetUtilities.AddElementToAsset( paneWindow.document, m_DragPreviewElement, item.makeElementAssetCallback, index); } selection.NotifyOfHierarchyChange(null); selection.NotifyOfStylingChange(null); selection.Select(null, m_DragPreviewElement); // Commit to the preview element as the final element. // This will stop the ResetDragPreviewElement() from calling // RemoveFromHierarchy() on it. m_DragPreviewElement = null; // If we dragged into the Viewport, focus the Viewport. if (pane == DestinationPane.Viewport) { viewport.pane.Focus(); } }
protected override void PerformAction(VisualElement destination, DestinationPane pane, int index = -1) { if (m_TargetElementToReparent.IsSelector()) { PerformActionForSelector(destination, pane, index); } else if (m_TargetElementToReparent.IsStyleSheet()) { PerformActionForStyleSheet(destination, pane, index); } }
void PerformActionForStyleSheet(VisualElement destination, DestinationPane pane, int index = -1) { if (destination == null) { destination = BuilderSharedStyles.GetSelectorContainerElement(selection.documentRootElement); } BuilderAssetUtilities.ReorderStyleSheetsInAsset(paneWindow.document, destination); selection.NotifyOfHierarchyChange(); selection.NotifyOfStylingChange(null); selection.ForceReselection(); }
protected override void PerformAction(VisualElement destination, DestinationPane pane, int index = -1) { m_DragPreviewElement.RemoveFromClassList(s_DragPreviewElementClassName); destination.RemoveMinSizeSpecialElement(); // 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_DragPreviewElement); // We should have an item reference here if the OnDragStart() worked. var item = m_LibraryItem; var itemVTA = item.SourceAsset; if (!paneWindow.document.WillCauseCircularDependency(itemVTA)) { BuilderDialogsUtility.DisplayDialog(BuilderConstants.InvalidWouldCauseCircularDependencyMessage, BuilderConstants.InvalidWouldCauseCircularDependencyMessageDescription, null); return; } if (item.MakeElementAssetCallback == null) { BuilderAssetUtilities.AddElementToAsset( paneWindow.document, m_DragPreviewElement, index); } else { BuilderAssetUtilities.AddElementToAsset( paneWindow.document, m_DragPreviewElement, item.MakeElementAssetCallback, index); } selection.NotifyOfHierarchyChange(null); selection.NotifyOfStylingChange(null); selection.Select(null, m_DragPreviewElement); // Commit to the preview element as the final element. // This will stop the ResetDragPreviewElement() from calling // RemoveFromHierarchy() on it. m_DragPreviewElement = null; // If we dragged into the Viewport, focus the Viewport. if (pane == DestinationPane.Viewport) { Viewport.pane.Focus(); } }
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); }
protected override void PerformAction(VisualElement destination, DestinationPane pane, int index = -1) { if (BuilderSharedStyles.IsDocumentElement(destination)) { return; } var className = m_ClassNameBeingDragged.TrimStart('.'); destination.AddToClassList(className); // Update VisualTreeAsset. BuilderAssetUtilities.AddStyleClassToElementInAsset( paneWindow.document, destination, className); selection.NotifyOfHierarchyChange(null); selection.NotifyOfStylingChange(null); }
protected override void PerformAction(VisualElement destination, DestinationPane pane, int index = -1) { m_TargetElementToReparent.RemoveFromClassList(s_DragPreviewElementClassName); // Remove temporary min-size element. destination.RemoveMinSizeSpecialElement(); var elementToReparent = m_TargetElementToReparent; 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); BuilderAssetUtilities.ReparentElementInAsset( paneWindow.document, elementToReparent, newParent, index); selection.NotifyOfHierarchyChange(null); }
protected virtual void PerformAction(VisualElement destination, DestinationPane pane, int index = -1) { }
protected virtual void PerformAction(VisualElement destination, DestinationPane pane, Vector2 localMousePosition, int index = -1) { }
protected override void PerformAction(VisualElement destination, DestinationPane pane, Vector2 localMousePosition, int index = -1) { Reparent(destination, index); }