Ejemplo n.º 1
0
        void PasteUXML(string copyBuffer)
        {
            var importer = new BuilderVisualTreeAssetImporter(); // Cannot be cached because the StyleBuilder never gets reset.

            importer.ImportXmlFromString(copyBuffer, out var pasteVta);

            VisualElementAsset parent = null;

            if (!m_Selection.isEmpty)
            {
                parent = m_Selection.selection.First().parent?.GetVisualElementAsset();
            }

            BuilderAssetUtilities.TransferAssetToAsset(m_PaneWindow.document, parent, pasteVta);
            m_PaneWindow.document.AddStyleSheetToAllRootElements();

            var selectionParentId = parent?.id ?? m_PaneWindow.document.visualTreeAsset.GetRootUXMLElementId();
            VisualElementAsset newSelectedItem = pasteVta.templateAssets.FirstOrDefault(tpl => tpl.parentId == selectionParentId);

            if (newSelectedItem == null)
            {
                newSelectedItem = pasteVta.visualElementAssets.FirstOrDefault(asset => asset.parentId == selectionParentId);
            }

            m_Selection.ClearSelection(null);
            newSelectedItem.Select();

            ScriptableObject.DestroyImmediate(pasteVta);
        }
Ejemplo n.º 2
0
        protected virtual void ElementSelectionChanged(List <VisualElement> elements)
        {
            if (m_SelectionMadeExternally)
            {
                return;
            }

            if (elements == null)
            {
                m_Selection.ClearSelection(this);
                return;
            }

            m_Selection.ClearSelection(this);
            foreach (var element in elements)
            {
                if (element.ClassListContains(BuilderConstants.ExplorerItemUnselectableClassName))
                {
                    m_SelectionMadeExternally = true;
                    m_ElementHierarchyView.ClearSelection();
                    m_SelectionMadeExternally = false;
                    m_Selection.ClearSelection(this);
                    return;
                }

                m_Selection.AddToSelection(this, element);
            }
        }
Ejemplo n.º 3
0
        public void DeleteSelection()
        {
            if (m_Selection.isEmpty)
            {
                return;
            }

            // Must save a copy of the selection here and then clear selection before
            // we delete the elements. Otherwise the selection clearing will fail
            // to remove the special selection objects because it won't be able
            // to query parent information of selected elements (they have already
            // been removed from the hierarchy).
            var selectionCopy = m_Selection.selection.ToList();

            m_Selection.ClearSelection(null, true);

            bool somethingWasDeleted = false;

            foreach (var element in selectionCopy)
            {
                somethingWasDeleted |= DeleteElement(element);
            }

            if (somethingWasDeleted)
            {
                JustNotify();
            }
        }
        public bool NewDocument(bool checkForUnsavedChanges = true, bool unloadAllSubdocuments = true)
        {
            if (checkForUnsavedChanges && !document.CheckForUnsavedChanges())
            {
                return(false);
            }

            if (unloadAllSubdocuments)
            {
                document.GoToRootDocument(m_Viewport.documentRootElement, m_PaneWindow, true);
            }

            m_Selection.ClearSelection(null);

            document.NewDocument(m_Viewport.documentRootElement);

            m_Viewport.ResetView();
            m_Inspector?.canvasInspector.Refresh();

            m_Selection.NotifyOfHierarchyChange(document);
            m_Selection.NotifyOfStylingChange(document);

            m_Library?.ResetCurrentlyLoadedUxmlStyles();

            SetCanvasTitle();

            return(true);
        }
Ejemplo n.º 5
0
        void OnPick(MouseDownEvent evt)
        {
            var pickedElement = PickElement(evt.mousePosition);

            if (pickedElement != null)
            {
                SetInnerSelection(pickedElement);
                m_Selection.Select(this, pickedElement);
            }
            else
            {
                ClearInnerSelection();
                m_Selection.ClearSelection(this);
            }

            evt.StopPropagation();
        }
Ejemplo n.º 6
0
        void OnPick(MouseDownEvent evt)
        {
            // Do not prevent zoom and pan
            if (evt.button == 2 || (evt.ctrlKey && evt.altKey || (evt.button == (int)MouseButton.RightMouse && evt.altKey)))
            {
                return;
            }

            var pickedElement = PickElement(evt.mousePosition);

            if (pickedElement != null)
            {
                m_Selection.Select(this, pickedElement);
                SetInnerSelection(pickedElement);

                if (evt.clickCount == 2)
                {
                    var posInViewport = m_PickOverlay.ChangeCoordinatesTo(this, evt.localMousePosition);
                    BuilderInPlaceTextEditingUtilities.OpenEditor(pickedElement, this.ChangeCoordinatesTo(pickedElement, posInViewport));
                }
            }
            else
            {
                ClearInnerSelection();
                m_Selection.ClearSelection(this);
            }

            if (evt.button == (int)MouseButton.RightMouse)
            {
                if (pickedElement != null && m_ContextMenuManipulator != null)
                {
                    pickedElement.SetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName, pickedElement);
                    m_ContextMenuManipulator.RegisterCallbacksOnTarget(pickedElement);
                    m_ContextMenuManipulator.DisplayContextMenu(evt, pickedElement);
                    evt.StopPropagation();
                }
            }
            else
            {
                evt.StopPropagation();
            }
        }
