aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI/UI_Templates.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/UI/UI_Templates.cpp')
-rw-r--r--core/src/UI/UI_Templates.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index 7ebb9e1..def50d9 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -140,7 +140,7 @@ void UI::TemplatesTab()
bool openedDummy = true;
static std::unique_ptr<TemplateUI> openTemplate;
- static AssetList::DrawState state;
+ static AssetList::ListState state;
// Toolbar item: close
if (ImGui::Button(ls->Close.Get(), openTemplate == nullptr)) {
@@ -156,8 +156,8 @@ void UI::TemplatesTab()
project.Templates.DrawDetails(state);
if (state.SelectedAsset) {
- auto kind = state.SelectedAsset->Kind;
- auto tmpl = state.SelectedAsset->LoadFromDisk();
+ auto kind = static_cast<Template::Kind>(state.SelectedAsset->Payload);
+ auto tmpl = project.Templates.Load(*state.SelectedAsset);
openTemplate = TemplateUI::CreateByKind(kind, std::move(tmpl));
}
@@ -186,8 +186,7 @@ void UI::TemplatesTab()
newNameError = NameSelectionError::Empty;
}
- auto& templates = gs.GetCurrentProject()->GetTemplates();
- if (templates.find(newName) != templates.end()) {
+ if (project.Templates.FindByName(newName)) {
newNameError = NameSelectionError::Duplicated;
}
};
@@ -233,13 +232,10 @@ void UI::TemplatesTab()
}
if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) {
- project.InsertTemplate(
- newName,
- TemplateInfo{
- .Path = project.GetTemplatePath(newName),
- .Name = newName, // Don't std::move here because evaluation order of `newName` (as parameter of InsertTemplate()) and this is unspecified
- .Kind = newKind,
- });
+ project.Templates.Create(SavedAsset{
+ .Name = newName,
+ .Payload = static_cast<uint64_t>(newKind),
+ });
openTemplate = TemplateUI::CreateByKind(newKind);
}
@@ -255,7 +251,7 @@ void UI::TemplatesTab()
}
ImGui::SameLine();
- if (ImGui::Button(ls->Rename.Get(), state.SelectedTemplate == nullptr)) {
+ if (ImGui::Button(ls->Rename.Get(), state.SelectedAsset == nullptr)) {
ImGui::OpenPopup("Rename template");
newName.clear();
}
@@ -265,14 +261,12 @@ void UI::TemplatesTab()
}
if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) {
- auto& project = *gs.GetCurrentProject();
-
- project.Templates.Rename(
- state.SelectedTemplate->Name,
+ auto tmpl = project.Templates.Rename(
+ state.SelectedAsset->Name,
newName);
- // We mutated the map, the pointer may be invalid now
- state.SelectedTemplate = &project.GetTemplates().at(newName);
+ // Update the selected pointer to the new location (we mutated the map, the pointer may be invalid now)
+ state.SelectedAsset = tmpl;
}
ImGui::SameLine();
if (ImGui::Button(ls->DialogCancel.Get())) {
@@ -285,14 +279,15 @@ void UI::TemplatesTab()
}
ImGui::SameLine();
- if (ImGui::Button(ls->Delete.Get(), state.SelectedTemplate == nullptr)) {
+ if (ImGui::Button(ls->Delete.Get(), state.SelectedAsset == nullptr)) {
ImGui::OpenPopup("Delete confirmation");
}
if (ImGui::BeginPopupModal("Delete confirmation")) {
- assert(state.SelectedTemplate != nullptr);
-
if (ImGui::Button(ls->DialogConfirm.Get())) {
- gs.GetCurrentProject()->RemoveTemplate(state.SelectedTemplate->Name);
+ auto& assetName = state.SelectedAsset->Name;
+ project.Templates.Remove(assetName);
+
+ state.SelectedAsset = nullptr;
}
ImGui::SameLine();
if (ImGui::Button(ls->DialogCancel.Get())) {