From 8cb833eca926499ccf109384d666c7146aeb1cbd Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 31 Dec 2023 13:53:44 +0100 Subject: [PATCH] impr: Improve Documentation AI UX --- .../content/popups/popup_docs_question.hpp | 15 +++++++++---- plugins/builtin/romfs/lang/en_US.json | 1 + .../source/content/views/view_about.cpp | 22 +++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/plugins/builtin/include/content/popups/popup_docs_question.hpp b/plugins/builtin/include/content/popups/popup_docs_question.hpp index 6c99de52f..d0c9c3743 100644 --- a/plugins/builtin/include/content/popups/popup_docs_question.hpp +++ b/plugins/builtin/include/content/popups/popup_docs_question.hpp @@ -14,8 +14,14 @@ namespace hex::plugin::builtin { class PopupDocsQuestion : public Popup { public: - PopupDocsQuestion() - : hex::Popup("hex.builtin.popup.docs_question.title", true, true) { } + PopupDocsQuestion(const std::string &input = "") + : hex::Popup("hex.builtin.popup.docs_question.title", true, true) { + + if (!input.empty()) { + m_inputBuffer = input; + this->executeQuery(); + } + } enum class TextBlockType { Text, @@ -99,6 +105,7 @@ namespace hex::plugin::builtin { try { auto json = nlohmann::json::parse(response.getData()); + if (!json.contains("answer")) continue; @@ -126,9 +133,9 @@ namespace hex::plugin::builtin { } catch(...) { continue; } - - m_noAnswer = m_answer.empty(); } + + m_noAnswer = m_answer.empty(); }); } diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 790e46252..4b4ed6ebd 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -721,6 +721,7 @@ "hex.builtin.view.help.about.translator": "Translated by WerWolv", "hex.builtin.view.help.calc_cheat_sheet": "Calculator Cheat Sheet", "hex.builtin.view.help.documentation": "ImHex Documentation", + "hex.builtin.view.help.documentation_search": "Search Documentation", "hex.builtin.view.help.name": "Help", "hex.builtin.view.help.pattern_cheat_sheet": "Pattern Language Cheat Sheet", "hex.builtin.view.hex_editor.copy.address": "Address", diff --git a/plugins/builtin/source/content/views/view_about.cpp b/plugins/builtin/source/content/views/view_about.cpp index 36c1dcb1c..12ec9c504 100644 --- a/plugins/builtin/source/content/views/view_about.cpp +++ b/plugins/builtin/source/content/views/view_about.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include namespace hex::plugin::builtin { @@ -81,14 +81,22 @@ namespace hex::plugin::builtin { ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.help" }, 2000); - // Add documentation links to the help menu - ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.help", "hex.builtin.view.help.documentation" }, 3000, Shortcut::None, [] { - hex::openWebpage("https://docs.werwolv.net/imhex"); - AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.docs.name"); + ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.help" }, 3000, [] { + static std::string content; + if (ImGui::InputTextWithHint("##search", "hex.builtin.view.help.documentation_search"_lang, content, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EscapeClearsAll | ImGuiInputTextFlags_EnterReturnsTrue)) { + PopupDocsQuestion::open(content); + content.clear(); + ImGui::CloseCurrentPopup(); + } }); - ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.help", "hex.builtin.menu.help.ask_for_help" }, 4000, CTRLCMD + SHIFT + Keys::D, [] { - PopupDocsQuestion::open(); + ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.help" }, 4000); + + + // Add documentation link to the help menu + ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.help", "hex.builtin.view.help.documentation" }, 5000, Shortcut::None, [] { + hex::openWebpage("https://docs.werwolv.net/imhex"); + AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.docs.name"); }); }