void UnsetAllAttributes(DropdownMenuAction action) { var attributeList = currentVisualElement.GetAttributeDescriptions(); // Undo/Redo Undo.RegisterCompleteObjectUndo(m_Inspector.visualTreeAsset, BuilderConstants.ChangeAttributeValueUndoMessage); foreach (var attribute in attributeList) { if (attribute?.name == null) { continue; } // Unset value in asset. var vea = currentVisualElement.GetVisualElementAsset(); vea.RemoveAttribute(attribute.name); } var fields = m_AttributesSection.Query <BindableElement>().Where(e => !string.IsNullOrEmpty(e.bindingPath)).ToList(); foreach (var fieldElement in fields) { // Reset UI value. ResetAttributeFieldToDefault(fieldElement); } // Call Init(); CallInitOnElement(); // Notify of changes. m_Selection.NotifyOfHierarchyChange(m_Inspector); }
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); }
void AddStyleClass(string className) { PreAddStyleClass(className); // Update VisualTreeAsset. BuilderAssetUtilities.AddStyleClassToElementInAsset( m_PaneWindow.document, currentVisualElement, className); // We actually want to get the notification back and refresh ourselves. m_Selection.NotifyOfHierarchyChange(null); m_Selection.NotifyOfStylingChange(null); }
public void Paste() { var copyBuffer = BuilderEditorUtility.SystemCopyBuffer; if (string.IsNullOrEmpty(copyBuffer)) { return; } var trimmedBuffer = copyBuffer.Trim(); if (trimmedBuffer.StartsWith("<") && trimmedBuffer.EndsWith(">")) { PasteUXML(copyBuffer); } else if (trimmedBuffer.EndsWith("}")) { PasteUSS(copyBuffer); } else // Unknown string. { return; } if (m_CutElements.Count > 0) { foreach (var elementToCut in m_CutElements) { DeleteElement(elementToCut); } m_CutElements.Clear(); BuilderEditorUtility.SystemCopyBuffer = null; } m_PaneWindow.OnEnableAfterAllSerialization(); // TODO: ListView bug. Does not refresh selection pseudo states after a // call to Refresh(). m_PaneWindow.rootVisualElement.schedule.Execute(() => { if (m_Selection.isEmpty) { return; } m_Selection.ForceReselection(); }).ExecuteLater(200); m_Selection.NotifyOfHierarchyChange(); }
public void Paste() { var focused = m_PaneWindow.rootVisualElement.focusController.focusedElement as VisualElement; if (!BuilderEditorUtility.CopyBufferMatchesTarget(focused)) { return; } var copyBuffer = BuilderEditorUtility.systemCopyBuffer; if (BuilderEditorUtility.IsUxml(copyBuffer)) { PasteUXML(copyBuffer); } else if (BuilderEditorUtility.IsUss(copyBuffer)) { PasteUSS(copyBuffer); } else // Unknown string. { return; } if (m_CutElements.Count > 0) { foreach (var elementToCut in m_CutElements) { DeleteElement(elementToCut); } m_CutElements.Clear(); BuilderEditorUtility.systemCopyBuffer = null; } m_PaneWindow.OnEnableAfterAllSerialization(); // TODO: ListView bug. Does not refresh selection pseudo states after a // call to Refresh(). m_PaneWindow.rootVisualElement.schedule.Execute(() => { if (m_Selection.isEmpty) { return; } m_Selection.ForceReselection(); }).ExecuteLater(200); m_Selection.NotifyOfHierarchyChange(); }
void OnEditTextFinished(VisualElement documentElement, TextField renameTextfield, Label nameLabel, BuilderSelection selection) { var vea = documentElement.GetVisualElementAsset(); var value = renameTextfield.text ?? documentElement.name; if (!string.IsNullOrEmpty(renameTextfield.text)) { value = value.Trim(); value = value.TrimStart('#'); if (!BuilderNameUtilities.AttributeRegex.IsMatch(value)) { Builder.ShowWarning(string.Format(BuilderConstants.AttributeValidationSpacialCharacters, "Name")); renameTextfield.schedule.Execute(() => { FocusOnRenameTextField(); renameTextfield.SetValueWithoutNotify(value); }); return; } nameLabel.text = BuilderConstants.UssSelectorNameSymbol + value; } else { nameLabel.text = renameTextfield.text; } documentElement.name = value; vea.SetAttributeValue("name", value); selection.NotifyOfHierarchyChange(); }
void OnStyleSelectorNameChange(ChangeEvent <string> evt) { if (m_Selection.selectionType != BuilderSelectionType.StyleSelector) { return; } if (evt.newValue.Length == 0) { Refresh(); return; } if (evt.newValue == evt.previousValue) { return; } Undo.RegisterCompleteObjectUndo( styleSheet, BuilderConstants.RenameSelectorUndoMessage); BuilderSharedStyles.SetSelectorString(currentVisualElement, styleSheet, evt.newValue); m_Selection.NotifyOfHierarchyChange(m_Inspector); m_Selection.NotifyOfStylingChange(m_Inspector); }
public TextField CreateRenamingTextField(VisualElement documentElement, Label nameLabel, BuilderSelection selection) { var renameTextfield = new TextField() { name = BuilderConstants.ExplorerItemRenameTextfieldName, isDelayed = true }; #if UNITY_2019_3_OR_NEWER renameTextfield.AddToClassList(BuilderConstants.ExplorerItemRenameTextfieldClassName); #else renameTextfield.AddToClassList(BuilderConstants.ExplorerItemRenameTextfieldClassNamePre2019_3); #endif renameTextfield.SetValueWithoutNotify( string.IsNullOrEmpty(documentElement.name) ? documentElement.typeName : documentElement.name); renameTextfield.AddToClassList(BuilderConstants.HiddenStyleClassName); renameTextfield.RegisterCallback <KeyUpEvent>((e) => { e.StopImmediatePropagation(); }); renameTextfield.RegisterValueChangedCallback((e) => { documentElement.name = e.newValue; var vea = documentElement.GetVisualElementAsset(); vea.SetAttributeValue("name", e.newValue); if (!string.IsNullOrEmpty(e.newValue)) { nameLabel.text = "#" + e.newValue; } else { nameLabel.text = e.newValue; } e.StopPropagation(); selection.NotifyOfHierarchyChange(); }); renameTextfield.RegisterCallback <BlurEvent>((e) => { nameLabel.RemoveFromClassList(BuilderConstants.HiddenStyleClassName); renameTextfield.AddToClassList(BuilderConstants.HiddenStyleClassName); renameTextfield.SetValueWithoutNotify(string.IsNullOrEmpty(documentElement.name) ? documentElement.typeName : documentElement.name); e.StopPropagation(); }); return(renameTextfield); }
void OnItemChosen(ITreeViewItem selectedItem) #endif { #if UNITY_2020_1_OR_NEWER if (selectedItems == null || selectedItems.Count() == 0) { return; } var selectedItem = selectedItems.First(); #else if (selectedItem == null) { return; } #endif var item = selectedItem as LibraryTreeItem; if (item.makeVisualElement == null) { return; } // If this is the uxml file entry of the currently open file, don't allow // the user to instantiate it (infinite recursion) or re-open it. if (item.name == m_PaneWindow.document.uxmlFileName) { return; } var newElement = item.makeVisualElement(); if (newElement == null) { return; } m_DocumentElement.Add(newElement); if (item.makeElementAsset == null) { BuilderAssetUtilities.AddElementToAsset(m_PaneWindow.document, newElement); } else { BuilderAssetUtilities.AddElementToAsset( m_PaneWindow.document, newElement, item.makeElementAsset); } // TODO: ListView bug. Does not refresh selection pseudo states after a // call to Refresh(). m_Selection.NotifyOfHierarchyChange(null); this.schedule.Execute(() => { m_Selection.Select(null, newElement); }).ExecuteLater(200); }
protected void AddItemToTheDocument(BuilderLibraryTreeItem item) { // If this is the uxml file entry of the currently open file, don't allow // the user to instantiate it (infinite recursion) or re-open it. var listOfOpenDocuments = m_PaneWindow.document.openUXMLFiles; bool isCurrentDocumentOpen = listOfOpenDocuments.Any(doc => doc.uxmlFileName == item.name); if (isCurrentDocumentOpen) { return; } if (m_PaneWindow.document.WillCauseCircularDependency(item.sourceAsset)) { BuilderDialogsUtility.DisplayDialog(BuilderConstants.InvalidWouldCauseCircularDependencyMessage, BuilderConstants.InvalidWouldCauseCircularDependencyMessageDescription, null); return; } var newElement = item.makeVisualElementCallback?.Invoke(); if (newElement == null) { return; } if (item.makeElementAssetCallback != null && newElement is TemplateContainer tempContainer) { if (!BuilderAssetUtilities.ValidateAsset(item.sourceAsset, item.sourceAssetPath)) { return; } } var activeVTARootElement = m_DocumentRootElement.Query().Where(e => e.GetVisualTreeAsset() == m_PaneWindow.document.visualTreeAsset).First(); if (activeVTARootElement == null) { Debug.LogError("UI Builder has a bug. Could not find document root element for currently active open UXML document."); return; } activeVTARootElement.Add(newElement); if (item.makeElementAssetCallback == null) { BuilderAssetUtilities.AddElementToAsset(m_PaneWindow.document, newElement); } else { BuilderAssetUtilities.AddElementToAsset( m_PaneWindow.document, newElement, item.makeElementAssetCallback); } m_Selection.NotifyOfHierarchyChange(); m_Selection.Select(null, newElement); }
private void UnsetName(DropdownMenuAction action) { // Undo/Redo Undo.RegisterCompleteObjectUndo(m_Inspector.visualTreeAsset, BuilderConstants.ChangeAttributeValueUndoMessage); // Unset value in asset. var vea = currentVisualElement.GetVisualElementAsset(); vea.RemoveAttribute("name"); m_TextField.SetValueWithoutNotify(string.Empty); m_Inspector.CallInitOnElement(); // Notify of changes. m_Selection.NotifyOfHierarchyChange(m_Inspector); ToggleNameOverrideBox(false); }
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(); }
void NotifyStyleChanges(List <string> styles = null) { if (BuilderSharedStyles.IsSelectorElement(currentVisualElement)) { m_Selection.NotifyOfStylingChange(m_Inspector, styles); } else { m_Selection.NotifyOfStylingChange(m_Inspector, styles); m_Selection.NotifyOfHierarchyChange(m_Inspector, currentVisualElement, BuilderHierarchyChangeType.InlineStyle); } }
void CreateNewSelector(string newSelectorString) { m_NewSelectorNameNameField.SetValueWithoutNotify(string.Empty); Undo.RegisterCompleteObjectUndo( styleSheet, BuilderConstants.AddNewSelectorUndoMessage); BuilderSharedStyles.CreateNewSelector( currentVisualElement, styleSheet, newSelectorString); m_Selection.NotifyOfHierarchyChange(m_Inspector); m_Selection.NotifyOfStylingChange(m_Inspector); }
void UnsetAttributeProperty(DropdownMenuAction action) { var fieldElement = action.userData as BindableElement; var attributeName = fieldElement.bindingPath; // Undo/Redo Undo.RegisterCompleteObjectUndo(m_Inspector.visualTreeAsset, BuilderConstants.ChangeAttributeValueUndoMessage); // Unset value in asset. var vea = currentVisualElement.GetVisualElementAsset(); vea.RemoveAttribute(attributeName); // Reset UI value. ResetAttributeFieldToDefault(fieldElement); // Call Init(); CallInitOnElement(); // Notify of changes. m_Selection.NotifyOfHierarchyChange(m_Inspector); }
public override void OnEnableAfterAllSerialization() { // Perform post-serialization functions. document.OnAfterBuilderDeserialize(m_Viewport.documentElement); m_Toolbar.OnAfterBuilderDeserialize(); // Restore selection. selection.RestoreSelectionFromDocument(m_Viewport.sharedStylesAndDocumentElement); // We claim the change is coming from the Document because we don't // want the document hasUnsavedChanges flag to be set at this time. m_Selection.NotifyOfStylingChange(document); m_Selection.NotifyOfHierarchyChange(document); }
protected void AddItemToTheDocument(BuilderLibraryTreeItem item) { // If this is the uxml file entry of the currently open file, don't allow // the user to instantiate it (infinite recursion) or re-open it. var listOfOpenDocuments = m_PaneWindow.document.openUXMLFiles; bool isCurrentDocumentOpen = listOfOpenDocuments.Any(doc => doc.uxmlFileName == item.name); if (isCurrentDocumentOpen) { return; } var newElement = item.makeVisualElementCallback?.Invoke(); if (newElement == null) { return; } var activeVTARootElement = m_DocumentRootElement.Query().Where(e => e.GetVisualTreeAsset() == m_PaneWindow.document.visualTreeAsset).First(); if (activeVTARootElement == null) { Debug.LogError("UI Builder has a bug. Could not find document root element for currently active open UXML document."); return; } activeVTARootElement.Add(newElement); if (item.makeElementAssetCallback == null) { BuilderAssetUtilities.AddElementToAsset(m_PaneWindow.document, newElement); } else { BuilderAssetUtilities.AddElementToAsset( m_PaneWindow.document, newElement, item.makeElementAssetCallback); } // TODO: ListView bug. Does not refresh selection pseudo states after a // call to Refresh(). m_Selection.NotifyOfHierarchyChange(); schedule.Execute(() => { m_Selection.Select(null, newElement); }).ExecuteLater(200); }
void FlexDirectionOnToggle() { var result = FlexDirection.Column; switch (m_Target.resolvedStyle.flexDirection) { case FlexDirection.Column: result = FlexDirection.ColumnReverse; break; case FlexDirection.ColumnReverse: result = FlexDirection.Row; break; case FlexDirection.Row: result = FlexDirection.RowReverse; break; case FlexDirection.RowReverse: result = FlexDirection.Column; break; } FlexDirectionUpdateToggleIcon(result); BuilderStyleUtilities.SetInlineStyleValue(m_VisualTreeAsset, m_Target, k_FlexDirectionName, result); m_Selection.NotifyOfHierarchyChange(null, m_Target, BuilderHierarchyChangeType.InlineStyle | BuilderHierarchyChangeType.FullRefresh); m_Selection.NotifyOfStylingChange(null, new List <string>() { k_FlexDirectionName }); }
protected void AddItemToTheDocument(BuilderLibraryTreeItem item) { // If this is the uxml file entry of the currently open file, don't allow // the user to instantiate it (infinite recursion) or re-open it. var listOfOpenDocuments = m_PaneWindow.document.openUXMLFiles; bool isCurrentDocumentOpen = listOfOpenDocuments.Any(doc => doc.uxmlFileName == item.Name); if (isCurrentDocumentOpen) { return; } var newElement = item.MakeVisualElementCallback?.Invoke(); if (newElement == null) { return; } m_DocumentElement.Add(newElement); if (item.MakeElementAssetCallback == null) { BuilderAssetUtilities.AddElementToAsset(m_PaneWindow.document, newElement); } else { BuilderAssetUtilities.AddElementToAsset( m_PaneWindow.document, newElement, item.MakeElementAssetCallback); } // TODO: ListView bug. Does not refresh selection pseudo states after a // call to Refresh(). m_Selection.NotifyOfHierarchyChange(); schedule.Execute(() => { m_Selection.Select(null, newElement); }).ExecuteLater(200); }
public TextField CreateRenamingTextField(VisualElement documentElement, Label nameLabel, BuilderSelection selection) { var renameTextfield = new TextField() { name = BuilderConstants.ExplorerItemRenameTextfieldName, isDelayed = true }; #if UNITY_2019_3_OR_NEWER renameTextfield.AddToClassList(BuilderConstants.ExplorerItemRenameTextfieldClassName); #else renameTextfield.AddToClassList(BuilderConstants.ExplorerItemRenameTextfieldClassNamePre2019_3); #endif renameTextfield.SetValueWithoutNotify( string.IsNullOrEmpty(documentElement.name) ? documentElement.typeName : documentElement.name); renameTextfield.AddToClassList(BuilderConstants.HiddenStyleClassName); renameTextfield.RegisterCallback <KeyUpEvent>((e) => { e.StopImmediatePropagation(); }); renameTextfield.RegisterValueChangedCallback((e) => { var vea = documentElement.GetVisualElementAsset(); var value = e.newValue; if (!string.IsNullOrEmpty(e.newValue)) { value = value.Trim(); value = value.TrimStart('#'); if (!BuilderNameUtilities.AttributeRegex.IsMatch(value)) { Builder.ShowWarning(string.Format(BuilderConstants.AttributeValidationSpacialCharacters, "Name")); renameTextfield.schedule.Execute(() => { FocusOnRenameTextField(); renameTextfield.SetValueWithoutNotify(value); }); e.StopPropagation(); return; } nameLabel.text = BuilderConstants.UssSelectorNameSymbol + value; } else { nameLabel.text = e.newValue; } documentElement.name = value; vea.SetAttributeValue("name", value); e.StopPropagation(); selection.NotifyOfHierarchyChange(); }); return(renameTextfield); }
public void ClearSelectionNotify() { m_Selection.ClearSelection(null); m_Selection.NotifyOfHierarchyChange(null); m_Selection.NotifyOfStylingChange(null); }