Exemplo 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);
        }
Exemplo n.º 2
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();
                m_Selection.ClearSelection(null);
            }

            // Select all pasted elements.
            foreach (var templateAsset in pasteVta.templateAssets)
            {
                if (pasteVta.IsRootElement(templateAsset))
                {
                    templateAsset.Select();
                }
            }
            foreach (var vea in pasteVta.visualElementAssets)
            {
                if (pasteVta.IsRootElement(vea))
                {
                    vea.Select();
                }
            }

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

            ScriptableObject.DestroyImmediate(pasteVta);
        }
Exemplo n.º 3
0
        void PasteUXML(string copyBuffer)
        {
            var importer = new BuilderVisualTreeAssetImporter(); // Cannot be cached because the StyleBuilder never gets reset.

            importer.ImportXmlFromString(copyBuffer, out var pasteVta);

            /* If the current parent element is linked to a VisualTreeAsset, it could mean
             * that our parent is the TemplateContainer belonging to our parent document and the
             * current open document is a sub-document opened in-place. In such a case, we don't
             * want to use our parent's VisualElementAsset, as that belongs to our parent document.
             * So instead, we just use no parent, indicating that we are adding this new element
             * to the root of our document. */
            VisualElementAsset parent = null;

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

                if (selectionParent?.GetVisualTreeAsset() == m_PaneWindow.document.visualTreeAsset)
                {
                    parent = null;
                }

                m_Selection.ClearSelection(null);
            }

            // Select all pasted elements.
            foreach (var templateAsset in pasteVta.templateAssets)
            {
                if (pasteVta.IsRootElement(templateAsset))
                {
                    templateAsset.Select();
                }
            }
            foreach (var vea in pasteVta.visualElementAssets)
            {
                if (pasteVta.IsRootElement(vea))
                {
                    vea.Select();
                }
            }

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

            ScriptableObject.DestroyImmediate(pasteVta);
        }
        void PasteUXML(string copyBuffer)
        {
            VisualTreeAsset pasteVta = null;
            var             importer = new BuilderVisualTreeAssetImporter(); // Cannot be cached because the StyleBuilder never gets reset.

            importer.ImportXmlFromString(copyBuffer, out 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();

            ScriptableObject.DestroyImmediate(pasteVta);
        }