Ejemplo n.º 7
0
        void NewDocument()
        {
            if (!CheckForUnsavedChanges())
            {
                return;
            }

            m_Selection.ClearSelection(null);

            document.NewDocument(m_Viewport.documentElement);

            m_Viewport.canvas.SetSizeFromDocumentSettings();
            m_Inspector?.canvasInspector.Refresh();

            m_Selection.NotifyOfHierarchyChange(document);
            m_Selection.NotifyOfStylingChange(document);

            m_Library?.ResetCurrentlyLoadedUxmlStyles();

            SetViewportSubTitle();
        }
Ejemplo n.º 8
0
        void ElementSelected(VisualElement element)
        {
            if (m_SelectionMadeExternally)
            {
                return;
            }

            if (element == null)
            {
                m_Selection.ClearSelection(this);
                return;
            }
            else if (element.ClassListContains(BuilderConstants.ExplorerItemUnselectableClassName))
            {
                m_SelectionMadeExternally = true;
                m_ElementHierarchyView.ClearSelection();
                m_SelectionMadeExternally = false;
                m_Selection.ClearSelection(this);
                return;
            }

            m_Selection.Select(this, element);
        }
        void OnPick(MouseDownEvent evt)
        {
            // Do not prevent zoom and pan
            if (evt.button == 2 || (evt.ctrlKey && evt.altKey || (evt.button == (int)MouseButton.RightMouse && evt.altKey)))
            {
                return;
            }

            var pickedElement = PickElement(evt.mousePosition);

            if (pickedElement != null)
            {
                SetInnerSelection(pickedElement);
                m_Selection.Select(this, pickedElement);
            }
            else
            {
                ClearInnerSelection();
                m_Selection.ClearSelection(this);
            }

            if (evt.button == (int)MouseButton.RightMouse)
            {
                if (pickedElement != null && m_ContextMenuManipulator != null)
                {
                    pickedElement.SetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName, pickedElement);
                    m_ContextMenuManipulator.RegisterCallbacksOnTarget(pickedElement);
                    m_ContextMenuManipulator.DisplayContextMenu(evt, pickedElement);
                    evt.StopPropagation();
                }
            }
            else
            {
                evt.StopPropagation();
            }
        }
Ejemplo n.º 10
0
        void OnPick(MouseDownEvent evt)
        {
            // Do not prevent zoom and pan
            if (evt.button == 2 || (evt.ctrlKey && evt.altKey || (evt.button == (int)MouseButton.RightMouse && evt.altKey)))
            {
                return;
            }

            m_PickedElements.Clear();
            var pickedElement = PickElement(evt.mousePosition, m_PickedElements);

            if (pickedElement != null)
            {
                var timeSinceStartup  = EditorApplication.timeSinceStartup;
                var previousMouseRect = new Rect(
                    m_PreviousPickMousePosition.x - BuilderConstants.PickSelectionRepeatRectHalfSize,
                    m_PreviousPickMousePosition.y - BuilderConstants.PickSelectionRepeatRectHalfSize,
                    BuilderConstants.PickSelectionRepeatRectSize,
                    BuilderConstants.PickSelectionRepeatRectSize);
                if (timeSinceStartup - m_PreviousPickMouseTime > BuilderConstants.PickSelectionRepeatMinTimeDelay && previousMouseRect.Contains(evt.mousePosition))
                {
                    m_SameLocationPickCount++;
                    var offset = 0;

                    var index = m_PickedElements.IndexOf(pickedElement);
                    // For compound controls, we don't seem to have the actual field root element
                    // in the pickedElements list. So we get index == -1 here. We need to do
                    // some magic to select the proper parent element from the list then.
                    if (index < 0)
                    {
                        index  = m_PickedElements.IndexOf(pickedElement.parent);
                        offset = 1;
                    }

                    var maxIndex = m_PickedElements.Count - 1;
                    var newIndex = index + m_SameLocationPickCount - offset;
                    if (newIndex > maxIndex)
                    {
                        m_SameLocationPickCount = 0;
                    }
                    else
                    {
                        pickedElement = m_PickedElements[newIndex];
                    }
                }
                else
                {
                    m_SameLocationPickCount = 0;
                }
                m_PreviousPickMousePosition = evt.mousePosition;
                m_PreviousPickMouseTime     = EditorApplication.timeSinceStartup;

                m_Selection.Select(this, pickedElement);
                SetInnerSelection(pickedElement);

                if (evt.clickCount == 2)
                {
                    var posInViewport = m_PickOverlay.ChangeCoordinatesTo(this, evt.localMousePosition);
                    BuilderInPlaceTextEditingUtilities.OpenEditor(pickedElement, this.ChangeCoordinatesTo(pickedElement, posInViewport));
                }
            }
            else
            {
                ClearInnerSelection();
                m_Selection.ClearSelection(this);
            }

            if (evt.button == (int)MouseButton.RightMouse)
            {
                if (pickedElement != null && m_ContextMenuManipulator != null)
                {
                    pickedElement.SetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName, pickedElement);
                    m_ContextMenuManipulator.RegisterCallbacksOnTarget(pickedElement);
                    m_ContextMenuManipulator.DisplayContextMenu(evt, pickedElement);
                    evt.StopPropagation();
                }
            }
            else
            {
                evt.StopPropagation();
            }
        }
 public void ClearSelectionNotify()
 {
     m_Selection.ClearSelection(null);
     m_Selection.NotifyOfHierarchyChange(null);
     m_Selection.NotifyOfStylingChange(null);
 }