public override void CreateUI() { var root = rootVisualElement; var viewportWindow = document.primaryViewportWindow; if (viewportWindow == null) { return; } var selection = viewportWindow.selection; var viewport = viewportWindow.viewport; var classDragger = new BuilderClassDragger(this, root, selection, viewport, viewport.parentTracker); var hierarchyDragger = new BuilderHierarchyDragger(this, root, selection, viewport, viewport.parentTracker); var contextMenuManipulator = new BuilderExplorerContextMenu(this, selection); m_StyleSheetsPane = new BuilderStyleSheets(viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, null, null); selection.AddNotifier(m_StyleSheetsPane); root.Add(m_StyleSheetsPane); // Command Handler commandHandler.RegisterPane(m_StyleSheetsPane); }
public BuilderExplorer( BuilderViewport viewport, BuilderSelection selection, BuilderClassDragger classDragger, BuilderHierarchyDragger hierarchyDragger, BuilderExplorerContextMenu contextMenuManipulator, VisualElement documentElementRoot, HighlightOverlayPainter highlightOverlayPainter, string toolbarUxmlPath) { m_Viewport = viewport; m_DocumentElementRoot = documentElementRoot; m_DocumentElement = viewport.documentElement; AddToClassList(s_UssClassName); m_ClassDragger = classDragger; m_HierarchyDragger = hierarchyDragger; m_ContextMenuManipulator = contextMenuManipulator; m_SelectionMadeExternally = false; m_Selection = selection; // TODO: Transfer to own USS. var sheet = EditorGUIUtility.Load(k_DefaultStyleSheetPath) as StyleSheet; styleSheets.Add(sheet); StyleSheet colorSheet; if (EditorGUIUtility.isProSkin) { colorSheet = EditorGUIUtility.Load(k_DefaultDarkStyleSheetPath) as StyleSheet; } else { colorSheet = EditorGUIUtility.Load(k_DefaultLightStyleSheetPath) as StyleSheet; } styleSheets.Add(colorSheet); // Query the UI if (!string.IsNullOrEmpty(toolbarUxmlPath)) { var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(toolbarUxmlPath); template.CloneTree(this); } // Create the Hierarchy View. m_ElementHierarchyView = new ElementHierarchyView( m_DocumentElement, selection, classDragger, hierarchyDragger, contextMenuManipulator, ElementSelected, highlightOverlayPainter); m_ElementHierarchyView.style.flexGrow = 1; Add(m_ElementHierarchyView); // Make sure the Hierarchy View gets focus when the pane gets focused. primaryFocusable = m_ElementHierarchyView.Q <ListView>(); UpdateHierarchyAndSelection(); }
public BuilderHierarchy( BuilderViewport viewport, BuilderSelection selection, BuilderClassDragger classDragger, BuilderHierarchyDragger hierarchyDragger, BuilderExplorerContextMenu contextMenuManipulator, HighlightOverlayPainter highlightOverlayPainter) : base( viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, viewport.documentElement, highlightOverlayPainter, kToolbarPath) { viewDataKey = "builder-hierarchy"; m_HierarchyTypeClassVisibilityMenu = this.Q <ToolbarMenu>("hierarchy-visibility-toolbar-menu"); SetUpHierarchyVisibilityMenu(); }
public BuilderStyleSheets( BuilderViewport viewport, BuilderSelection selection, BuilderClassDragger classDragger, BuilderHierarchyDragger hierarchyDragger, BuilderExplorerContextMenu contextMenuManipulator, HighlightOverlayPainter highlightOverlayPainter, BuilderTooltipPreview tooltipPreview) : base( viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, viewport.styleSelectorElementContainer, highlightOverlayPainter, kToolbarPath) { m_TooltipPreview = tooltipPreview; if (m_TooltipPreview != null) { var helpTooltipTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(kHelpTooltipPath); var helpTooltipContainer = helpTooltipTemplate.CloneTree(); m_TooltipPreview.Add(helpTooltipContainer); // We are the only ones using it so just add the contents and be done. } viewDataKey = "builder-style-sheets"; AddToClassList(BuilderConstants.ExplorerStyleSheetsPaneClassName); var parent = this.Q("new-selector-item"); // Init text field. m_NewSelectorTextField = parent.Q <TextField>("new-selector-field"); m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input"); m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown); m_NewSelectorTextInputField.RegisterCallback <FocusEvent>((evt) => { var input = evt.target as VisualElement; var field = input.parent as TextField; m_FieldFocusedFromStandby = true; if (field.text == BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage || m_NewSelectorJustCreated) { m_NewSelectorJustCreated = false; field.value = BuilderConstants.UssSelectorClassNameSymbol; } ShowTooltip(); }); m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) => { var field = evt.target as TextField; if (!string.IsNullOrEmpty(evt.newValue) && evt.newValue != BuilderConstants.UssSelectorClassNameSymbol) { m_NewSelectorAddButton.SetEnabled(true); m_PseudoStatesMenu.SetEnabled(true); } else { m_NewSelectorAddButton.SetEnabled(false); m_PseudoStatesMenu.SetEnabled(false); } if (!m_FieldFocusedFromStandby) { return; } m_FieldFocusedFromStandby = false; // We don't want the '.' we just inserted in the FocusEvent to be highlighted, // which is the default behavior. field.SelectRange(1, 1); }); m_NewSelectorTextInputField.RegisterCallback <BlurEvent>((evt) => { var input = evt.target as VisualElement; var field = input.parent as TextField; if (m_NewSelectorJustCreated) { field.schedule.Execute(PostEnterRefocus); evt.PreventDefault(); evt.StopImmediatePropagation(); return; } if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol) { field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_NewSelectorAddButton.SetEnabled(false); m_PseudoStatesMenu.SetEnabled(false); } HideTooltip(); }); // Setup new selector button. m_NewSelectorAddButton = parent.Q <ToolbarButton>("add-new-selector-button"); m_NewSelectorAddButton.clickable.clicked += OnAddPress; m_NewSelectorAddButton.SetEnabled(false); // Setup pseudo states menu. m_PseudoStatesMenu = parent.Q <ToolbarMenu>("add-pseudo-state-menu"); m_PseudoStatesMenu.SetEnabled(false); SetUpPseudoStatesMenu(); }
public override void CreateUI() { var root = rootVisualElement; // Load assets. var builderTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/Builder.uxml"); var saveDialogTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/BuilderSaveDialog.uxml"); // Load templates. builderTemplate.CloneTree(root); saveDialogTemplate.CloneTree(root); // Create overlay painter. m_HighlightOverlayPainter = new HighlightOverlayPainter(); // Fetch the save dialog. var dialog = root.Q <ModalPopup>("save-dialog"); // Fetch the tooltip previews. var styleSheetsPaneTooltipPreview = root.Q <BuilderTooltipPreview>("stylesheets-pane-tooltip-preview"); var libraryTooltipPreview = root.Q <BuilderTooltipPreview>("library-tooltip-preview"); // Create selection. m_Selection = new BuilderSelection(root, this); // Create viewport first. m_Viewport = new BuilderViewport(this, selection); selection.documentElement = m_Viewport.documentElement; var overlayHelper = viewport.Q <OverlayPainterHelperElement>(); overlayHelper.painter = m_HighlightOverlayPainter; // Create the rest of the panes. var classDragger = new BuilderClassDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker); var hierarchyDragger = new BuilderHierarchyDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker); var contextMenuManipulator = new BuilderExplorerContextMenu(this, selection); var styleSheetsPane = new BuilderStyleSheets(m_Viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, m_HighlightOverlayPainter, styleSheetsPaneTooltipPreview); var hierarchy = new BuilderHierarchy(m_Viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, m_HighlightOverlayPainter); var libraryDragger = new BuilderLibraryDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker, hierarchy.container, libraryTooltipPreview); m_Library = new BuilderLibrary(this, m_Viewport, selection, libraryDragger, libraryTooltipPreview); m_Inspector = new BuilderInspector(this, selection); m_Toolbar = new BuilderToolbar(this, selection, dialog, m_Viewport, hierarchy, m_Library, m_Inspector, libraryTooltipPreview); m_UxmlPreview = new BuilderUxmlPreview(this); m_UssPreview = new BuilderUssPreview(this); root.Q("viewport").Add(m_Viewport); m_Viewport.toolbar.Add(m_Toolbar); root.Q("library").Add(m_Library); root.Q("style-sheets").Add(styleSheetsPane); root.Q("hierarchy").Add(hierarchy); root.Q("uxml-preview").Add(m_UxmlPreview); root.Q("uss-preview").Add(m_UssPreview); root.Q("inspector").Add(m_Inspector); // Init selection. selection.AssignNotifiers(new IBuilderSelectionNotifier[] { document, m_Viewport, styleSheetsPane, hierarchy, m_Inspector, m_UxmlPreview, m_UssPreview, m_Viewport.parentTracker, m_Viewport.resizer, m_Viewport.mover, m_Viewport.anchorer }); // Command Handler commandHandler.RegisterPane(styleSheetsPane); commandHandler.RegisterPane(hierarchy); commandHandler.RegisterPane(m_Viewport); commandHandler.RegisterToolbar(m_Toolbar); OnEnableAfterAllSerialization(); }
public ElementHierarchyView( VisualElement documentRootElement, BuilderSelection selection, BuilderClassDragger classDragger, BuilderHierarchyDragger hierarchyDragger, BuilderExplorerContextMenu contextMenuManipulator, Action <VisualElement> selectElementCallback, HighlightOverlayPainter highlightOverlayPainter) { m_DocumentRootElement = documentRootElement; m_Selection = selection; m_ClassDragger = classDragger; m_HierarchyDragger = hierarchyDragger; m_ContextMenuManipulator = contextMenuManipulator; this.focusable = true; m_SelectElementCallback = selectElementCallback; hierarchyHasChanged = true; m_SearchResultsHightlights = new List <VisualElement>(); this.RegisterCallback <FocusEvent>(e => m_TreeView?.Focus()); // HACK: ListView/TreeView need to clear their selections when clicking on nothing. this.RegisterCallback <MouseDownEvent>(e => { var leafTarget = e.leafTarget as VisualElement; if (leafTarget.parent is ScrollView) { ClearSelection(); } }); m_TreeViewHoverOverlay = highlightOverlayPainter; m_Container = new VisualElement(); m_Container.name = "explorer-container"; m_Container.style.flexGrow = 1; m_ClassDragger.builderHierarchyRoot = m_Container; m_HierarchyDragger.builderHierarchyRoot = m_Container; Add(m_Container); m_SearchBar = new ElementHierarchySearchBar(this); Add(m_SearchBar); // TODO: Hiding for now since search does not work, especially with style class pills. m_SearchBar.style.display = DisplayStyle.None; m_ClassPillTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>( BuilderConstants.UIBuilderPackagePath + "/BuilderClassPill.uxml"); // Create TreeView. m_TreeRootItems = new List <ITreeViewItem>(); m_TreeView = new TreeView(m_TreeRootItems, 20, MakeItem, FillItem); m_TreeView.viewDataKey = "unity-builder-explorer-tree"; m_TreeView.style.flexGrow = 1; #if UNITY_2020_1_OR_NEWER m_TreeView.onSelectionChange += OnSelectionChange; #else m_TreeView.onSelectionChanged += OnSelectionChange; #endif m_Container.Add(m_TreeView); m_ContextMenuManipulator.RegisterCallbacksOnTarget(m_Container); }