void ValidateStyleSelectorNameChange(string value) { if (!BuilderNameUtilities.styleSelectorRegex.IsMatch(value)) { Builder.ShowWarning(string.Format(BuilderConstants.StyleSelectorValidationSpacialCharacters, "Name")); m_TextField.schedule.Execute(() => { var baseInput = m_TextField.Q(TextField.textInputUssName); if (baseInput.focusController != null) { baseInput.focusController.DoFocusChange(baseInput); } m_TextField.SetValueWithoutNotify(value); m_TextField.SelectAll(); }); return; } Undo.RegisterCompleteObjectUndo( styleSheet, BuilderConstants.RenameSelectorUndoMessage); BuilderSharedStyles.SetSelectorString(currentVisualElement, styleSheet, value); m_Selection.NotifyOfHierarchyChange(m_Inspector); m_Selection.NotifyOfStylingChange(m_Inspector); }
public void SelectionChanged() { if (m_CurrentVisualElement != null && BuilderSharedStyles.IsSelectorElement(m_CurrentVisualElement)) { StyleSheetUtilities.RemoveFakeSelector(m_CurrentVisualElement); } m_CurrentVisualElement = null; foreach (var element in m_Selection.selection) { if (m_CurrentVisualElement != null) // We only support editing one element. Disable for for multiple elements. { m_CurrentVisualElement = null; break; } m_CurrentVisualElement = element; } if (m_CurrentVisualElement != null) { m_CachedVisualElement = m_CurrentVisualElement; } if (m_CurrentVisualElement != null && BuilderSharedStyles.IsSelectorElement(m_CurrentVisualElement)) { StyleSheetUtilities.AddFakeSelector(m_CurrentVisualElement); m_Selection.NotifyOfStylingChange(null, null, BuilderStylingChangeType.RefreshOnly); } else { RefreshUI(); } }
void OnEditTextFinished(VisualElement documentElement, TextField renameTextfield, Label nameLabel, BuilderSelection selection) { var vea = documentElement.GetVisualElementAsset(); var value = renameTextfield.text ?? documentElement.name; if (documentElement.IsSelector()) { value = value.Trim(); var stylesheet = documentElement.GetStyleSheet(); if (!string.IsNullOrEmpty(renameTextfield.text)) { if (!BuilderNameUtilities.styleSelectorRegex.IsMatch(value)) { Builder.ShowWarning(string.Format(BuilderConstants.StyleSelectorValidationSpacialCharacters, "Name")); renameTextfield.schedule.Execute(() => { FocusOnRenameTextField(); renameTextfield.SetValueWithoutNotify(value); }); return; } BuilderSharedStyles.SetSelectorString(documentElement, stylesheet, value); } selection.NotifyOfStylingChange(); } else { 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); }
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 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); }
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); }
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 }); }
public void ClearSelectionNotify() { m_Selection.ClearSelection(null); m_Selection.NotifyOfHierarchyChange(null); m_Selection.NotifyOfStylingChange(null); }