public static void LoadCurrent() { if (files.Length == 0) { return; } try { ImGuiHelper.ClearNodes(); var name = files[current]; LoadFromRoot(name, JsonValue.Parse(FileHandle.FromRoot($"Dialogs/{name}.json").ReadAll())); } catch (Exception e) { Log.Error(e); } }
public static void Destroy() { SaveDialogs(); ImGuiHelper.ClearNodes(); }
public static void Render() { if (ImGuiHelper.BeforeRender()) { ImGui.PushItemWidth(-1); var old = current; if (ImGui.Combo("##file", ref current, files, files.Length)) { var o = current; current = old; SaveDialogs(); current = o; LoadCurrent(); } ImGui.PopItemWidth(); if (ImGui.Button("Save")) { SaveDialogs(); } ImGui.SameLine(); if (ImGui.Button("Delete")) { ImGui.OpenPopup("Delete?"); } if (ImGui.BeginPopupModal("Delete?")) { ImGui.Text("This operation can't be undone!"); ImGui.Text("Are you sure?"); if (ImGui.Button("Yes")) { ImGui.CloseCurrentPopup(); var list = files.ToList(); var s = files[current]; try { var file = FileHandle.FromRoot($"Dialogs/{s}.json"); file.Delete(); } catch (Exception e) { Log.Error(e); } list.RemoveAt(current); files = list.ToArray(); current = 0; LoadCurrent(); } ImGui.SameLine(); ImGui.SetItemDefaultFocus(); if (ImGui.Button("No")) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } ImGui.SameLine(); if (ImGui.Button("New")) { ImGui.OpenPopup("New tree"); } if (ImGui.BeginPopupModal("New tree")) { ImGui.SetItemDefaultFocus(); var input = ImGui.InputText("Name", ref newName, 64, ImGuiInputTextFlags.EnterReturnsTrue); var button = ImGui.Button("Create"); ImGui.SameLine(); if (ImGui.Button("Cancel")) { ImGui.CloseCurrentPopup(); newName = ""; } else { if (input || button) { var list = files.ToList(); list.Add(newName); files = list.ToArray(); current = list.Count - 1; newName = ""; SaveDialogs(); LoadCurrent(); ImGuiHelper.ClearNodes(); ImGui.CloseCurrentPopup(); } } ImGui.EndPopup(); } ImGui.Separator(); ImGuiHelper.RenderNodes(); } }