public BuilderToolbar(
            BuilderPaneWindow paneWindow,
            BuilderSelection selection,
            BuilderViewport viewport,
            BuilderExplorer explorer,
            BuilderLibrary library,
            BuilderInspector inspector,
            BuilderTooltipPreview tooltipPreview)
        {
            m_PaneWindow     = paneWindow;
            m_Selection      = selection;
            m_Viewport       = viewport;
            m_Explorer       = explorer;
            m_Library        = library;
            m_Inspector      = inspector;
            m_TooltipPreview = tooltipPreview;

            var template = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderToolbar.uxml");

            template.CloneTree(this);

#if !UNITY_2019_4 && !UNITY_2020_1
            m_ThemeManager                    = new ThemeStyleSheetManager(this);
            m_ThemeManager.selection          = m_Selection;
            m_ThemeManager.themeFilesChanged += UpdateCanvasThemeMenuStatus;
#else
            m_ThemeManager = null;
#endif

            // File Menu
            m_FileMenu = this.Q <ToolbarMenu>("file-menu");
            SetUpFileMenu();

            // Zoom Menu
            m_ZoomMenu = this.Q <ToolbarMenu>("zoom-menu");
            SetUpZoomMenu();

            // Fit canvas
            m_FitCanvasButton = this.Q <ToolbarButton>(FitCanvasButtonName);
            m_FitCanvasButton.clickable.clicked += () => m_Viewport.FitCanvas();

            // Preview Button
            var previewButton = this.Q <ToolbarToggle>(PreviewToggleName);
            previewButton.RegisterValueChangedCallback(TogglePreviewMode);

            m_CanvasThemeMenu = this.Q <ToolbarMenu>("canvas-theme-menu");
            SetUpCanvasThemeMenu();
            ChangeCanvasTheme(document.currentCanvasTheme, document.currentCanvasThemeStyleSheet);
            UpdateCanvasThemeMenuStatus();
            SetViewportSubTitle();

            // Track unsaved changes state change.
            SetCanvasTitle();

            m_SettingsMenu = this.Q <ToolbarMenu>("settings-menu");
            SetupSettingsMenu();

            // Breadcrumbs & BreadCrumbs Toolbar
            m_BreadcrumbsToolbar = this.Q <Toolbar>(BreadcrumbsToolbarName);
            m_Breadcrumbs        = this.Q <ToolbarBreadcrumbs>(BreadcrumbsName);
            SetToolbarBreadCrumbs();

            // Get Builder package version.
            var packageInfo = PackageInfo.FindForAssetPath("Packages/" + BuilderConstants.BuilderPackageName);
            if (packageInfo == null)
            {
                m_BuilderPackageVersion = null;
            }
            else
            {
                m_BuilderPackageVersion = packageInfo.version;
            }

            RegisterCallback <AttachToPanelEvent>(RegisterCallbacks);
        }
Exemplo n.º 2
0
        public BuilderToolbar(
            BuilderPaneWindow paneWindow,
            BuilderSelection selection,
            ModalPopup saveDialog,
            BuilderViewport viewport,
            BuilderExplorer explorer,
            BuilderLibrary library,
            BuilderInspector inspector,
            BuilderTooltipPreview tooltipPreview)
        {
            m_PaneWindow     = paneWindow;
            m_Selection      = selection;
            m_SaveDialog     = saveDialog;
            m_Viewport       = viewport;
            m_Explorer       = explorer;
            m_Library        = library;
            m_Inspector      = inspector;
            m_TooltipPreview = tooltipPreview;

            // Query the UI
            m_SaveDialogUxmlPathField      = m_SaveDialog.Q <TextField>("save-dialog-uxml-path");
            m_SaveDialogUxmlLocationButton = m_SaveDialog.Q <Button>("save-dialog-uxml-location-button");
            m_SaveDialogUssPathField       = m_SaveDialog.Q <TextField>("save-dialog-uss-path");
            m_SaveDialogUssLocationButton  = m_SaveDialog.Q <Button>("save-dialog-uss-location-button");
            m_SaveDialogSaveButton         = m_SaveDialog.Q <Button>("save-dialog-save-button");
            m_SaveDialogCancelButton       = m_SaveDialog.Q <Button>("save-dialog-cancel-button");
            m_SaveDialogTitleLabel         = m_SaveDialog.Q <Label>("title");

            m_SaveDialogUxmlPathField.RegisterValueChangedCallback(OnUxmlPathFieldChange);
            m_SaveDialogUssPathField.RegisterValueChangedCallback(OnUssPathFieldChange);
            m_SaveDialogUxmlPathField.RegisterCallback <KeyUpEvent>(OnSaveDialogEnterPress);
            m_SaveDialogUssPathField.RegisterCallback <KeyUpEvent>(OnSaveDialogEnterPress);

            m_SaveDialogSaveButton.clickable.clicked         += SaveDocument;
            m_SaveDialogCancelButton.clickable.clicked       += m_SaveDialog.Hide;
            m_SaveDialogUxmlLocationButton.clickable.clicked += OnUxmlLocationButtonClick;
            m_SaveDialogUssLocationButton.clickable.clicked  += OnUssLocationButtonClick;

            var saveDialogValidationBoxContainer = m_SaveDialog.Q("save-dialog-validation-box");

            m_SaveDialogValidationBox = new IMGUIContainer(DrawSaveDialogValidationMessage);
            m_SaveDialogValidationBox.style.overflow = Overflow.Hidden;
            saveDialogValidationBoxContainer.Add(m_SaveDialogValidationBox);

            var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderToolbar.uxml");

            template.CloneTree(this);

            // File Menu
            m_FileMenu = this.Q <ToolbarMenu>("file-menu");
            SetUpFileMenu();

            // Zoom Menu
            m_ZoomMenu = this.Q <ToolbarMenu>("zoom-menu");
            SetUpZoomMenu();

            // Fit canvas
            m_FitCanvasButton = this.Q <ToolbarButton>("fit-canvas-button");
            m_FitCanvasButton.clickable.clicked += () => m_Viewport.FitCanvas();

            // Preview Button
            var previewButton = this.Q <ToolbarToggle>("preview-button");

            previewButton.RegisterValueChangedCallback(TogglePreviewMode);

            m_CanvasThemeMenu = this.Q <ToolbarMenu>("canvas-theme-menu");
            SetUpCanvasThemeMenu();
            ChangeCanvasTheme(document.currentCanvasTheme);
            UpdateCanvasThemeMenuStatus();

            // Track unsaved changes state change.
            SetViewportSubTitle();

            // Get Builder package version.
            var packageInfo = PackageInfo.FindForAssetPath("Packages/" + BuilderConstants.BuilderPackageName);

            if (packageInfo == null)
            {
                m_BuilderPackageVersion = null;
            }
            else
            {
                m_BuilderPackageVersion = packageInfo.version;
            }

            RegisterCallback <AttachToPanelEvent>(RegisterCallbacks);
        }
