Make pattern popup when loading a file list all available patterns

This commit is contained in:
WerWolv
2021-01-23 14:01:23 +01:00
parent 51d9d37d1a
commit b8e383368d
2 changed files with 22 additions and 12 deletions

View File

@@ -9,6 +9,7 @@
#include <cstring>
#include <filesystem>
#include <thread>
#include <vector>
#include <ImGuiFileBrowser.h>
#include <TextEditor.h>
@@ -26,7 +27,8 @@ namespace hex {
private:
lang::PatternLanguage *m_patternLanguageRuntime;
std::vector<lang::PatternData*> &m_patternData;
std::filesystem::path m_possiblePatternFile;
std::vector<std::string> m_possiblePatternFiles;
int m_selectedPatternFile = 0;
TextEditor m_textEditor;
std::vector<std::pair<lang::LogConsole::Level, std::string>> m_console;

View File

@@ -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();