From 0da31b6bbb2231388e94eb834abcb9fbfea80d63 Mon Sep 17 00:00:00 2001 From: qdlmcfresh Date: Tue, 30 Nov 2021 21:02:37 +0100 Subject: [PATCH] ui: Add result count to string view (#353) * Add result count to string view * Localization * formating and logic fix --- plugins/builtin/source/lang/de_DE.cpp | 1 + plugins/builtin/source/lang/en_US.cpp | 1 + source/views/view_strings.cpp | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 84d4defe4..90f5e1b16 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -285,6 +285,7 @@ namespace hex::plugin::builtin { { "hex.view.strings.filter", "Filter" }, { "hex.view.strings.extract", "Extrahieren" }, { "hex.view.strings.regex_error", "Ungültiges Regex" }, + { "hex.view.strings.results", "{0} Ergebnisse" }, { "hex.view.strings.searching", "Suchen..." }, { "hex.view.strings.offset", "Offset" }, { "hex.view.strings.size", "Grösse" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index 24b6a55da..b7cf4eb2d 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -288,6 +288,7 @@ namespace hex::plugin::builtin { { "hex.view.strings.filter", "Filter" }, { "hex.view.strings.extract", "Extract" }, { "hex.view.strings.regex_error", "Invalid regex" }, + { "hex.view.strings.results", "Found {0} occurrences" }, { "hex.view.strings.searching", "Searching..." }, { "hex.view.strings.offset", "Offset" }, { "hex.view.strings.size", "Size" }, diff --git a/source/views/view_strings.cpp b/source/views/view_strings.cpp index f28ec7897..195d84d64 100644 --- a/source/views/view_strings.cpp +++ b/source/views/view_strings.cpp @@ -1,6 +1,7 @@ #include "views/view_strings.hpp" #include +#include #include #include @@ -116,17 +117,17 @@ namespace hex { } } for (u64 i = 0; i < view.m_foundStrings.size(); i++) { - if(view.m_regex){ + if (view.m_regex) { if(view.m_pattern_parsed && std::regex_search(readString(view.m_foundStrings[i]), pattern)) view.m_filterIndices.push_back(i); } - else if(readString(view.m_foundStrings[i]).find(data->Buf) != std::string::npos) { + else if (readString(view.m_foundStrings[i]).find(data->Buf) != std::string::npos) { view.m_filterIndices.push_back(i); } } return 0; }, this); - if(this->m_regex && !this->m_pattern_parsed){ + if (this->m_regex && !this->m_pattern_parsed) { ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "hex.view.strings.regex_error"_lang); } @@ -138,6 +139,10 @@ namespace hex { ImGui::SameLine(); ImGui::TextSpinner("hex.view.strings.searching"_lang); } + else if (this->m_foundStrings.size() > 0) { + ImGui::SameLine(); + ImGui::TextUnformatted(hex::format("hex.view.strings.results"_lang, this->m_filterIndices.size()).c_str()); + } ImGui::Separator();