diff options
Diffstat (limited to 'core/src/Model')
-rw-r--r-- | core/src/Model/Assets.cpp | 113 | ||||
-rw-r--r-- | core/src/Model/Assets.hpp | 19 | ||||
-rw-r--r-- | core/src/Model/Template/Template.hpp | 2 | ||||
-rw-r--r-- | core/src/Model/Template/Template_Main.cpp | 22 | ||||
-rw-r--r-- | core/src/Model/Workflow/Workflow.hpp | 2 | ||||
-rw-r--r-- | core/src/Model/Workflow/Workflow_Main.cpp | 16 |
6 files changed, 73 insertions, 101 deletions
diff --git a/core/src/Model/Assets.cpp b/core/src/Model/Assets.cpp index 0e53537..ac3335a 100644 --- a/core/src/Model/Assets.cpp +++ b/core/src/Model/Assets.cpp @@ -81,6 +81,11 @@ void AssetList::Reload() }); } +int AssetList::GetCount() const +{ + return mPrivate->Assets.size(); +} + const SavedAsset* AssetList::FindByName(std::string_view name) const { auto iter = mPrivate->Assets.find(name); @@ -166,99 +171,46 @@ void AssetList::SetCacheSizeLimit(int limit) mPrivate->CacheSizeLimit = limit; } -void AssetList::DisplayBigIconsList(ListState& state) +void AssetList::DisplayIconsList(ListState& state) { // TODO } -void AssetList::DisplayDetailsTable(ListState& state) +void AssetList::DisplayDetailsList(ListState& state) { SetupDetailsTable("AssetDetailsTable"); for (auto& asset : mPrivate->Assets) { - DrawDetailsTableRow(state, asset); ImGui::TableNextRow(); + DrawDetailsTableRow(state, asset); } ImGui::EndTable(); } -void AssetList::OpenBigIconsPopup() -{ - ImGui::OpenPopup("Manage assets##BigIcons"); -} - -void AssetList::DisplayBigIconsPopup(PopupState& state) -{ - if (ImGui::BeginPopupModal("Manage assets##BigIcons")) { - DisplayBigIconsList(state); - DisplayPopupControls(state); - ImGui::EndPopup(); - } -} - -void AssetList::OpenDetailsPopup() -{ - ImGui::OpenPopup("Manage assets##Details"); -} - -void AssetList::DisplayDetailsPopup(PopupState& state) -{ - if (ImGui::BeginPopupModal("Manage assets##Details")) { - DisplayBigIconsList(state); - DisplayPopupControls(state); - ImGui::EndPopup(); - } -} - -void AssetList::DiscoverFilesByExtension(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, std::string_view extension) const -{ - for (auto entry : fs::directory_iterator(containerDir)) { - if (!entry.is_regular_file()) continue; - - // If the caller provided an extension to match against, and it doesn't equal to current file extension, skip - if (!extension.empty() && - entry.path().extension() != extension) - { - continue; - } - - callback(SavedAsset{ - .Name = RetrieveNameFromFile(entry.path()), - .Uuid = RetrieveUuidFromFile(entry.path()), - // TODO load payload - }); - } -} - -void AssetList::DiscoverFilesByHeader(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, const std::function<bool(std::istream&)>& validater) const -{ - // TODO -} - -void AssetList::DisplayPopupControls(PopupState& state) +void AssetList::DisplayControls(ListState& state) { auto& ps = mPrivate->PopupPrivateState; auto ls = LocaleStrings::Instance.get(); - bool openedDummy = false; + bool openedDummy = true; if (ImGui::Button(ls->Add.Get())) { - ImGui::OpenPopup("Create template"); + ImGui::OpenPopup(ls->AddDialogTitle.Get()); } - if (ImGui::BeginPopupModal("Create template", &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::BeginPopupModal(ls->AddDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { DisplayAssetCreator(state); ImGui::EndPopup(); } ImGui::SameLine(); if (ImGui::Button(ls->Rename.Get(), state.SelectedAsset == nullptr)) { - ImGui::OpenPopup("Rename template"); + ImGui::OpenPopup(ls->RenameDialogTitle.Get()); } - if (ImGui::BeginPopupModal("Rename template")) { + if (ImGui::BeginPopupModal(ls->RenameDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { if (ImGui::InputText("New name", &ps.NewName)) { ps.Validate(*this); } - if (ImGui::Button(ls->DialogConfirm.Get(), ps.HasErrors())) { + if (ImGui::Button(ls->Confirm.Get(), ps.HasErrors())) { ImGui::CloseCurrentPopup(); auto movedAsset = Rename(state.SelectedAsset->Name, ps.NewName); @@ -268,7 +220,7 @@ void AssetList::DisplayPopupControls(PopupState& state) ps = {}; } ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { + if (ImGui::Button(ls->Cancel.Get())) { ImGui::CloseCurrentPopup(); } @@ -279,10 +231,10 @@ void AssetList::DisplayPopupControls(PopupState& state) ImGui::SameLine(); if (ImGui::Button(ls->Delete.Get(), state.SelectedAsset == nullptr)) { - ImGui::OpenPopup("Delete confirmation"); + ImGui::OpenPopup(ls->DeleteDialogTitle.Get()); } - if (ImGui::BeginPopupModal("Delete confirmation")) { - if (ImGui::Button(ls->DialogConfirm.Get())) { + if (ImGui::BeginPopupModal(ls->DeleteDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::Button(ls->Confirm.Get())) { ImGui::CloseCurrentPopup(); auto& assetName = state.SelectedAsset->Name; @@ -291,9 +243,34 @@ void AssetList::DisplayPopupControls(PopupState& state) state.SelectedAsset = nullptr; } ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { + if (ImGui::Button(ls->Cancel.Get())) { ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); } } + +void AssetList::DiscoverFilesByExtension(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, std::string_view extension) const +{ + for (auto entry : fs::directory_iterator(containerDir)) { + if (!entry.is_regular_file()) continue; + + // If the caller provided an extension to match against, and it doesn't equal to current file extension, skip + if (!extension.empty() && + entry.path().extension() != extension) + { + continue; + } + + callback(SavedAsset{ + .Name = RetrieveNameFromFile(entry.path()), + .Uuid = RetrieveUuidFromFile(entry.path()), + // TODO load payload + }); + } +} + +void AssetList::DiscoverFilesByHeader(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, const std::function<bool(std::istream&)>& validater) const +{ + // TODO +} diff --git a/core/src/Model/Assets.hpp b/core/src/Model/Assets.hpp index e035f51..adde97b 100644 --- a/core/src/Model/Assets.hpp +++ b/core/src/Model/Assets.hpp @@ -48,6 +48,7 @@ public: // TODO support file watches void Reload(); + int GetCount() const; const SavedAsset* FindByName(std::string_view name) const; const SavedAsset& Create(SavedAsset asset); std::unique_ptr<Asset> CreateAndLoad(SavedAsset asset); @@ -66,16 +67,9 @@ public: { const SavedAsset* SelectedAsset = nullptr; }; - void DisplayBigIconsList(ListState& state); - void DisplayDetailsTable(ListState& state); - - struct PopupState : public ListState - { - }; - void OpenBigIconsPopup(); - void DisplayBigIconsPopup(PopupState& state); - void OpenDetailsPopup(); - void DisplayDetailsPopup(PopupState& state); + void DisplayIconsList(ListState& state); + void DisplayDetailsList(ListState& state); + void DisplayControls(ListState& state); protected: virtual void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const = 0; @@ -93,15 +87,12 @@ protected: virtual uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const = 0; virtual std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const = 0; - virtual void DisplayAssetCreator(PopupState& state) = 0; + virtual void DisplayAssetCreator(ListState& state) = 0; /// This should call ImGui::BeginTable() along with other accessories such as setting up the header row. virtual void SetupDetailsTable(const char* tableId) const = 0; virtual void DrawBigIcon(ListState& state, const SavedAsset& asset) const = 0; virtual void DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const = 0; - -private: - void DisplayPopupControls(PopupState& state); }; template <class T> diff --git a/core/src/Model/Template/Template.hpp b/core/src/Model/Template/Template.hpp index fdac574..7cfbb8b 100644 --- a/core/src/Model/Template/Template.hpp +++ b/core/src/Model/Template/Template.hpp @@ -64,7 +64,7 @@ protected: virtual Template* LoadImpl(const SavedAsset& diskForm) const override; - virtual void DisplayAssetCreator(PopupState& state) override; + virtual void DisplayAssetCreator(ListState& state) override; virtual void SetupDetailsTable(const char* tableId) const override; virtual void DrawBigIcon(ListState& state, const SavedAsset& asset) const override; diff --git a/core/src/Model/Template/Template_Main.cpp b/core/src/Model/Template/Template_Main.cpp index ebec490..7d1b755 100644 --- a/core/src/Model/Template/Template_Main.cpp +++ b/core/src/Model/Template/Template_Main.cpp @@ -89,7 +89,7 @@ Template* TemplateAssetList::LoadImpl(const SavedAsset& asset) const return tmpl.release(); } -void TemplateAssetList::DisplayAssetCreator(PopupState& state) +void TemplateAssetList::DisplayAssetCreator(ListState& state) { auto ls = LocaleStrings::Instance.get(); @@ -111,17 +111,17 @@ void TemplateAssetList::DisplayAssetCreator(PopupState& state) switch (mACNewNameError) { case NameSelectionError::None: break; case NameSelectionError::Duplicated: - ImGui::ErrorMessage("Duplicate template name"); + ImGui::ErrorMessage(ls->DuplicateNameError.Get()); break; case NameSelectionError::Empty: - ImGui::ErrorMessage("Template name cannot be empty"); + ImGui::ErrorMessage(ls->EmptyNameError.Get()); break; } }; auto ShowNewKindErrors = [&]() -> void { if (mACNewKind == Template::InvalidKind) { - ImGui::ErrorMessage("Must select a valid template type"); + ImGui::ErrorMessage(ls->InvalidTemplateTypeError.Get()); } }; @@ -136,11 +136,11 @@ void TemplateAssetList::DisplayAssetCreator(PopupState& state) ValidateNewName(); }; - if (ImGui::InputText("Name", &mACNewName)) { + if (ImGui::InputText(ls->Name.Get(), &mACNewName)) { ValidateNewName(); } - if (ImGui::BeginCombo("Type", Template::FormatKind(mACNewKind))) { + if (ImGui::BeginCombo(ls->Type.Get(), Template::FormatKind(mACNewKind))) { for (int i = 0; i < Template::KindCount; ++i) { auto kind = static_cast<Template::Kind>(i); if (ImGui::Selectable(Template::FormatKind(kind), mACNewKind == kind)) { @@ -153,7 +153,7 @@ void TemplateAssetList::DisplayAssetCreator(PopupState& state) ShowNewNameErrors(); ShowNewKindErrors(); - if (ImGui::Button(ls->DialogConfirm.Get(), !IsInputValid())) { + if (ImGui::Button(ls->Confirm.Get(), !IsInputValid())) { ImGui::CloseCurrentPopup(); Create(SavedAsset{ @@ -163,17 +163,19 @@ void TemplateAssetList::DisplayAssetCreator(PopupState& state) ResetState(); } ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { + if (ImGui::Button(ls->Cancel.Get())) { ImGui::CloseCurrentPopup(); } } void TemplateAssetList::SetupDetailsTable(const char* tableId) const { + auto ls = LocaleStrings::Instance.get(); + ImGui::BeginTable(tableId, 2, ImGuiTableFlags_Borders); - ImGui::TableSetupColumn("Name"); - ImGui::TableSetupColumn("Type"); + ImGui::TableSetupColumn(ls->Name.Get()); + ImGui::TableSetupColumn(ls->Type.Get()); ImGui::TableHeadersRow(); } diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp index 95dcafe..3dc6f38 100644 --- a/core/src/Model/Workflow/Workflow.hpp +++ b/core/src/Model/Workflow/Workflow.hpp @@ -294,7 +294,7 @@ public: virtual Workflow* LoadImpl(const SavedAsset& diskForm) const override; - virtual void DisplayAssetCreator(PopupState& state) override; + virtual void DisplayAssetCreator(ListState& state) override; virtual void SetupDetailsTable(const char* tableId) const override; virtual void DrawBigIcon(ListState& state, const SavedAsset& asset) const override; diff --git a/core/src/Model/Workflow/Workflow_Main.cpp b/core/src/Model/Workflow/Workflow_Main.cpp index 99c70a7..a01ab7b 100644 --- a/core/src/Model/Workflow/Workflow_Main.cpp +++ b/core/src/Model/Workflow/Workflow_Main.cpp @@ -802,7 +802,7 @@ Workflow* WorkflowAssetList::LoadImpl(const SavedAsset& asset) const return workflow.release(); } -void WorkflowAssetList::DisplayAssetCreator(PopupState& state) +void WorkflowAssetList::DisplayAssetCreator(ListState& state) { auto ls = LocaleStrings::Instance.get(); @@ -824,10 +824,10 @@ void WorkflowAssetList::DisplayAssetCreator(PopupState& state) switch (mACNewNameError) { case NameSelectionError::None: break; case NameSelectionError::Duplicated: - ImGui::ErrorMessage("Duplicate template name"); + ImGui::ErrorMessage(ls->DuplicateNameError.Get()); break; case NameSelectionError::Empty: - ImGui::ErrorMessage("Template name cannot be empty"); + ImGui::ErrorMessage(ls->EmptyNameError.Get()); break; } }; @@ -841,13 +841,13 @@ void WorkflowAssetList::DisplayAssetCreator(PopupState& state) ValidateNewName(); }; - if (ImGui::InputText("Name", &mACNewName)) { + if (ImGui::InputText(ls->Name.Get(), &mACNewName)) { ValidateNewName(); } ShowNewNameErrors(); - if (ImGui::Button(ls->DialogConfirm.Get(), !IsInputValid())) { + if (ImGui::Button(ls->Confirm.Get(), !IsInputValid())) { ImGui::CloseCurrentPopup(); Create(SavedAsset{ @@ -856,16 +856,18 @@ void WorkflowAssetList::DisplayAssetCreator(PopupState& state) ResetState(); } ImGui::SameLine(); - if (ImGui::Button(ls->DialogCancel.Get())) { + if (ImGui::Button(ls->Cancel.Get())) { ImGui::CloseCurrentPopup(); } } void WorkflowAssetList::SetupDetailsTable(const char* tableId) const { + auto ls = LocaleStrings::Instance.get(); + ImGui::BeginTable(tableId, 1, ImGuiTableFlags_Borders); - ImGui::TableSetupColumn("Name"); + ImGui::TableSetupColumn(ls->Name.Get()); ImGui::TableHeadersRow(); } |