126 lines
4.2 KiB
C#
126 lines
4.2 KiB
C#
using ImGuiNET;
|
|
using SzCore;
|
|
using SzCore.DataObjects;
|
|
|
|
namespace SzGui.Windows;
|
|
|
|
public class SzLibraryWindow : SzGuiWindowBase
|
|
{
|
|
public SzLibraryWindow()
|
|
{
|
|
WindowName = "SZ Library";
|
|
RefreshData();
|
|
}
|
|
|
|
private Dictionary<string, SzDataset> _loadedDatasets = [];
|
|
private Dictionary<string, SzDataObjectTemplate> _loadedDataObjectTemplates = [];
|
|
|
|
private async void RefreshData()
|
|
{
|
|
await SZ.DataHandler.LoadAllDatasetsAsync();
|
|
await SZ.DataHandler.LoadAllDataObjectTemplatesAsync();
|
|
|
|
_loadedDatasets = SZ.DataHandler.LoadedDatasets;
|
|
_loadedDataObjectTemplates = SZ.DataHandler.LoadedTemplates.Values
|
|
.OfType<SzDataObjectTemplate>()
|
|
.ToDictionary(t => t.Id, t => t);
|
|
}
|
|
|
|
protected override void RenderContent()
|
|
{
|
|
if (ImGui.BeginMenuBar())
|
|
{
|
|
if (ImGui.BeginMenu("Create"))
|
|
{
|
|
if (ImGui.MenuItem("New Template"))
|
|
{
|
|
SzApp.AppInstance.ActivateWindow(new SzTemplateCreatorWindow());
|
|
}
|
|
|
|
if (ImGui.MenuItem("New Dataset"))
|
|
{
|
|
SzApp.AppInstance.ActivateWindow(new DatasetCreatorWindow());
|
|
}
|
|
ImGui.EndMenu();
|
|
}
|
|
|
|
if (ImGui.MenuItem("Refresh"))
|
|
{
|
|
RefreshData();
|
|
}
|
|
|
|
ImGui.EndMenuBar();
|
|
}
|
|
|
|
if (ImGui.CollapsingHeader("Data Object Templates", ImGuiTreeNodeFlags.DefaultOpen))
|
|
{
|
|
if (ImGui.BeginTable("DataObjectTemplatesTable", 2, ImGuiTableFlags.Borders | ImGuiTableFlags.RowBg))
|
|
{
|
|
ImGui.TableSetupColumn("Template ID", ImGuiTableColumnFlags.WidthStretch);
|
|
ImGui.TableSetupColumn("Actions", ImGuiTableColumnFlags.WidthFixed, 120);
|
|
ImGui.TableHeadersRow();
|
|
|
|
foreach (var template in _loadedDataObjectTemplates)
|
|
{
|
|
ImGui.TableNextRow();
|
|
ImGui.TableNextColumn();
|
|
ImGui.TextUnformatted(template.Key);
|
|
|
|
ImGui.TableNextColumn();
|
|
|
|
if (ImGui.SmallButton($"Edit##T_{template.Key}"))
|
|
{
|
|
SzApp.AppInstance.ActivateWindow(new SzDataObjectTemplateEditorWindow(template.Value));
|
|
}
|
|
|
|
ImGui.SameLine();
|
|
|
|
if (ImGui.SmallButton($"Delete##T_{template.Key}"))
|
|
{
|
|
_ = Task.Run(async () => {
|
|
await SZ.DataHandler.DeleteTemplateAsync(template.Key);
|
|
RefreshData();
|
|
});
|
|
}
|
|
}
|
|
ImGui.EndTable();
|
|
}
|
|
}
|
|
|
|
ImGui.Spacing();
|
|
|
|
if (ImGui.CollapsingHeader("Datasets", ImGuiTreeNodeFlags.DefaultOpen))
|
|
{
|
|
if (ImGui.BeginTable("DatasetsTable", 2, ImGuiTableFlags.Borders | ImGuiTableFlags.RowBg))
|
|
{
|
|
ImGui.TableSetupColumn("Dataset Name", ImGuiTableColumnFlags.WidthStretch);
|
|
ImGui.TableSetupColumn("Actions", ImGuiTableColumnFlags.WidthFixed, 120);
|
|
ImGui.TableHeadersRow();
|
|
|
|
foreach (var datasetEntry in _loadedDatasets)
|
|
{
|
|
var dataset = datasetEntry.Value;
|
|
ImGui.TableNextRow();
|
|
|
|
ImGui.TableNextColumn();
|
|
ImGui.TextUnformatted(dataset.Name);
|
|
|
|
ImGui.TableNextColumn();
|
|
if (ImGui.SmallButton($"Open##{dataset.Id}"))
|
|
{
|
|
SzApp.AppInstance.ActivateWindow(new SzDatasetViewerWindow(dataset));
|
|
}
|
|
ImGui.SameLine();
|
|
if (ImGui.SmallButton($"Delete##{dataset.Id}"))
|
|
{
|
|
_ = Task.Run(async () => {
|
|
await SZ.DataHandler.DeleteDatasetAsync(dataset.Id);
|
|
RefreshData();
|
|
});
|
|
}
|
|
}
|
|
ImGui.EndTable();
|
|
}
|
|
}
|
|
}
|
|
} |