diff options
author | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
commit | 7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch) | |
tree | e95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Model/GlobalStates.hpp | |
parent | 2cf952088d375ac8b2f45b144462af0953436cff (diff) |
Restructure project
Diffstat (limited to 'app/source/Cplt/Model/GlobalStates.hpp')
-rw-r--r-- | app/source/Cplt/Model/GlobalStates.hpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/app/source/Cplt/Model/GlobalStates.hpp b/app/source/Cplt/Model/GlobalStates.hpp new file mode 100644 index 0000000..1eb47fb --- /dev/null +++ b/app/source/Cplt/Model/GlobalStates.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include <Cplt/Utils/Sigslot.hpp> +#include <Cplt/fwd.hpp> + +#include <filesystem> +#include <string> +#include <vector> + +class GlobalStates +{ +public: + static void Init(); + static void Init(std::filesystem::path userDataDir); + static void Shutdown(); + + static GlobalStates& GetInstance(); + static const std::filesystem::path& GetUserDataPath(); + + struct RecentProject + { + std::filesystem::path Path; + std::string CachedUtf8String; + }; + +public: + Signal<> OnModified; + +private: + std::vector<RecentProject> mRecentProjects; + std::unique_ptr<Project> mCurrentProject; + mutable bool mDirty = false; + +public: + const std::vector<RecentProject>& GetRecentProjects() const; + void ClearRecentProjects(); + void AddRecentProject(const Project& project); + /// Move or add the project to end of the recent projects list. + /// If the project is not in the list of recently used projects, it will be appended, otherwise + /// it will be moved to the end. + void MoveProjectToTop(const Project& project); + void RemoveRecentProject(int idx); + + bool HasCurrentProject() const; + Project* GetCurrentProject() const; + void SetCurrentProject(std::unique_ptr<Project> project); + + // TODO async autosaving to prevent data loss on crash + void WriteToDisk() const; + + bool IsDirty() const; + +private: + void MarkDirty(); +}; |