Lots of SzGui work
This commit is contained in:
68
SzGui/Windows/DatasetCreatorWindow.cs
Normal file
68
SzGui/Windows/DatasetCreatorWindow.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using ImGuiNET;
|
||||
using SzCore;
|
||||
using SzCore.DataObjects;
|
||||
|
||||
namespace SzGui.Windows;
|
||||
|
||||
public class DatasetCreatorWindow : SzGuiWindowBase
|
||||
{
|
||||
private string _datasetName = "";
|
||||
private int _selectedTemplateIndex = 0;
|
||||
private List<string> _templateIds = new();
|
||||
|
||||
public DatasetCreatorWindow()
|
||||
{
|
||||
WindowName = "Create New Dataset";
|
||||
RefreshTemplates();
|
||||
}
|
||||
|
||||
private void RefreshTemplates()
|
||||
{
|
||||
_ = SZ.DataHandler.LoadAllDataObjectTemplatesAsync();
|
||||
_templateIds = SZ.DataHandler.LoadedTemplates.Keys.ToList();
|
||||
}
|
||||
|
||||
protected override void RenderContent()
|
||||
{
|
||||
ImGui.InputText("Dataset Name", ref _datasetName, 128);
|
||||
|
||||
if (_templateIds.Count == 0)
|
||||
{
|
||||
ImGui.TextColored(new System.Numerics.Vector4(1, 0, 0, 1), "No templates loaded! Create a template first.");
|
||||
if (ImGui.Button("Refresh Template List")) RefreshTemplates();
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] items = _templateIds.ToArray();
|
||||
ImGui.Combo("Template", ref _selectedTemplateIndex, items, items.Length);
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.Button("Create Dataset", new System.Numerics.Vector2(0, 30)))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_datasetName))
|
||||
{
|
||||
ExecuteCreation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void ExecuteCreation()
|
||||
{
|
||||
string selectedId = _templateIds[_selectedTemplateIndex];
|
||||
|
||||
var result = await SZ.DataHandler.CreateDatasetAsync(_datasetName, selectedId);
|
||||
|
||||
if (result.IsSuccess && result.Value != null)
|
||||
{
|
||||
await SZ.DataHandler.SaveDatasetAsync(result.Value);
|
||||
|
||||
IsOpen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Error creating dataset: {result.Error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user