Allow separators in "Create new Asset" dropdown (also changed text to just "Create new")

This commit is contained in:
Simon Lübeß
2023-11-15 16:23:22 +01:00
parent 6f1467046d
commit d718c6625d
2 changed files with 25 additions and 1 deletions
@@ -45,7 +45,9 @@ namespace GlitchyEditor.EditWindows
private typealias AssetCreatorTree = TreeNode<(StringView Name, AssetCreator Creator)>; private typealias AssetCreatorTree = TreeNode<(StringView Name, AssetCreator Creator)>;
private AssetCreatorTree _creatorTree = new AssetCreatorTree(("Create new Asset", null)) ~ delete _; private AssetCreatorTree _creatorTree = new AssetCreatorTree(("Create new", null)) ~ delete _;
/// The last Asset Creator that was inserted.
private AssetCreatorTree _lastInsertedAssetCreator = null;
public const String s_WindowTitle = "Content Browser"; public const String s_WindowTitle = "Content Browser";
@@ -72,6 +74,7 @@ namespace GlitchyEditor.EditWindows
_manager = contentManager; _manager = contentManager;
} }
/// Registers an asset creator that will show up in the "Create new" drop down menu
public void RegisterAssetCreator(AssetCreator assetCreator) public void RegisterAssetCreator(AssetCreator assetCreator)
{ {
_assetCreators.Add(assetCreator); _assetCreators.Add(assetCreator);
@@ -92,6 +95,17 @@ namespace GlitchyEditor.EditWindows
{ {
tree->Creator = assetCreator; tree->Creator = assetCreator;
} }
_lastInsertedAssetCreator = tree;
}
/// Adds a seperator line after the asset creator that was last added.
public void InsertAssetCreatorSeparator()
{
AssetCreatorTree parent = _lastInsertedAssetCreator.Parent;
// Separators have an empty name and no creator!
parent.AddChild(("", null));
} }
protected override void InternalShow() protected override void InternalShow()
@@ -209,6 +223,14 @@ namespace GlitchyEditor.EditWindows
/// Shows the menu for the given asset creator tree. /// Shows the menu for the given asset creator tree.
private void ShowCreateContextMenu(AssetCreatorTree subtree) private void ShowCreateContextMenu(AssetCreatorTree subtree)
{ {
// Separators have an empty name and no creator
if (subtree->Name.IsWhiteSpace && subtree->Creator == null)
{
ImGui.Separator();
return;
}
if (subtree.Children.Count == 0) if (subtree.Children.Count == 0)
{ {
if (ImGui.MenuItem(subtree->Name.ToScopeCStr!())) if (ImGui.MenuItem(subtree->Name.ToScopeCStr!()))
+2
View File
@@ -152,6 +152,8 @@ namespace GlitchyEditor
} }
})); }));
Editor.Instance.ContentBrowserWindow.InsertAssetCreatorSeparator();
Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Scene", "New Scene", ".scene", new (path) => Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Scene", "New Scene", ".scene", new (path) =>
{ {
using (Scene newScene = CreateNewScene()) using (Scene newScene = CreateNewScene())