From 31e7edcc9cf428bba4ba9bb9e10fb9e9359dfe33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 6 Jan 2024 13:16:36 +0100 Subject: [PATCH] ScriptCore: Open newly created dictionary entry --- ScriptCore/Editor/DictionaryEditor.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ScriptCore/Editor/DictionaryEditor.cs b/ScriptCore/Editor/DictionaryEditor.cs index 767bd9d..61c3934 100644 --- a/ScriptCore/Editor/DictionaryEditor.cs +++ b/ScriptCore/Editor/DictionaryEditor.cs @@ -13,6 +13,7 @@ public class DictionaryEditor { private static object? dictionaryForNewValue = null; private static DictionaryEntry newDictionaryValue = new(); + private static object? keyLastCreated = null; public static object? ShowEditor(object? reference, Type fieldType, string fieldName) { @@ -47,14 +48,6 @@ public class DictionaryEditor dictionaryForNewValue = dictionary; - // TODO: show fake entry! - - //object? newKey = ActivatorExtension.CreateInstanceSafe(keyType); - //object? newValue = ActivatorExtension.CreateInstanceSafe(valueType); - - //if (newKey != null) - // dictionary!.Add(newKey, newValue); - newDictionaryValue = new DictionaryEntry(); } @@ -74,6 +67,13 @@ public class DictionaryEditor id++; ImGui.PushID(id); + if (entry.Key == keyLastCreated) + { + // The current key is the one that was last created. Open the tree node. + ImGui.SetNextItemOpen(true); + keyLastCreated = null; + } + bool isEntryOpen = ImGui.TreeNode(""); ImGui.SameLine(ImGui.GetWindowContentRegionMax().X - removeButtonWidth); @@ -136,6 +136,7 @@ public class DictionaryEditor newEntries.Add(new DictionaryEntry(newKey, newDictionaryValue.Value)); dictionaryForNewValue = null; newDictionaryValue = new(); + keyLastCreated = newKey; } object newValue = EntityEditor.ShowFieldEditor(newDictionaryValue.Value, newDictionaryValue.Value?.GetType() ?? valueType, "Value");