Exemplo n.º 3
0
        public BuilderToolbar(
            BuilderPaneWindow paneWindow,
            BuilderSelection selection,
            BuilderViewport viewport,
            BuilderExplorer explorer,
            BuilderLibrary library,
            BuilderInspector inspector,
            BuilderTooltipPreview tooltipPreview)
        {
            m_PaneWindow     = paneWindow;
            m_Selection      = selection;
            m_Viewport       = viewport;
            m_Explorer       = explorer;
            m_Library        = library;
            m_Inspector      = inspector;
            m_TooltipPreview = tooltipPreview;

            var template = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderToolbar.uxml");

            template.CloneTree(this);

            m_ThemeManager                    = new ThemeStyleSheetManager(this);
            m_ThemeManager.selection          = m_Selection;
            m_ThemeManager.themeFilesChanged += UpdateCanvasThemeMenuStatus;

            // File Menu
            m_FileMenu = this.Q <ToolbarMenu>("file-menu");
            SetUpFileMenu();

            // Zoom Menu
            m_ZoomMenu = this.Q <ToolbarMenu>("zoom-menu");
            SetUpZoomMenu();

            // Fit canvas
            m_FitCanvasButton = this.Q <ToolbarButton>(FitCanvasButtonName);
            m_FitCanvasButton.clickable.clicked += () => m_Viewport.FitCanvas();

            // Preview Button
            var previewButton = this.Q <ToolbarToggle>(PreviewToggleName);

            previewButton.RegisterValueChangedCallback(TogglePreviewMode);

            m_Viewport.SetPreviewMode(false);

            m_CanvasThemeMenu = this.Q <ToolbarMenu>("canvas-theme-menu");

            InitCanvasTheme();

            SetViewportSubTitle();

            // Track unsaved changes state change.
            UpdateHasUnsavedChanges();

            m_SettingsMenu = this.Q <ToolbarMenu>("settings-menu");
            SetupSettingsMenu();

            // Breadcrumbs & BreadCrumbs Toolbar
            m_BreadcrumbsToolbar = this.Q <Toolbar>(BreadcrumbsToolbarName);
            m_Breadcrumbs        = this.Q <ToolbarBreadcrumbs>(BreadcrumbsName);
            SetToolbarBreadCrumbs();

            RegisterCallback <AttachToPanelEvent>(RegisterCallbacks);
        }
Exemplo n.º 4
0
        public BuilderStyleSheets(
            BuilderPaneWindow paneWindow,
            BuilderViewport viewport,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderStyleSheetsDragger styleSheetsDragger,
            HighlightOverlayPainter highlightOverlayPainter,
            BuilderTooltipPreview tooltipPreview)
            : base(
                paneWindow,
                viewport,
                selection,
                classDragger,
                styleSheetsDragger,
                new BuilderStyleSheetsContextMenu(paneWindow, selection),
                viewport.styleSelectorElementContainer,
                false,
                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_NewSelectorField     = parent.Q <BuilderNewSelectorField>("new-selector-field");
            m_NewSelectorTextField = m_NewSelectorField.textField;
            m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
            m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input");
            m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown);
            UpdateNewSelectorFieldEnabledStateFromDocument();

            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_ShouldRefocusSelectorFieldOnBlur)
                {
                    m_ShouldRefocusSelectorFieldOnBlur = false;
                    field.value = BuilderConstants.UssSelectorClassNameSymbol;
                }

                ShowTooltip();
            });

            m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                var field = evt.target as TextField;

                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_ShouldRefocusSelectorFieldOnBlur)
                {
                    field.schedule.Execute(PostEnterRefocus);
                    evt.PreventDefault();
                    evt.StopImmediatePropagation();
                    return;
                }

                if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol)
                {
                    field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
                    m_PseudoStatesMenu.SetEnabled(false);
                }

                HideTooltip();
            });

            // Setup New USS Menu.
            m_AddUSSMenu = parent.Q <ToolbarMenu>("add-uss-menu");
            SetUpAddUSSMenu();

            // Setup pseudo states menu.
            m_PseudoStatesMenu = m_NewSelectorField.pseudoStatesMenu;

            // Update sub title.
            UpdateSubtitleFromActiveUSS();
        }