44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using ImGuiNET;
|
|
using SzCore;
|
|
using SzCore.DataObjects;
|
|
using SzGui.Windows;
|
|
|
|
public class NewObjectModal : SzGuiWindowBase
|
|
{
|
|
private readonly SzDataset _dataset;
|
|
private string _objName = "";
|
|
|
|
public NewObjectModal(SzDataset dataset)
|
|
{
|
|
_dataset = dataset;
|
|
WindowName = $"Add Object to {dataset.Name}";
|
|
}
|
|
|
|
protected override void RenderContent()
|
|
{
|
|
ImGui.Text($"Creating object for template: {_dataset.DataObjectTemplateId}");
|
|
ImGui.InputText("Object Name", ref _objName, 64);
|
|
|
|
if (ImGui.Button("Create", new System.Numerics.Vector2(100, 0)))
|
|
{
|
|
Create();
|
|
}
|
|
}
|
|
|
|
private async void Create()
|
|
{
|
|
var templateResult = await SZ.DataHandler.LoadTemplateAsync<SzDataObjectTemplate>(_dataset.DataObjectTemplateId);
|
|
|
|
if (templateResult.IsSuccess)
|
|
{
|
|
var objResult = SZ.DataHandler.CreateDataObject(templateResult.Value!, _objName);
|
|
|
|
if (objResult.IsSuccess)
|
|
{
|
|
_dataset.DataObjects.Add(objResult.Value!.Id, objResult.Value);
|
|
await SZ.DataHandler.SaveDatasetAsync(_dataset);
|
|
IsOpen = false;
|
|
}
|
|
}
|
|
}
|
|
} |