From 90906baae2e91faaf7345971c595de526ce1893c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 6 May 2022 17:14:25 +0200 Subject: [PATCH] Various improvements for Editor --- Source/Editor/Content/Items/ContentItem.cs | 13 +------- Source/Editor/GUI/Docking/DockWindow.cs | 5 +++ Source/Editor/Modules/ContentFindingModule.cs | 9 ++---- Source/Editor/Surface/VisjectSurfaceWindow.cs | 9 ++++++ Source/Editor/Utilities/Utils.cs | 14 +++++++++ .../Windows/Assets/VisualScriptWindow.cs | 4 +++ Source/Editor/Windows/ContentWindow.cs | 31 +++++++++---------- 7 files changed, 49 insertions(+), 36 deletions(-) diff --git a/Source/Editor/Content/Items/ContentItem.cs b/Source/Editor/Content/Items/ContentItem.cs index cc0ece600..a97f455f3 100644 --- a/Source/Editor/Content/Items/ContentItem.cs +++ b/Source/Editor/Content/Items/ContentItem.cs @@ -271,18 +271,7 @@ namespace FlaxEditor.Content /// /// Gets the asset name relative to the project root folder (without asset file extension) /// - public string NamePath - { - get - { - string result = Path; - if (result.StartsWith(Globals.ProjectFolder)) - { - result = result.Substring(Globals.ProjectFolder.Length + 1); - } - return StringUtils.GetPathWithoutExtension(result); - } - } + public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path); /// /// Gets the default name of the content item thumbnail. Returns null if not used. diff --git a/Source/Editor/GUI/Docking/DockWindow.cs b/Source/Editor/GUI/Docking/DockWindow.cs index 438d4b84d..49b73bfea 100644 --- a/Source/Editor/GUI/Docking/DockWindow.cs +++ b/Source/Editor/GUI/Docking/DockWindow.cs @@ -56,6 +56,11 @@ namespace FlaxEditor.GUI.Docking /// public bool IsSelected => _dockedTo?.SelectedTab == this; + /// + /// Gets a value indicating whether this window is hidden from the user (eg. not shown or hidden on closed). + /// + public bool IsHidden => !Visible || _dockedTo == null; + /// /// Gets the default window size. /// diff --git a/Source/Editor/Modules/ContentFindingModule.cs b/Source/Editor/Modules/ContentFindingModule.cs index 764000d84..89d5914fa 100644 --- a/Source/Editor/Modules/ContentFindingModule.cs +++ b/Source/Editor/Modules/ContentFindingModule.cs @@ -48,11 +48,6 @@ namespace FlaxEditor.Modules private List _quickActions; private ContentFinder _finder; - /// - /// The content finding context menu. - /// - internal ContentFinder Finder => _finder ?? (_finder = new ContentFinder()); - /// /// Initializes a new instance of the class. /// @@ -81,12 +76,12 @@ namespace FlaxEditor.Modules } /// - /// Shows the finder. + /// Shows the content finder popup. /// /// The target control to show finder over it. public void ShowFinder(Control control) { - var finder = Finder; + var finder = _finder ?? (_finder = new ContentFinder()); var position = (control.Size - new Vector2(finder.Width, 300.0f)) * 0.5f; finder.Show(control, position); } diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 733cd2682..e475c0f2d 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -41,6 +41,11 @@ namespace FlaxEditor.Surface /// IEnumerable NewParameterTypes { get; } + /// + /// Event called when surface gets loaded (eg. after opening the window). + /// + event Action SurfaceLoaded; + /// /// Called when parameter rename undo action is performed. /// @@ -974,6 +979,7 @@ namespace FlaxEditor.Surface _showWholeGraphOnLoad = false; _surface.ShowWholeGraph(); } + SurfaceLoaded?.Invoke(); } else if (_refreshPropertiesOnLoad && _asset.IsLoaded) { @@ -1023,6 +1029,9 @@ namespace FlaxEditor.Surface /// public abstract IEnumerable NewParameterTypes { get; } + /// + public event Action SurfaceLoaded; + /// public virtual void OnParamRenameUndo() { diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 9ec08aacc..dbdac487b 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -897,5 +897,19 @@ namespace FlaxEditor.Utilities }; return menu; } + + /// + /// Gets the asset name relative to the project root folder (without asset file extension) + /// + /// The asset path. + /// The processed name path. + public static string GetAssetNamePath(string path) + { + if (path.StartsWith(Globals.ProjectFolder)) + { + path = path.Substring(Globals.ProjectFolder.Length + 1); + } + return StringUtils.GetPathWithoutExtension(path); + } } } diff --git a/Source/Editor/Windows/Assets/VisualScriptWindow.cs b/Source/Editor/Windows/Assets/VisualScriptWindow.cs index dd56e14b9..b76d2427d 100644 --- a/Source/Editor/Windows/Assets/VisualScriptWindow.cs +++ b/Source/Editor/Windows/Assets/VisualScriptWindow.cs @@ -1322,6 +1322,7 @@ namespace FlaxEditor.Windows.Assets _surface.ShowWholeGraph(); } LoadBreakpoints(); + SurfaceLoaded?.Invoke(); Editor.VisualScriptingDebugFlow += OnDebugFlow; } else if (_refreshPropertiesOnLoad && _asset.IsLoaded) @@ -1381,6 +1382,9 @@ namespace FlaxEditor.Windows.Assets /// public IEnumerable NewParameterTypes => Editor.CodeEditing.VisualScriptPropertyTypes.Get(); + /// + public event Action SurfaceLoaded; + /// public void OnParamRenameUndo() { diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index c98dbd8a8..320e7e4aa 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -220,7 +220,7 @@ namespace FlaxEditor.Windows filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text); } }; - + var sortBy = menu.AddChildMenu("Sort by"); sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked).Tag = SortType.AlphabeticOrder; sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked).Tag = SortType.AlphabeticReverse; @@ -260,10 +260,12 @@ namespace FlaxEditor.Windows { switch ((SortType)button.Tag) { - case SortType.AlphabeticOrder: _sortType = SortType.AlphabeticOrder; - break; - case SortType.AlphabeticReverse: _sortType = SortType.AlphabeticReverse; - break; + case SortType.AlphabeticOrder: + _sortType = SortType.AlphabeticOrder; + break; + case SortType.AlphabeticReverse: + _sortType = SortType.AlphabeticReverse; + break; } RefreshView(SelectedNode); } @@ -446,14 +448,15 @@ namespace FlaxEditor.Windows /// The items to delete. public void Delete(List items) { - if (items.Count == 0) return; + if (items.Count == 0) + return; // TODO: remove items that depend on different items in the list: use wants to remove `folderA` and `folderA/asset.x`, we should just remove `folderA` var toDelete = new List(items); - string msg = toDelete.Count == 1 ? - string.Format("Are you sure to delete \'{0}\'?\nThis action cannot be undone. Files will be deleted permanently.", items[0].Path) - : string.Format("Are you sure to delete {0} selected items?\nThis action cannot be undone. Files will be deleted permanently.", items.Count); + string msg = toDelete.Count == 1 + ? string.Format("Are you sure to delete \'{0}\'?\nThis action cannot be undone. Files will be deleted permanently.", items[0].Path) + : string.Format("Are you sure to delete {0} selected items?\nThis action cannot be undone. Files will be deleted permanently.", items.Count); // Ask user if (MessageBox.Show(msg, "Delete asset(s)", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) @@ -767,12 +770,6 @@ namespace FlaxEditor.Windows _navigateUpButton.Enabled = folder != null && _tree.SelectedNode != _root; } - private void AddFolder2Root(ContentTreeNode node) - { - // Add to the root - _root.AddChild(node); - } - private void RemoveFolder2Root(ContentTreeNode node) { // Remove from the root @@ -790,7 +787,7 @@ namespace FlaxEditor.Windows _root.Expand(true); foreach (var project in Editor.ContentDatabase.Projects) - AddFolder2Root(project); + _root.AddChild(project); Editor.ContentDatabase.Game?.Expand(true); _tree.Margin = new Margin(0.0f, 0.0f, -16.0f, 2.0f); // Hide root node @@ -842,7 +839,7 @@ namespace FlaxEditor.Windows { while (_root.HasChildren) { - RemoveFolder2Root((ContentTreeNode)_root.GetChild(0)); + _root.RemoveChild((ContentTreeNode)_root.GetChild(0)); } } }