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.cpp44
1 files changed, 10 insertions, 34 deletions
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index 4f6e69e..7ebb9e1 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -130,41 +130,17 @@ std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind)
case Template::InvalidKind: return nullptr;
}
}
-
-struct DrawTemplateList_State
-{
- // Internal data
-
- // Items that are intended for user usage
- const TemplateInfo* SelectedTemplate = nullptr;
-};
-
-void DrawTemplateList(DrawTemplateList_State& state)
-{
- auto& gs = GlobalStates::GetInstance();
- auto& templates = gs.GetCurrentProject()->GetTemplates();
-
- for (auto& info : templates) {
- if (ImGui::Selectable(info.Name.c_str(), state.SelectedTemplate == &info)) {
- state.SelectedTemplate = &info;
- }
- if (ImGui::IsItemHovered()) {
- ImGui::BeginTooltip();
- ImGui::Text("Path: %s", info.PathStringCache.c_str());
- ImGui::EndTooltip();
- }
- }
-}
} // namespace
void UI::TemplatesTab()
{
auto ls = LocaleStrings::Instance.get();
auto& gs = GlobalStates::GetInstance();
+ auto& project = *gs.GetCurrentProject();
bool openedDummy = true;
static std::unique_ptr<TemplateUI> openTemplate;
- static DrawTemplateList_State state;
+ static AssetList::DrawState state;
// Toolbar item: close
if (ImGui::Button(ls->Close.Get(), openTemplate == nullptr)) {
@@ -177,11 +153,11 @@ void UI::TemplatesTab()
ImGui::OpenPopup("Open template");
}
if (ImGui::BeginPopupModal("Open template", &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
- DrawTemplateList(state);
+ project.Templates.DrawDetails(state);
- if (state.SelectedTemplate) {
- auto kind = state.SelectedTemplate->Kind;
- auto tmpl = state.SelectedTemplate->LoadFromDisk();
+ if (state.SelectedAsset) {
+ auto kind = state.SelectedAsset->Kind;
+ auto tmpl = state.SelectedAsset->LoadFromDisk();
openTemplate = TemplateUI::CreateByKind(kind, std::move(tmpl));
}
@@ -194,7 +170,7 @@ void UI::TemplatesTab()
ImGui::OpenPopup("Manage templates");
}
if (ImGui::BeginPopupModal("Manage templates", &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
- DrawTemplateList(state);
+ project.Templates.DrawDetails(state);
enum class NameSelectionError
{
@@ -257,8 +233,6 @@ void UI::TemplatesTab()
}
if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) {
- auto& project = *gs.GetCurrentProject();
-
project.InsertTemplate(
newName,
TemplateInfo{
@@ -280,6 +254,7 @@ void UI::TemplatesTab()
ImGui::EndPopup();
}
+ ImGui::SameLine();
if (ImGui::Button(ls->Rename.Get(), state.SelectedTemplate == nullptr)) {
ImGui::OpenPopup("Rename template");
newName.clear();
@@ -292,7 +267,7 @@ void UI::TemplatesTab()
if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) {
auto& project = *gs.GetCurrentProject();
- project.RenameTemplate(
+ project.Templates.Rename(
state.SelectedTemplate->Name,
newName);
@@ -309,6 +284,7 @@ void UI::TemplatesTab()
ImGui::EndPopup();
}
+ ImGui::SameLine();
if (ImGui::Button(ls->Delete.Get(), state.SelectedTemplate == nullptr)) {
ImGui::OpenPopup("Delete confirmation");
}