diff --git a/include/helpers/project_file_handler.hpp b/include/helpers/project_file_handler.hpp index 58f581d58..a80a80dd1 100644 --- a/include/helpers/project_file_handler.hpp +++ b/include/helpers/project_file_handler.hpp @@ -6,6 +6,9 @@ #include "patches.hpp" #include +#include + +#include namespace hex { @@ -16,25 +19,73 @@ namespace hex { static bool load(std::string_view filePath); static bool store(std::string_view filePath = ""); - [[nodiscard]] static bool hasUnsavedChanges() { return ProjectFile::s_hasUnsavedChanged; } - static void markDirty() { if (!ProjectFile::s_currProjectFilePath.empty()) ProjectFile::s_hasUnsavedChanged = true; } + [[nodiscard]] static bool hasUnsavedChanges() { + return ProjectFile::s_hasUnsavedChanged; + } - [[nodiscard]] static std::string getProjectFilePath() { return ProjectFile::s_currProjectFilePath; } + static void markDirty() { + bool setWindowTitle = !hasUnsavedChanges(); - [[nodiscard]] static std::string getFilePath() { return ProjectFile::s_filePath; } - static void setFilePath(std::string_view filePath) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_filePath = filePath; } + ProjectFile::s_hasUnsavedChanged = true; - [[nodiscard]] static std::string getPattern() { return ProjectFile::s_pattern; } - static void setPattern(std::string_view pattern) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_pattern = pattern; } + if (setWindowTitle) + EventManager::post(std::filesystem::path(getFilePath()).filename().string()); + } - [[nodiscard]] static const Patches& getPatches() { return ProjectFile::s_patches; } - static void setPatches(const Patches &patches) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_patches = patches; } + [[nodiscard]] static std::string getProjectFilePath() { + return ProjectFile::s_currProjectFilePath; + } - [[nodiscard]] static const std::list& getBookmarks() { return ProjectFile::s_bookmarks; } - static void setBookmarks(const std::list &bookmarks) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_bookmarks = bookmarks; } - [[nodiscard]] static const std::string_view getDataProcessorContent() { return ProjectFile::s_dataProcessorContent; } - static void setDataProcessorContent(std::string_view json) { ProjectFile::s_dataProcessorContent = json; } + [[nodiscard]] static std::string getFilePath() { + return ProjectFile::s_filePath; + } + + static void setFilePath(std::string_view filePath) { + ProjectFile::s_filePath = filePath; + + EventManager::post(std::filesystem::path(filePath).filename().string()); + } + + + [[nodiscard]] static std::string getPattern() { + return ProjectFile::s_pattern; + } + + static void setPattern(std::string_view pattern) { + markDirty(); + ProjectFile::s_pattern = pattern; + } + + + [[nodiscard]] static const Patches& getPatches() { + return ProjectFile::s_patches; + } + + static void setPatches(const Patches &patches) { + markDirty(); + ProjectFile::s_patches = patches; + } + + + [[nodiscard]] static const std::list& getBookmarks() { + return ProjectFile::s_bookmarks; + } + + static void setBookmarks(const std::list &bookmarks) { + markDirty(); + ProjectFile::s_bookmarks = bookmarks; + } + + + [[nodiscard]] static const std::string_view getDataProcessorContent() { + return ProjectFile::s_dataProcessorContent; + } + + static void setDataProcessorContent(std::string_view json) { + markDirty(); + ProjectFile::s_dataProcessorContent = json; + } private: static inline std::string s_currProjectFilePath; diff --git a/source/helpers/project_file_handler.cpp b/source/helpers/project_file_handler.cpp index bbaf7333c..dab4a0374 100644 --- a/source/helpers/project_file_handler.cpp +++ b/source/helpers/project_file_handler.cpp @@ -57,7 +57,7 @@ namespace hex { } bool ProjectFile::store(std::string_view filePath) { - ProjectFile::s_hasUnsavedChanged = false; + EventManager::post(); json projectFileData; @@ -82,6 +82,7 @@ namespace hex { return false; } + ProjectFile::s_hasUnsavedChanged = false; ProjectFile::s_currProjectFilePath = filePath; return true; diff --git a/source/views/view_data_processor.cpp b/source/views/view_data_processor.cpp index 0817faec5..97b7c303d 100644 --- a/source/views/view_data_processor.cpp +++ b/source/views/view_data_processor.cpp @@ -70,6 +70,8 @@ namespace hex { } this->m_links.erase(link); + + ProjectFile::markDirty(); } void ViewDataProcessor::eraseNodes(const std::vector &ids) { @@ -95,6 +97,8 @@ namespace hex { this->m_nodes.erase(node); } + + ProjectFile::markDirty(); } void ViewDataProcessor::processNodes() { @@ -181,11 +185,13 @@ namespace hex { } else if (unlocalizedCategory.empty()) { if (ImGui::MenuItem(LangEntry(unlocalizedName))) { node = function(); + ProjectFile::markDirty(); } } else { if (ImGui::BeginMenu(LangEntry(unlocalizedCategory))) { if (ImGui::MenuItem(LangEntry(unlocalizedName))) { node = function(); + ProjectFile::markDirty(); } ImGui::EndMenu(); } diff --git a/source/window.cpp b/source/window.cpp index 4ab026ae3..5f411da85 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -19,11 +19,14 @@ #include #include #include +#include +#include #include #include #include "helpers/plugin_manager.hpp" +#include "helpers/project_file_handler.hpp" #include "init/tasks.hpp" #include