mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
feat: Allow memory files to be renamed
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user