From 35c209c791964c26cc771fc6e840fff464cac2ce Mon Sep 17 00:00:00 2001 From: Lukas Cone Date: Thu, 14 Jul 2022 11:37:02 +0200 Subject: [PATCH] fix: In/Out variables not working, add recusive pattern scan (#579) --- .../content/views/view_pattern_editor.hpp | 3 +-- .../content/views/view_pattern_editor.cpp | 21 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 8bb35133f..288be915c 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -56,7 +56,6 @@ namespace hex::plugin::builtin { }; std::map m_patternVariables; - std::vector m_patternTypes; enum class EnvVarType { @@ -102,4 +101,4 @@ namespace hex::plugin::builtin { void evaluatePattern(const std::string &code); }; -} \ No newline at end of file +} diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 603869579..37a8fd213 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -93,9 +93,7 @@ namespace hex::plugin::builtin { }); EventManager::subscribe(this, [this](const std::string &code) { - this->m_textEditor.SelectAll(); - this->m_textEditor.Delete(); - this->m_textEditor.InsertText(code); + this->m_textEditor.SetText(code); }); EventManager::subscribe(this, [this](const std::fs::path &path) { @@ -127,7 +125,7 @@ namespace hex::plugin::builtin { std::error_code errorCode; for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Patterns)) { - for (auto &entry : std::fs::directory_iterator(dir, errorCode)) { + for (auto &entry : std::fs::recursive_directory_iterator(dir, errorCode)) { foundCorrectType = false; if (!entry.is_regular_file()) continue; @@ -558,25 +556,27 @@ namespace hex::plugin::builtin { if (variable.outVariable) { ImGui::TextUnformatted(pl::Token::literalToString(variable.value, true).c_str()); } else if (variable.inVariable) { + const std::string label { "##" + name }; + if (pl::Token::isSigned(variable.type)) { i64 value = hex::get_or(variable.value, 0); - ImGui::InputScalar("", ImGuiDataType_S64, &value); + ImGui::InputScalar(label.c_str(), ImGuiDataType_S64, &value); variable.value = i128(value); } else if (pl::Token::isUnsigned(variable.type)) { u64 value = hex::get_or(variable.value, 0); - ImGui::InputScalar("", ImGuiDataType_U64, &value); + ImGui::InputScalar(label.c_str(), ImGuiDataType_U64, &value); variable.value = u128(value); } else if (pl::Token::isFloatingPoint(variable.type)) { double value = hex::get_or(variable.value, 0.0); - ImGui::InputScalar("", ImGuiDataType_Double, &value); + ImGui::InputScalar(label.c_str(), ImGuiDataType_Double, &value); variable.value = value; } else if (variable.type == pl::Token::ValueType::Boolean) { bool value = hex::get_or(variable.value, false); - ImGui::Checkbox("", &value); + ImGui::Checkbox(label.c_str(), &value); variable.value = value; } else if (variable.type == pl::Token::ValueType::Character) { char buffer[2]; - ImGui::InputText("", buffer, 2); + ImGui::InputText(label.c_str(), buffer, 2); variable.value = buffer[0]; } } @@ -717,7 +717,6 @@ namespace hex::plugin::builtin { auto ast = this->m_parserRuntime->parseString(code); this->m_patternVariables.clear(); - this->m_patternTypes.clear(); if (ast) { for (auto &node : *ast) { @@ -752,7 +751,7 @@ namespace hex::plugin::builtin { this->m_textEditor.SetErrorMarkers({}); this->m_console.clear(); - this->clearPatterns(); + ImHexApi::Provider::get()->getPatternLanguageRuntime().reset(); EventManager::post();