From 64a6dbcfdb89a5f57d93d47a2be0c741dda4662d Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sun, 15 Aug 2021 09:17:02 -0700 Subject: Fix issues and cleanup - Fix compile error on MSVC where is not included properly - Fix creating a workflow actually saves to the templates/ directory - Fix renaming assets are not saved to disk - TODO ser/deser still not working - Cleanup AssetList::* pure virtual setup (fewer splits) --- core/src/Model/Template/TableTemplate.hpp | 11 ++-- core/src/Model/Template/Template.hpp | 25 ++++----- core/src/Model/Template/Template_Main.cpp | 90 ++++++++++++++++++++----------- 3 files changed, 76 insertions(+), 50 deletions(-) (limited to 'core/src/Model/Template') diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp index 141e952..c651ce1 100644 --- a/core/src/Model/Template/TableTemplate.hpp +++ b/core/src/Model/Template/TableTemplate.hpp @@ -43,7 +43,7 @@ public: TextAlignment HorizontalAlignment = AlignCenter; TextAlignment VerticalAlignment = AlignCenter; CellType Type = ConstantCell; - /// The id of the group description object, if this cell isn't a constant or singluar parameter cell. Otherwise, this value is -1. + /// The id of the group description object, if this cell isn't a constant or singular parameter cell. Otherwise, this value is -1. int DataId = -1; public: @@ -57,11 +57,12 @@ public: // TODO support reverse (bottom to top) filling order // TODO support horizontal filling order -/// Parameter group information for a grouped array of cells. When instanciated, an array of 0 or more + +/// Parameter group information for a grouped array of cells. When instantiated, an array of 0 or more /// elements shall be provided by the user, which will replace the group of templated cells with a list /// of rows, each instantiated with the n-th element in the provided array. /// \code -/// [["foo", "bar", "foobar"], +/// [["foo", "bar", "foobar"], /// ["a", "b", c"], /// ["1", "2", "3"], /// ["x", "y", "z"]] @@ -210,6 +211,6 @@ public: lxw_workbook* InstantiateToExcelWorkbook(const TableInstantiationParameters& params) const; lxw_worksheet* InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstantiationParameters& params) const; - virtual ReadResult ReadFrom(std::istream& stream) override; - virtual void WriteTo(std::ostream& stream) const override; + ReadResult ReadFrom(std::istream& stream) override; + void WriteTo(std::ostream& stream) const override; }; diff --git a/core/src/Model/Template/Template.hpp b/core/src/Model/Template/Template.hpp index 7d43130..30fdc75 100644 --- a/core/src/Model/Template/Template.hpp +++ b/core/src/Model/Template/Template.hpp @@ -31,7 +31,7 @@ public: static bool IsInstance(const Template* tmpl); Template(Kind kind); - virtual ~Template() = default; + ~Template() override = default; Kind GetKind() const; @@ -57,20 +57,17 @@ public: using AssetListTyped::AssetListTyped; protected: - virtual void DiscoverFiles(const std::function& callback) const override; + void DiscoverFiles(const std::function& callback) const override; - virtual std::string RetrieveNameFromFile(const std::filesystem::path& file) const override; - virtual uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override; - virtual std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override; + std::string RetrieveNameFromFile(const std::filesystem::path& file) const override; + uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override; + std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override; - virtual void SaveEmptyInstance(const SavedAsset& asset) const override; - virtual Template* CreateEmptyInstance(const SavedAsset& diskForm) const override; + bool SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const override; + Template* LoadInstance(const SavedAsset& assetInfo) const override; + Template* CreateInstance(const SavedAsset& assetInfo) const override; + bool RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const override; - virtual Template* LoadImpl(const SavedAsset& diskForm) const 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; - virtual void DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const override; + void DisplayAssetCreator(ListState& state) override; + void DisplayDetailsTable(ListState& state) const override; }; diff --git a/core/src/Model/Template/Template_Main.cpp b/core/src/Model/Template/Template_Main.cpp index a681c4a..19803aa 100644 --- a/core/src/Model/Template/Template_Main.cpp +++ b/core/src/Model/Template/Template_Main.cpp @@ -2,8 +2,8 @@ #include "Model/GlobalStates.hpp" #include "Model/Project.hpp" -#include "Utils/I18n.hpp" #include "UI/UI.hpp" +#include "Utils/I18n.hpp" #include "Utils/UUID.hpp" #include @@ -57,28 +57,33 @@ fs::path TemplateAssetList::RetrievePathFromAsset(const SavedAsset& asset) const return GetConnectedProject().GetTemplatePath(fileName); } -void TemplateAssetList::SaveEmptyInstance(const SavedAsset& asset) const +bool TemplateAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const { - auto path = RetrievePathFromAsset(asset); + auto path = RetrievePathFromAsset(assetInfo); - std::ofstream ofs(path); - if (!ofs) return; - ofs << (uint64_t)asset.Name.size(); - ofs << asset.Name; - ofs << static_cast(asset.Payload); -} + std::ofstream ofs(path, std::ios::binary); + if (!ofs) return false; + ofs << (uint64_t)assetInfo.Name.size(); + ofs << assetInfo.Name; + ofs << static_cast(assetInfo.Payload); -Template* TemplateAssetList::CreateEmptyInstance(const SavedAsset& asset) const -{ - auto kind = static_cast(asset.Payload); - return Template::CreateByKind(kind).release(); + if (auto tmpl = static_cast(asset)) { + tmpl->WriteTo(ofs); + } + + return true; } -Template* TemplateAssetList::LoadImpl(const SavedAsset& asset) const +static std::unique_ptr