From b6f76ad8ede79790cefeec908ede981a5a7c4816 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 18 May 2021 18:27:36 +0200 Subject: [PATCH] ux: Fixed MIME-based pattern loading popup not working properly Fixed issues addressed in #225 --- source/views/view_pattern.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index b7a87bd23..cf29d8a74 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -143,6 +143,7 @@ namespace hex { }); preprocessor.addDefaultPragmaHandlers(); + this->m_possiblePatternFiles.clear(); std::error_code errorCode; for (const auto &dir : hex::getPath(ImHexPath::Patterns)) { @@ -294,13 +295,20 @@ namespace hex { if (ImGui::BeginPopupModal("hex.view.pattern.accept_pattern"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::TextWrapped("hex.view.pattern.accept_pattern.desc"_lang); - char *entries[this->m_possiblePatternFiles.size()]; + std::vector entries; + entries.resize(this->m_possiblePatternFiles.size()); - for (u32 i = 0; i < this->m_possiblePatternFiles.size(); i++) { - entries[i] = this->m_possiblePatternFiles[i].data(); + for (u32 i = 0; i < entries.size(); i++) { + entries[i] = std::filesystem::path(this->m_possiblePatternFiles[i]).filename().string(); } - ImGui::ListBox("hex.view.pattern.accept_pattern.patterns"_lang, &this->m_selectedPatternFile, entries, IM_ARRAYSIZE(entries), 4); + ImGui::ListBox("hex.view.pattern.accept_pattern.patterns"_lang, &this->m_selectedPatternFile, [](void *data, int id, const char** outText) -> bool { + auto &entries = *static_cast*>(data); + + *outText = entries[id].c_str(); + + return true; + }, &entries, entries.size(), 4); ImGui::NewLine(); ImGui::Text("hex.view.pattern.accept_pattern.question"_lang);