diff options
Diffstat (limited to 'core/src/UI')
-rw-r--r-- | core/src/UI/UI_Templates.cpp | 168 | ||||
-rw-r--r-- | core/src/UI/UI_Workflows.cpp | 107 |
2 files changed, 50 insertions, 225 deletions
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp index def50d9..d48e8bf 100644 --- a/core/src/UI/UI_Templates.cpp +++ b/core/src/UI/UI_Templates.cpp @@ -1,4 +1,4 @@ -#include "UI.hpp" +#include "UI.hpp" #include "Model/GlobalStates.hpp" #include "Model/Project.hpp" @@ -135,12 +135,18 @@ std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind) void UI::TemplatesTab() { auto ls = LocaleStrings::Instance.get(); - auto& gs = GlobalStates::GetInstance(); - auto& project = *gs.GetCurrentProject(); + auto& project = *GlobalStates::GetInstance().GetCurrentProject(); + + enum class PopupType + { + None, + TemplateSelect, + Management, + }; - bool openedDummy = true; static std::unique_ptr<TemplateUI> openTemplate; - static AssetList::ListState state; + static AssetList::PopupState popup; + static PopupType popupType = PopupType::None; // Toolbar item: close if (ImGui::Button(ls->Close.Get(), openTemplate == nullptr)) { @@ -150,153 +156,29 @@ void UI::TemplatesTab() // Toolbar item: open... ImGui::SameLine(); if (ImGui::Button("Open...")) { - ImGui::OpenPopup("Open template"); - } - if (ImGui::BeginPopupModal("Open template", &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { - project.Templates.DrawDetails(state); - - if (state.SelectedAsset) { - auto kind = static_cast<Template::Kind>(state.SelectedAsset->Payload); - auto tmpl = project.Templates.Load(*state.SelectedAsset); - openTemplate = TemplateUI::CreateByKind(kind, std::move(tmpl)); - } - - ImGui::EndPopup(); + project.Templates.OpenDetailsPopup(); + popupType = PopupType::TemplateSelect; } // Toolbar item: manage... ImGui::SameLine(); if (ImGui::Button("Manage...")) { - ImGui::OpenPopup("Manage templates"); + project.Templates.OpenDetailsPopup(); + popupType = PopupType::Management; } - if (ImGui::BeginPopupModal("Manage templates", &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { - project.Templates.DrawDetails(state); - - enum class NameSelectionError - { - None, - Duplicated, - Empty, - }; - - static std::string newName; - static NameSelectionError newNameError; - auto ValidateNewName = [&]() -> void { - if (newName.empty()) { - newNameError = NameSelectionError::Empty; - } - - if (project.Templates.FindByName(newName)) { - newNameError = NameSelectionError::Duplicated; - } - }; - auto ShowNewNameErrors = [&]() -> void { - switch (newNameError) { - case NameSelectionError::None: break; - case NameSelectionError::Duplicated: - ImGui::ErrorMessage("Duplicate template name"); - break; - case NameSelectionError::Empty: - ImGui::ErrorMessage("Template name cannot be empty"); - break; - } - }; - - static Template::Kind newKind = Template::InvalidKind; - auto ShowNewKindErrors = [&]() -> void { - if (newKind == Template::InvalidKind) { - ImGui::ErrorMessage("Must select a valid template type"); - } - }; - - auto IsInputValid = [&]() -> bool { - return newNameError == NameSelectionError::None && newKind != Template::InvalidKind; - }; - - if (ImGui::Button(ls->Add.Get())) { - ImGui::OpenPopup("Create template"); - } - if (ImGui::BeginPopupModal("Create template")) { - if (ImGui::InputText("Name", &newName)) { - ValidateNewName(); - } - - if (ImGui::BeginCombo("Type", Template::FormatKind(newKind))) { - for (int i = 0; i < Template::KindCount; ++i) { - auto kind = static_cast<Template::Kind>(i); - if (ImGui::Selectable(Template::FormatKind(kind), newKind == kind)) { - newKind = kind; - } - } - ImGui::EndCombo(); - } - - if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) { - project.Templates.Create(SavedAsset{ - .Name = newName, - .Payload = static_cast<uint64_t>(newKind), - }); - openTemplate = TemplateUI::CreateByKind(newKind); + switch (popupType) { + case PopupType::TemplateSelect: + if (ImGui::Button("Open", popup.SelectedAsset == nullptr)) { + auto kind = static_cast<Template::Kind>(popup.SelectedAsset->Payload); + openTemplate = TemplateUI::CreateByKind(kind); } - ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { - ImGui::CloseCurrentPopup(); - } - - ShowNewNameErrors(); - ShowNewKindErrors(); - - ImGui::EndPopup(); - } - - ImGui::SameLine(); - if (ImGui::Button(ls->Rename.Get(), state.SelectedAsset == nullptr)) { - ImGui::OpenPopup("Rename template"); - newName.clear(); - } - if (ImGui::BeginPopupModal("Rename template")) { - if (ImGui::InputText("New name", &newName)) { - ValidateNewName(); - } - - if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) { - auto tmpl = project.Templates.Rename( - state.SelectedAsset->Name, - 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())) { - ImGui::CloseCurrentPopup(); - } - - ShowNewNameErrors(); - - ImGui::EndPopup(); - } - - ImGui::SameLine(); - if (ImGui::Button(ls->Delete.Get(), state.SelectedAsset == nullptr)) { - ImGui::OpenPopup("Delete confirmation"); - } - if (ImGui::BeginPopupModal("Delete confirmation")) { - if (ImGui::Button(ls->DialogConfirm.Get())) { - auto& assetName = state.SelectedAsset->Name; - project.Templates.Remove(assetName); - - state.SelectedAsset = nullptr; - } - ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { - ImGui::CloseCurrentPopup(); - } - ImGui::EndPopup(); - } + project.Templates.DisplayDetailsPopup(popup); + break; - ImGui::EndPopup(); + default: + project.Templates.DisplayDetailsPopup(popup); + break; } if (openTemplate) { diff --git a/core/src/UI/UI_Workflows.cpp b/core/src/UI/UI_Workflows.cpp index 7b2de2a..3c23c30 100644 --- a/core/src/UI/UI_Workflows.cpp +++ b/core/src/UI/UI_Workflows.cpp @@ -363,12 +363,18 @@ public: void UI::WorkflowsTab() { auto ls = LocaleStrings::Instance.get(); - auto& gs = GlobalStates::GetInstance(); - auto& project = *gs.GetCurrentProject(); + auto& project = *GlobalStates::GetInstance().GetCurrentProject(); + + enum class PopupType + { + None, + WorkflowSelect, + Management, + }; - bool openedDummy = true; static std::unique_ptr<WorkflowUI> openWorkflow; - static AssetList::ListState state; + static AssetList::PopupState popup; + static PopupType popupType = PopupType::None; // Toolbar item: close if (ImGui::Button(ls->Close.Get(), openWorkflow == nullptr)) { @@ -378,93 +384,30 @@ void UI::WorkflowsTab() // Toolbar item: open... ImGui::SameLine(); if (ImGui::Button(ls->OpenWorkflow.Get())) { - ImGui::OpenPopup(ls->OpenWorkflowDialogTitle.Get()); - } - if (ImGui::BeginPopupModal(ls->OpenWorkflowDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { - project.Workflows.DrawDetails(state); - - if (state.SelectedAsset) { - auto workflow = project.Workflows.Load(*state.SelectedAsset); - openWorkflow = std::make_unique<WorkflowUI>(std::move(workflow)); - } - - ImGui::EndPopup(); + project.Workflows.OpenDetailsPopup(); + popupType = PopupType::WorkflowSelect; } // Toolbar item: manage... ImGui::SameLine(); if (ImGui::Button(ls->ManageWorkflows.Get())) { - ImGui::OpenPopup(ls->ManageWorkflowsDialogTitle.Get()); + project.Workflows.OpenDetailsPopup(); + popupType = PopupType::Management; } - if (ImGui::BeginPopupModal(ls->ManageWorkflowsDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { - project.Workflows.DrawDetails(state); - - enum class NameSelectionError - { - None, - Duplicated, - Empty, - }; - static std::string newName; - static NameSelectionError newNameError; - if (ImGui::Button(ls->Rename.Get(), state.SelectedAsset == nullptr)) { - ImGui::OpenPopup("Rename workflow"); - newName.clear(); - } - if (ImGui::BeginPopupModal("Rename workflow")) { - if (ImGui::InputText("New name", &newName)) { - if (newName.empty()) { - newNameError = NameSelectionError::Empty; - } - - if (project.Workflows.FindByName(newName)) { - newNameError = NameSelectionError::Duplicated; - } - } - - if (ImGui::Button(ls->DialogConfirm.Get(), newName.empty())) { - auto workflow = project.Workflows.Rename( - state.SelectedAsset->Name, - newName); - state.SelectedAsset = workflow; + project.Workflows.DisplayDetailsPopup(popup); + switch (popupType) { + case PopupType::WorkflowSelect: + if (ImGui::Button("Open", popup.SelectedAsset == nullptr)) { + auto workflow = project.Workflows.Load(*popup.SelectedAsset); + openWorkflow = std::make_unique<WorkflowUI>(std::move(workflow)); } - ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { - ImGui::CloseCurrentPopup(); - } - - switch (newNameError) { - case NameSelectionError::None: break; - case NameSelectionError::Duplicated: - ImGui::ErrorMessage("Duplicate workflow name"); - break; - case NameSelectionError::Empty: - ImGui::ErrorMessage("Workflow name cannot be empty"); - break; - } - - ImGui::EndPopup(); - } - - if (ImGui::Button(ls->Delete.Get(), state.SelectedAsset == nullptr)) { - ImGui::OpenPopup("Delete confirmation"); - } - if (ImGui::BeginPopupModal("Delete confirmation")) { - if (ImGui::Button(ls->DialogConfirm.Get())) { - auto& assetName = state.SelectedAsset->Name; - project.Workflows.Remove(assetName); - - state.SelectedAsset = nullptr; - } - ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { - ImGui::CloseCurrentPopup(); - } - ImGui::EndPopup(); - } + project.Workflows.DisplayDetailsPopup(popup); + break; - ImGui::EndPopup(); + default: + project.Workflows.DisplayDetailsPopup(popup); + break; } if (openWorkflow) { |