From 7285537d73a976abf11810fa2dc5b8c7fb5ed720 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 28 Aug 2021 18:15:47 +0200 Subject: [PATCH] tools: Various fixes and improvements --- .../builtin/source/content/tools_entries.cpp | 27 ++++++++++++------- plugins/builtin/source/lang/de_DE.cpp | 8 +++--- plugins/builtin/source/lang/en_US.cpp | 8 +++--- plugins/builtin/source/lang/it_IT.cpp | 8 +++--- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/plugins/builtin/source/content/tools_entries.cpp b/plugins/builtin/source/content/tools_entries.cpp index b4e8ff564..2c9e5b35c 100644 --- a/plugins/builtin/source/content/tools_entries.cpp +++ b/plugins/builtin/source/content/tools_entries.cpp @@ -525,7 +525,7 @@ namespace hex::plugin::builtin { ImGui::Header("hex.builtin.tools.file_uploader.recent"_lang); - if (ImGui::BeginTable("##links", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg, ImVec2(0, 400))) { + if (ImGui::BeginTable("##links", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg, ImVec2(0, 200))) { ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("hex.common.file"_lang); ImGui::TableSetupColumn("hex.common.link"_lang); @@ -587,28 +587,37 @@ namespace hex::plugin::builtin { void drawWikiExplainer() { static hex::Net net; - static std::string searchString(0xFFF, 0x00); + static std::string resultTitle, resultExtract; static std::future> searchProcess; static bool extendedSearch = false; + static auto searchString = []{ + std::string s; + s.reserve(0xFFFF); + std::memset(s.data(), 0x00, s.capacity()); + + return s; + }(); + constexpr static auto WikipediaApiUrl = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext&redirects=10&formatversion=2"; - ImGui::Header("hex.builtin.tools.file_uploader.control"_lang, true); + ImGui::Header("hex.builtin.tools.wiki_explain.control"_lang, true); - ImGui::BeginDisabled(searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready); + bool startSearch; - bool startSearch = ImGui::InputText("##search", searchString.data(), searchString.capacity(), ImGuiInputTextFlags_EnterReturnsTrue); + startSearch = ImGui::InputText("##search", searchString.data(), searchString.capacity(), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit, updateStringSizeCallback, &searchString); ImGui::SameLine(); - startSearch = ImGui::Button("hex.builtin.tools.file_uploader.search"_lang) || startSearch; + ImGui::BeginDisabled(searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready || searchString.empty()); + startSearch = ImGui::Button("hex.builtin.tools.wiki_explain.search"_lang) || startSearch; ImGui::EndDisabled(); - if (startSearch) { + if (startSearch && !searchString.empty()) { searchProcess = net.getString(WikipediaApiUrl + "&exintro"s + "&titles="s + net.encode(searchString)); } - ImGui::Header("hex.builtin.tools.file_uploader.results"_lang); + ImGui::Header("hex.builtin.tools.wiki_explain.results"_lang); if (ImGui::BeginChild("##summary", ImVec2(0, 300), true)) { if (!resultTitle.empty() && !resultExtract.empty()) { @@ -644,7 +653,7 @@ namespace hex::plugin::builtin { searchProcess = { }; resultTitle = "???"; - resultExtract = "hex.builtin.tools.file_uploader.invalid_response"_lang.get(); + resultExtract = "hex.builtin.tools.wiki_explain.invalid_response"_lang.get(); } } } diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 29369beeb..fa65b13bf 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -549,10 +549,10 @@ namespace hex::plugin::builtin { { "hex.builtin.tools.file_uploader.invalid_response", "Ungültige Antwort von Anonfiles!" }, { "hex.builtin.tools.file_uploader.error", "Dateiupload fehlgeschlagen\n\nError Code: {0}" }, { "hex.builtin.tools.wiki_explain", "Wikipedia Definition" }, - { "hex.builtin.tools.file_uploader.control", "Einstellungen" }, - { "hex.builtin.tools.file_uploader.search", "Suchen" }, - { "hex.builtin.tools.file_uploader.results", "Resultate" }, - { "hex.builtin.tools.file_uploader.invalid_response", "Ungültige Antwort von Wikipedia!" }, + { "hex.builtin.tools.wiki_explain.control", "Einstellungen" }, + { "hex.builtin.tools.wiki_explain.search", "Suchen" }, + { "hex.builtin.tools.wiki_explain.results", "Resultate" }, + { "hex.builtin.tools.wiki_explain.invalid_response", "Ungültige Antwort von Wikipedia!" }, { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "Kürzlich geöffnete Dateien" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index d866115d5..09ddcd4b2 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -549,10 +549,10 @@ namespace hex::plugin::builtin { { "hex.builtin.tools.file_uploader.invalid_response", "Invalid response from Anonfiles!" }, { "hex.builtin.tools.file_uploader.error", "Failed to upload file!\n\nError Code: {0}" }, { "hex.builtin.tools.wiki_explain", "Wikipedia term definitions" }, - { "hex.builtin.tools.file_uploader.control", "Control" }, - { "hex.builtin.tools.file_uploader.search", "Search" }, - { "hex.builtin.tools.file_uploader.results", "Results" }, - { "hex.builtin.tools.file_uploader.invalid_response", "Invalid response from Wikipedia!" }, + { "hex.builtin.tools.wiki_explain.control", "Control" }, + { "hex.builtin.tools.wiki_explain.search", "Search" }, + { "hex.builtin.tools.wiki_explain.results", "Results" }, + { "hex.builtin.tools.wiki_explain.invalid_response", "Invalid response from Wikipedia!" }, { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "Recent Files" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index 757d00b08..d4535ea87 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -548,10 +548,10 @@ namespace hex::plugin::builtin { //{ "hex.builtin.tools.file_uploader.invalid_response", "Invalid response from Anonfiles!" }, //{ "hex.builtin.tools.file_uploader.error", "Failed to upload file!\n\nError Code: {0}" }, //{ "hex.builtin.tools.wiki_explain", "Wikipedia term definitions" }, - //{ "hex.builtin.tools.file_uploader.control", "Control" }, - //{ "hex.builtin.tools.file_uploader.search", "Search" }, - //{ "hex.builtin.tools.file_uploader.results", "Results" }, - //{ "hex.builtin.tools.file_uploader.invalid_response", "Invalid response from Wikipedia!" }, + //{ "hex.builtin.tools.wiki_explain.control", "Control" }, + //{ "hex.builtin.tools.wiki_explain.search", "Search" }, + //{ "hex.builtin.tools.wiki_explain.results", "Results" }, + //{ "hex.builtin.tools.wiki_explain.invalid_response", "Invalid response from Wikipedia!" }, { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "File recenti" },