diff --git a/plugins/builtin/include/content/providers/memory_file_provider.hpp b/plugins/builtin/include/content/providers/memory_file_provider.hpp index 6553e0f60..4bff898ab 100644 --- a/plugins/builtin/include/content/providers/memory_file_provider.hpp +++ b/plugins/builtin/include/content/providers/memory_file_provider.hpp @@ -14,7 +14,7 @@ namespace hex::plugin::builtin { [[nodiscard]] bool isReadable() const override { return true; } [[nodiscard]] bool isWritable() const override { return !this->m_readOnly; } [[nodiscard]] bool isResizable() const override { return !this->m_readOnly; } - [[nodiscard]] bool isSavable() const override { return !this->m_readOnly; } + [[nodiscard]] bool isSavable() const override { return this->m_name.empty(); } [[nodiscard]] bool open() override; void close() override { } @@ -29,9 +29,11 @@ namespace hex::plugin::builtin { void save() override; - [[nodiscard]] std::string getName() const override { return LangEntry("hex.builtin.provider.mem_file.unsaved"); } + [[nodiscard]] std::string getName() const override; [[nodiscard]] std::vector getDataDescription() const override { return { }; } + std::vector getMenuEntries() override; + [[nodiscard]] std::string getTypeName() const override { return "hex.builtin.provider.mem_file"; } @@ -43,8 +45,12 @@ namespace hex::plugin::builtin { void setReadOnly(bool readOnly) { this->m_readOnly = readOnly; } + private: + void renameFile(); + private: std::vector m_data; + std::string m_name; bool m_readOnly = false; }; diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index c4d0a7874..6610b4419 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -499,6 +499,8 @@ "hex.builtin.provider.intel_hex.name": "Intel Hex {0}", "hex.builtin.provider.mem_file": "Memory File", "hex.builtin.provider.mem_file.unsaved": "Unsaved File", + "hex.builtin.provider.mem_file.rename": "Rename", + "hex.builtin.provider.mem_file.rename.desc": "Enter a name for this memory file.", "hex.builtin.provider.motorola_srec": "Motorola SREC Provider", "hex.builtin.provider.motorola_srec.name": "Motorola SREC {0}", "hex.builtin.provider.view": "View", diff --git a/plugins/builtin/source/content/providers/memory_file_provider.cpp b/plugins/builtin/source/content/providers/memory_file_provider.cpp index c32b0fcd1..4cbf59057 100644 --- a/plugins/builtin/source/content/providers/memory_file_provider.cpp +++ b/plugins/builtin/source/content/providers/memory_file_provider.cpp @@ -1,5 +1,6 @@ #include "content/providers/memory_file_provider.hpp" #include "content/providers/file_provider.hpp" +#include "content/popups/popup_text_input.hpp" #include @@ -35,6 +36,9 @@ namespace hex::plugin::builtin { } void MemoryFileProvider::save() { + if (!this->m_name.empty()) + return; + fs::openFileBrowser(fs::DialogMode::Save, { }, [this](const std::fs::path &path) { if (path.empty()) return; @@ -103,6 +107,19 @@ namespace hex::plugin::builtin { Provider::remove(offset, size); } + [[nodiscard]] std::string MemoryFileProvider::getName() const { + if (this->m_name.empty()) + return LangEntry("hex.builtin.provider.mem_file.unsaved"); + else + return this->m_name; + } + + std::vector MemoryFileProvider::getMenuEntries() { + return { + MenuEntry { LangEntry("hex.builtin.provider.mem_file.rename"), [this]() { this->renameFile(); } } + }; + } + std::pair MemoryFileProvider::getRegionValidity(u64 address) const { address -= this->getBaseAddress(); @@ -116,12 +133,20 @@ namespace hex::plugin::builtin { Provider::loadSettings(settings); this->m_data = settings["data"].get>(); + this->m_name = settings["name"].get(); } [[nodiscard]] nlohmann::json MemoryFileProvider::storeSettings(nlohmann::json settings) const { settings["data"] = this->m_data; + settings["name"] = this->m_name; return Provider::storeSettings(settings); } + void MemoryFileProvider::renameFile() { + PopupTextInput::open("hex.builtin.provider.mem_file.rename"_lang, "hex.builtin.provider.mem_file.rename.desc"_lang, [this](const std::string &name) { + this->m_name = name; + }); + } + }