public override void BuildElementContextualMenu(ContextualMenuPopulateEvent evt, VisualElement target) { base.BuildElementContextualMenu(evt, target); var documentElement = target.GetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName) as VisualElement; var vta = documentElement?.GetProperty(BuilderConstants.ElementLinkedInstancedVisualTreeAssetVEPropertyName) as VisualTreeAsset; if (vta != null) { evt.menu.AppendSeparator(); evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyOpenInBuilder, action => { paneWindow.LoadDocument(vta); }); evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyPaneOpenSubDocument, action => { BuilderHierarchyUtilities.OpenAsSubDocument(paneWindow, vta); }); } var activeDocumentsParentIndex = document.activeOpenUXMLFile.openSubDocumentParentIndex; if (documentElement == null && activeDocumentsParentIndex > -1) { evt.menu.AppendSeparator(); evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyReturnToParentDocument, action => { var parentDocument = document.openUXMLFiles[activeDocumentsParentIndex]; document.GoToSubdocument(documentElement, paneWindow, parentDocument); }); } }
public virtual void BuildElementContextualMenu(ContextualMenuPopulateEvent evt, VisualElement target) { var documentElement = target.GetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName) as VisualElement; var linkedOpenVTA = documentElement?.GetProperty(BuilderConstants.ElementLinkedVisualTreeAssetVEPropertyName) as VisualTreeAsset; var isValidTarget = documentElement != null && !linkedOpenVTA && (documentElement.IsPartOfActiveVisualTreeAsset(paneWindow.document) || documentElement.GetStyleComplexSelector() != null); var isValidCopyTarget = documentElement != null && !linkedOpenVTA && (documentElement.IsPartOfCurrentDocument() || documentElement.GetStyleComplexSelector() != null); evt.StopImmediatePropagation(); evt.menu.AppendAction( "Copy", a => { ReselectIfNecessary(documentElement); if (isValidCopyTarget) { m_PaneWindow.commandHandler.CopySelection(); } }, isValidCopyTarget ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled); evt.menu.AppendAction( "Paste", a => { m_PaneWindow.commandHandler.Paste(); }, string.IsNullOrEmpty(BuilderEditorUtility.systemCopyBuffer) ? DropdownMenuAction.Status.Disabled : DropdownMenuAction.Status.Normal); evt.menu.AppendSeparator(); evt.menu.AppendAction( "Rename", a => { m_Selection.Select(null, documentElement); var explorerItemElement = documentElement?.GetProperty(BuilderConstants.ElementLinkedExplorerItemVEPropertyName) as BuilderExplorerItem; if (explorerItemElement == null) { return; } explorerItemElement.ActivateRenameElementMode(); }, isValidTarget ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled); evt.menu.AppendAction( "Duplicate", a => { ReselectIfNecessary(documentElement); m_PaneWindow.commandHandler.DuplicateSelection(); }, isValidTarget ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled); evt.menu.AppendSeparator(); evt.menu.AppendAction( "Delete", a => { ReselectIfNecessary(documentElement); m_PaneWindow.commandHandler.DeleteSelection(); }, isValidTarget ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled); var linkedInstancedVTA = documentElement?.GetProperty(BuilderConstants.ElementLinkedInstancedVisualTreeAssetVEPropertyName) as VisualTreeAsset; var linkedVEA = documentElement?.GetProperty(BuilderConstants.ElementLinkedVisualElementAssetVEPropertyName) as TemplateAsset; var activeOpenUXML = document.activeOpenUXMLFile; var isLinkedOpenVTAActiveVTA = linkedOpenVTA == activeOpenUXML.visualTreeAsset; var isLinkedInstancedVTAActiveVTA = linkedInstancedVTA == activeOpenUXML.visualTreeAsset; var isLinkedVEADirectChild = activeOpenUXML.visualTreeAsset.templateAssets.Contains(linkedVEA); var showOpenInBuilder = linkedInstancedVTA != null; var showReturnToParentAction = isLinkedOpenVTAActiveVTA && activeOpenUXML.isChildSubDocument; var showOpenInIsolationAction = isLinkedVEADirectChild; var showOpenInPlaceAction = showOpenInIsolationAction; var showSiblingOpenActions = !isLinkedOpenVTAActiveVTA && isLinkedInstancedVTAActiveVTA; if (showOpenInBuilder || showReturnToParentAction || showOpenInIsolationAction || showOpenInPlaceAction || showSiblingOpenActions) { evt.menu.AppendSeparator(); } if (showOpenInBuilder) { evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyOpenInBuilder, action => { paneWindow.LoadDocument(linkedInstancedVTA); }); } if (showReturnToParentAction) { evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyReturnToParentDocument + BuilderConstants.SingleSpace + "(" + activeOpenUXML.openSubDocumentParent.visualTreeAsset.name + ")", action => document.GoToSubdocument(documentElement, paneWindow, activeOpenUXML.openSubDocumentParent)); } if (showOpenInIsolationAction) { evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyPaneOpenSubDocument, action => BuilderHierarchyUtilities.OpenAsSubDocument(paneWindow, linkedInstancedVTA)); } if (showOpenInPlaceAction) { evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyPaneOpenSubDocumentInPlace, action => BuilderHierarchyUtilities.OpenAsSubDocument(paneWindow, linkedInstancedVTA, linkedVEA)); } if (showSiblingOpenActions) { evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyPaneOpenSubDocument, action => { document.GoToSubdocument(documentElement, paneWindow, activeOpenUXML.openSubDocumentParent); BuilderHierarchyUtilities.OpenAsSubDocument(paneWindow, linkedInstancedVTA); }); evt.menu.AppendAction( BuilderConstants.ExplorerHierarchyPaneOpenSubDocumentInPlace, action => { document.GoToSubdocument(documentElement, paneWindow, activeOpenUXML.openSubDocumentParent); BuilderHierarchyUtilities.OpenAsSubDocument(paneWindow, linkedInstancedVTA, linkedVEA); }); } }