Various improvements for Editor

This commit is contained in:
Wojtek Figat
2022-05-06 17:14:25 +02:00
parent 3766488114
commit 90906baae2
7 changed files with 49 additions and 36 deletions

View File

@@ -271,18 +271,7 @@ namespace FlaxEditor.Content
/// <summary> /// <summary>
/// Gets the asset name relative to the project root folder (without asset file extension) /// Gets the asset name relative to the project root folder (without asset file extension)
/// </summary> /// </summary>
public string NamePath public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path);
{
get
{
string result = Path;
if (result.StartsWith(Globals.ProjectFolder))
{
result = result.Substring(Globals.ProjectFolder.Length + 1);
}
return StringUtils.GetPathWithoutExtension(result);
}
}
/// <summary> /// <summary>
/// Gets the default name of the content item thumbnail. Returns null if not used. /// Gets the default name of the content item thumbnail. Returns null if not used.

View File

@@ -56,6 +56,11 @@ namespace FlaxEditor.GUI.Docking
/// </summary> /// </summary>
public bool IsSelected => _dockedTo?.SelectedTab == this; public bool IsSelected => _dockedTo?.SelectedTab == this;
/// <summary>
/// Gets a value indicating whether this window is hidden from the user (eg. not shown or hidden on closed).
/// </summary>
public bool IsHidden => !Visible || _dockedTo == null;
/// <summary> /// <summary>
/// Gets the default window size. /// Gets the default window size.
/// </summary> /// </summary>

View File

@@ -48,11 +48,6 @@ namespace FlaxEditor.Modules
private List<QuickAction> _quickActions; private List<QuickAction> _quickActions;
private ContentFinder _finder; private ContentFinder _finder;
/// <summary>
/// The content finding context menu.
/// </summary>
internal ContentFinder Finder => _finder ?? (_finder = new ContentFinder());
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ContentFindingModule"/> class. /// Initializes a new instance of the <see cref="ContentFindingModule"/> class.
/// </summary> /// </summary>
@@ -81,12 +76,12 @@ namespace FlaxEditor.Modules
} }
/// <summary> /// <summary>
/// Shows the finder. /// Shows the content finder popup.
/// </summary> /// </summary>
/// <param name="control">The target control to show finder over it.</param> /// <param name="control">The target control to show finder over it.</param>
public void ShowFinder(Control control) 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; var position = (control.Size - new Vector2(finder.Width, 300.0f)) * 0.5f;
finder.Show(control, position); finder.Show(control, position);
} }

View File

@@ -41,6 +41,11 @@ namespace FlaxEditor.Surface
/// </summary> /// </summary>
IEnumerable<ScriptType> NewParameterTypes { get; } IEnumerable<ScriptType> NewParameterTypes { get; }
/// <summary>
/// Event called when surface gets loaded (eg. after opening the window).
/// </summary>
event Action SurfaceLoaded;
/// <summary> /// <summary>
/// Called when parameter rename undo action is performed. /// Called when parameter rename undo action is performed.
/// </summary> /// </summary>
@@ -974,6 +979,7 @@ namespace FlaxEditor.Surface
_showWholeGraphOnLoad = false; _showWholeGraphOnLoad = false;
_surface.ShowWholeGraph(); _surface.ShowWholeGraph();
} }
SurfaceLoaded?.Invoke();
} }
else if (_refreshPropertiesOnLoad && _asset.IsLoaded) else if (_refreshPropertiesOnLoad && _asset.IsLoaded)
{ {
@@ -1023,6 +1029,9 @@ namespace FlaxEditor.Surface
/// <inheritdoc /> /// <inheritdoc />
public abstract IEnumerable<ScriptType> NewParameterTypes { get; } public abstract IEnumerable<ScriptType> NewParameterTypes { get; }
/// <inheritdoc />
public event Action SurfaceLoaded;
/// <inheritdoc /> /// <inheritdoc />
public virtual void OnParamRenameUndo() public virtual void OnParamRenameUndo()
{ {

View File

@@ -897,5 +897,19 @@ namespace FlaxEditor.Utilities
}; };
return menu; return menu;
} }
/// <summary>
/// Gets the asset name relative to the project root folder (without asset file extension)
/// </summary>
/// <param name="path">The asset path.</param>
/// <returns>The processed name path.</returns>
public static string GetAssetNamePath(string path)
{
if (path.StartsWith(Globals.ProjectFolder))
{
path = path.Substring(Globals.ProjectFolder.Length + 1);
}
return StringUtils.GetPathWithoutExtension(path);
}
} }
} }

