ScriptCore: Open newly created dictionary entry

This commit is contained in:
Simon Lübeß
2024-01-06 13:16:36 +01:00
parent 5d9973a791
commit 31e7edcc9c
+9 -8
View File
@@ -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");