1
0
mirror of synced 2025-01-29 19:17:28 +01:00

sys: Fixed file modification detection

This commit is contained in:
WerWolv 2021-08-17 13:41:19 +02:00
parent 218f284678
commit 551da69a4c
4 changed files with 75 additions and 14 deletions

View File

@ -6,6 +6,9 @@
#include "patches.hpp" #include "patches.hpp"
#include <hex/api/imhex_api.hpp> #include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <filesystem>
namespace hex { namespace hex {
@ -16,25 +19,73 @@ namespace hex {
static bool load(std::string_view filePath); static bool load(std::string_view filePath);
static bool store(std::string_view filePath = ""); static bool store(std::string_view filePath = "");
[[nodiscard]] static bool hasUnsavedChanges() { return ProjectFile::s_hasUnsavedChanged; } [[nodiscard]] static bool hasUnsavedChanges() {
static void markDirty() { if (!ProjectFile::s_currProjectFilePath.empty()) ProjectFile::s_hasUnsavedChanged = true; } 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; } ProjectFile::s_hasUnsavedChanged = true;
static void setFilePath(std::string_view filePath) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_filePath = filePath; }
[[nodiscard]] static std::string getPattern() { return ProjectFile::s_pattern; } if (setWindowTitle)
static void setPattern(std::string_view pattern) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_pattern = pattern; } EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(getFilePath()).filename().string());
}
[[nodiscard]] static const Patches& getPatches() { return ProjectFile::s_patches; } [[nodiscard]] static std::string getProjectFilePath() {
static void setPatches(const Patches &patches) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_patches = patches; } return ProjectFile::s_currProjectFilePath;
}
[[nodiscard]] static const std::list<ImHexApi::Bookmarks::Entry>& getBookmarks() { return ProjectFile::s_bookmarks; }
static void setBookmarks(const std::list<ImHexApi::Bookmarks::Entry> &bookmarks) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_bookmarks = bookmarks; }
[[nodiscard]] static const std::string_view getDataProcessorContent() { return ProjectFile::s_dataProcessorContent; } [[nodiscard]] static std::string getFilePath() {
static void setDataProcessorContent(std::string_view json) { ProjectFile::s_dataProcessorContent = json; } return ProjectFile::s_filePath;
}
static void setFilePath(std::string_view filePath) {
ProjectFile::s_filePath = filePath;
EventManager::post<RequestChangeWindowTitle>(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<ImHexApi::Bookmarks::Entry>& getBookmarks() {
return ProjectFile::s_bookmarks;
}
static void setBookmarks(const std::list<ImHexApi::Bookmarks::Entry> &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: private:
static inline std::string s_currProjectFilePath; static inline std::string s_currProjectFilePath;

View File

@ -57,7 +57,7 @@ namespace hex {
} }
bool ProjectFile::store(std::string_view filePath) { bool ProjectFile::store(std::string_view filePath) {
ProjectFile::s_hasUnsavedChanged = false; EventManager::post<EventProjectFileStore>();
json projectFileData; json projectFileData;
@ -82,6 +82,7 @@ namespace hex {
return false; return false;
} }
ProjectFile::s_hasUnsavedChanged = false;
ProjectFile::s_currProjectFilePath = filePath; ProjectFile::s_currProjectFilePath = filePath;
return true; return true;

View File

@ -70,6 +70,8 @@ namespace hex {
} }
this->m_links.erase(link); this->m_links.erase(link);
ProjectFile::markDirty();
} }
void ViewDataProcessor::eraseNodes(const std::vector<int> &ids) { void ViewDataProcessor::eraseNodes(const std::vector<int> &ids) {
@ -95,6 +97,8 @@ namespace hex {
this->m_nodes.erase(node); this->m_nodes.erase(node);
} }
ProjectFile::markDirty();
} }
void ViewDataProcessor::processNodes() { void ViewDataProcessor::processNodes() {
@ -181,11 +185,13 @@ namespace hex {
} else if (unlocalizedCategory.empty()) { } else if (unlocalizedCategory.empty()) {
if (ImGui::MenuItem(LangEntry(unlocalizedName))) { if (ImGui::MenuItem(LangEntry(unlocalizedName))) {
node = function(); node = function();
ProjectFile::markDirty();
} }
} else { } else {
if (ImGui::BeginMenu(LangEntry(unlocalizedCategory))) { if (ImGui::BeginMenu(LangEntry(unlocalizedCategory))) {
if (ImGui::MenuItem(LangEntry(unlocalizedName))) { if (ImGui::MenuItem(LangEntry(unlocalizedName))) {
node = function(); node = function();
ProjectFile::markDirty();
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }

View File

@ -19,11 +19,14 @@
#include <imgui_imhex_extensions.h> #include <imgui_imhex_extensions.h>
#include <implot.h> #include <implot.h>
#include <implot_internal.h> #include <implot_internal.h>
#include <imnodes.h>
#include <imnodes_internal.h>
#include <fontawesome_font.h> #include <fontawesome_font.h>
#include <codicons_font.h> #include <codicons_font.h>
#include "helpers/plugin_manager.hpp" #include "helpers/plugin_manager.hpp"
#include "helpers/project_file_handler.hpp"
#include "init/tasks.hpp" #include "init/tasks.hpp"
#include <glad/glad.h> #include <glad/glad.h>