impr: Make accept pattern popup open faster and close correctly

This commit is contained in:
WerWolv
2024-05-08 23:54:09 +02:00
parent 6602e800ac
commit 978fa17932
3 changed files with 24 additions and 14 deletions

View File

@@ -487,7 +487,7 @@ namespace hex {
else
createPopup(ImGui::BeginPopup(name, flags));
if (!ImGui::IsPopupOpen(name) && displayFrameCount < 100) {
if (!ImGui::IsPopupOpen(name) && displayFrameCount < 5) {
ImGui::OpenPopup(name);
}

View File

@@ -81,6 +81,8 @@ namespace hex::plugin::builtin {
explicit PopupAcceptPattern(ViewPatternEditor *view) : Popup("hex.builtin.view.pattern_editor.accept_pattern"), m_view(view) {}
void drawContent() override {
std::scoped_lock lock(m_view->m_possiblePatternFilesMutex);
auto* provider = ImHexApi::Provider::get();
ImGuiExt::TextFormattedWrapped("{}", static_cast<const char *>("hex.builtin.view.pattern_editor.accept_pattern.desc"_lang));
@@ -117,13 +119,13 @@ namespace hex::plugin::builtin {
ImGui::TextUnformatted("hex.builtin.view.pattern_editor.accept_pattern.question"_lang);
ImGuiExt::ConfirmButtons("hex.ui.common.yes"_lang, "hex.ui.common.no"_lang,
[this, provider] {
m_view->loadPatternFile(m_view->m_possiblePatternFiles.get(provider)[m_selectedPatternFile], provider);
this->close();
},
[this] {
this->close();
}
[this, provider] {
m_view->loadPatternFile(m_view->m_possiblePatternFiles.get(provider)[m_selectedPatternFile], provider);
this->close();
},
[this] {
this->close();
}
);
if (ImGui::IsKeyPressed(ImGuiKey_Escape))
@@ -174,6 +176,7 @@ namespace hex::plugin::builtin {
std::unique_ptr<pl::PatternLanguage> m_editorRuntime;
std::mutex m_possiblePatternFilesMutex;
PerProvider<std::vector<std::fs::path>> m_possiblePatternFiles;
bool m_runAutomatically = false;
bool m_triggerEvaluation = false;

View File

@@ -1407,6 +1407,7 @@ namespace hex::plugin::builtin {
m_possiblePatternFiles.get(provider).clear();
bool popupOpen = false;
std::error_code errorCode;
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Patterns)) {
for (auto &entry : std::fs::recursive_directory_iterator(dir, errorCode)) {
@@ -1423,16 +1424,22 @@ namespace hex::plugin::builtin {
log::warn("Failed to preprocess file {} during MIME analysis", entry.path().string());
}
if (foundCorrectType)
m_possiblePatternFiles.get(provider).push_back(entry.path());
if (foundCorrectType) {
{
std::scoped_lock lock(m_possiblePatternFilesMutex);
m_possiblePatternFiles.get(provider).push_back(entry.path());
}
if (!popupOpen) {
PopupAcceptPattern::open(this);
popupOpen = true;
}
}
runtime.reset();
}
}
if (!m_possiblePatternFiles.get(provider).empty()) {
PopupAcceptPattern::open(this);
}
});
}
}