1
0
mirror of synced 2024-11-24 15:50:16 +01:00

feat: allow loading and saving pattern code via events (#1004)

Currently there is no way to save the pattern code progamically from a
plugin unless the builtin plugin is modified to add those events. This
pull request will be adding ability to load and save pattern code from
specified file.
This commit is contained in:
H1X4 2023-04-01 12:18:52 +03:00 committed by GitHub
parent af18ca011b
commit aab8c88a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -165,6 +165,8 @@ namespace hex {
EVENT_DEF(RequestSelectionChange, Region);
EVENT_DEF(RequestAddBookmark, Region, std::string, std::string, color_t);
EVENT_DEF(RequestSetPatternLanguageCode, std::string);
EVENT_DEF(RequestLoadPatternLanguageFile, std::fs::path);
EVENT_DEF(RequestSavePatternLanguageFile, std::fs::path);
EVENT_DEF(RequestUpdateWindowTitle);
EVENT_DEF(RequestCloseImHex, bool);
EVENT_DEF(RequestRestartImHex);

View File

@ -748,6 +748,15 @@ namespace hex::plugin::builtin {
}
void ViewPatternEditor::registerEvents() {
EventManager::subscribe<RequestLoadPatternLanguageFile>(this, [this](const std::fs::path &path) {
this->loadPatternFile(path, ImHexApi::Provider::get());
});
EventManager::subscribe<RequestSavePatternLanguageFile>(this, [this](const std::fs::path &path) {
wolv::io::File file(path, wolv::io::File::Mode::Create);
file.writeString(wolv::util::trim(this->m_textEditor.GetText()));
});
EventManager::subscribe<RequestSetPatternLanguageCode>(this, [this](const std::string &code) {
this->m_textEditor.SetText(code);
});