View File

@@ -1322,6 +1322,7 @@ namespace FlaxEditor.Windows.Assets
_surface.ShowWholeGraph(); _surface.ShowWholeGraph();
} }
LoadBreakpoints(); LoadBreakpoints();
SurfaceLoaded?.Invoke();
Editor.VisualScriptingDebugFlow += OnDebugFlow; Editor.VisualScriptingDebugFlow += OnDebugFlow;
} }
else if (_refreshPropertiesOnLoad && _asset.IsLoaded) else if (_refreshPropertiesOnLoad && _asset.IsLoaded)
@@ -1381,6 +1382,9 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<ScriptType> NewParameterTypes => Editor.CodeEditing.VisualScriptPropertyTypes.Get(); public IEnumerable<ScriptType> NewParameterTypes => Editor.CodeEditing.VisualScriptPropertyTypes.Get();
/// <inheritdoc />
public event Action SurfaceLoaded;
/// <inheritdoc /> /// <inheritdoc />
public void OnParamRenameUndo() public void OnParamRenameUndo()
{ {

View File

@@ -220,7 +220,7 @@ namespace FlaxEditor.Windows
filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text); filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text);
} }
}; };
var sortBy = menu.AddChildMenu("Sort by"); var sortBy = menu.AddChildMenu("Sort by");
sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked).Tag = SortType.AlphabeticOrder; sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked).Tag = SortType.AlphabeticOrder;
sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked).Tag = SortType.AlphabeticReverse; sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked).Tag = SortType.AlphabeticReverse;
@@ -260,10 +260,12 @@ namespace FlaxEditor.Windows
{ {
switch ((SortType)button.Tag) switch ((SortType)button.Tag)
{ {
case SortType.AlphabeticOrder: _sortType = SortType.AlphabeticOrder; case SortType.AlphabeticOrder:
break; _sortType = SortType.AlphabeticOrder;
case SortType.AlphabeticReverse: _sortType = SortType.AlphabeticReverse; break;
break; case SortType.AlphabeticReverse:
_sortType = SortType.AlphabeticReverse;
break;
} }
RefreshView(SelectedNode); RefreshView(SelectedNode);
} }
@@ -446,14 +448,15 @@ namespace FlaxEditor.Windows
/// <param name="items">The items to delete.</param> /// <param name="items">The items to delete.</param>
public void Delete(List<ContentItem> items) public void Delete(List<ContentItem> 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` // 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<ContentItem>(items); var toDelete = new List<ContentItem>(items);
string msg = toDelete.Count == 1 ? 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}\'?\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.Format("Are you sure to delete {0} selected items?\nThis action cannot be undone. Files will be deleted permanently.", items.Count);
// Ask user // Ask user
if (MessageBox.Show(msg, "Delete asset(s)", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) 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; _navigateUpButton.Enabled = folder != null && _tree.SelectedNode != _root;
} }
private void AddFolder2Root(ContentTreeNode node)
{
// Add to the root
_root.AddChild(node);
}
private void RemoveFolder2Root(ContentTreeNode node) private void RemoveFolder2Root(ContentTreeNode node)
{ {
// Remove from the root // Remove from the root
@@ -790,7 +787,7 @@ namespace FlaxEditor.Windows
_root.Expand(true); _root.Expand(true);
foreach (var project in Editor.ContentDatabase.Projects) foreach (var project in Editor.ContentDatabase.Projects)
AddFolder2Root(project); _root.AddChild(project);
Editor.ContentDatabase.Game?.Expand(true); Editor.ContentDatabase.Game?.Expand(true);
_tree.Margin = new Margin(0.0f, 0.0f, -16.0f, 2.0f); // Hide root node _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) while (_root.HasChildren)
{ {
RemoveFolder2Root((ContentTreeNode)_root.GetChild(0)); _root.RemoveChild((ContentTreeNode)_root.GetChild(0));
} }
} }
} }