feat: Allow memory files to be renamed
This commit is contained in:
parent
ba9227c1e0
commit
a6aafa8cd6
@ -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<Description> getDataDescription() const override { return { }; }
|
||||
|
||||
std::vector<MenuEntry> 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<u8> m_data;
|
||||
std::string m_name;
|
||||
bool m_readOnly = false;
|
||||
};
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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 <cstring>
|
||||
|
||||
@ -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::MenuEntry> MemoryFileProvider::getMenuEntries() {
|
||||
return {
|
||||
MenuEntry { LangEntry("hex.builtin.provider.mem_file.rename"), [this]() { this->renameFile(); } }
|
||||
};
|
||||
}
|
||||
|
||||
std::pair<Region, bool> 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<std::vector<u8>>();
|
||||
this->m_name = settings["name"].get<std::string>();
|
||||
}
|
||||
|
||||
[[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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user