From b8e383368df48d1a7873d239459a898c03e266ed Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 23 Jan 2021 14:01:23 +0100 Subject: [PATCH] Make pattern popup when loading a file list all available patterns --- include/views/view_pattern.hpp | 4 +++- source/views/view_pattern.cpp | 30 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/views/view_pattern.hpp b/include/views/view_pattern.hpp index f7fee5b26..e1f50421d 100644 --- a/include/views/view_pattern.hpp +++ b/include/views/view_pattern.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,8 @@ namespace hex { private: lang::PatternLanguage *m_patternLanguageRuntime; std::vector &m_patternData; - std::filesystem::path m_possiblePatternFile; + std::vector m_possiblePatternFiles; + int m_selectedPatternFile = 0; TextEditor m_textEditor; std::vector> m_console; diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index a9424cdd5..61bdcd40f 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -159,12 +159,13 @@ namespace hex { preprocessor.preprocess(buffer.data()); - if (foundCorrectType) { - this->m_possiblePatternFile = entry.path(); - View::doLater([] { ImGui::OpenPopup("Accept Pattern"); }); - ImGui::SetNextWindowSize(ImVec2(200, 100)); - break; - } + if (foundCorrectType) + this->m_possiblePatternFiles.push_back(entry.path().filename().string()); + } + + if (!this->m_possiblePatternFiles.empty()) { + this->m_selectedPatternFile = 0; + View::doLater([] { ImGui::OpenPopup("Accept Pattern"); }); } }); @@ -275,15 +276,22 @@ namespace hex { this->loadPatternFile(this->m_fileBrowser.selected_path); } - if (ImGui::BeginPopupModal("Accept Pattern", nullptr, ImGuiWindowFlags_NoResize)) { - ImGui::TextUnformatted("A pattern compatible with this data type has been found:"); - ImGui::Text("%ls", this->m_possiblePatternFile.filename().c_str()); + if (ImGui::BeginPopupModal("Accept Pattern", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::TextWrapped("One or more patterns compatible with this data type has been found"); + + char *entries[this->m_possiblePatternFiles.size()]; + + for (u32 i = 0; i < this->m_possiblePatternFiles.size(); i++) { + entries[i] = this->m_possiblePatternFiles[i].data(); + } + + ImGui::ListBox("Patterns", &this->m_selectedPatternFile, entries, IM_ARRAYSIZE(entries), 4); + ImGui::NewLine(); ImGui::Text("Do you want to load it?"); - ImGui::NewLine(); confirmButtons("Yes", "No", [this]{ - this->loadPatternFile(this->m_possiblePatternFile.string()); + this->loadPatternFile("patterns/" + this->m_possiblePatternFiles[this->m_selectedPatternFile]); ImGui::CloseCurrentPopup(); }, []{ ImGui::CloseCurrentPopup();