From 714d421334878ba46d58be2541dd24798275633f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 23 Jan 2022 02:28:38 +0100 Subject: [PATCH] api: Moved menu item adding to a new registry-type API --- .../include/hex/api/content_registry.hpp | 9 + .../include/hex/helpers/shared_data.hpp | 1 + lib/libimhex/include/hex/views/view.hpp | 1 - lib/libimhex/source/api/content_registry.cpp | 11 +- lib/libimhex/source/helpers/shared_data.cpp | 2 + lib/libimhex/source/views/view.cpp | 2 - main/source/init/tasks.cpp | 2 + main/source/window/window.cpp | 13 +- .../include/content/views/view_bookmarks.hpp | 1 - .../content/views/view_command_palette.hpp | 2 +- .../include/content/views/view_constants.hpp | 1 - .../content/views/view_data_inspector.hpp | 1 - .../content/views/view_data_processor.hpp | 1 - .../include/content/views/view_diff.hpp | 1 - .../content/views/view_disassembler.hpp | 1 - .../include/content/views/view_hashes.hpp | 1 - .../include/content/views/view_help.hpp | 3 +- .../include/content/views/view_hexeditor.hpp | 2 +- .../content/views/view_information.hpp | 1 - .../include/content/views/view_patches.hpp | 1 - .../content/views/view_pattern_data.hpp | 1 - .../content/views/view_pattern_editor.hpp | 1 - .../include/content/views/view_settings.hpp | 3 +- .../include/content/views/view_store.hpp | 1 - .../include/content/views/view_strings.hpp | 1 - .../include/content/views/view_tools.hpp | 1 - .../include/content/views/view_yara.hpp | 1 - .../source/content/views/view_bookmarks.cpp | 4 - .../content/views/view_command_palette.cpp | 4 - .../source/content/views/view_constants.cpp | 4 - .../content/views/view_data_inspector.cpp | 4 - .../content/views/view_data_processor.cpp | 4 - .../source/content/views/view_diff.cpp | 4 - .../content/views/view_disassembler.cpp | 4 - .../source/content/views/view_hashes.cpp | 4 - .../source/content/views/view_help.cpp | 27 +- .../source/content/views/view_hexeditor.cpp | 554 +++++++++--------- .../source/content/views/view_information.cpp | 4 - .../source/content/views/view_patches.cpp | 4 - .../content/views/view_pattern_data.cpp | 4 - .../content/views/view_pattern_editor.cpp | 33 +- .../source/content/views/view_settings.cpp | 21 +- .../source/content/views/view_store.cpp | 19 +- .../source/content/views/view_strings.cpp | 4 - .../source/content/views/view_tools.cpp | 4 - .../source/content/views/view_yara.cpp | 4 - .../include/views/view_tty_console.hpp | 1 - .../windows/source/views/view_tty_console.cpp | 4 - 48 files changed, 364 insertions(+), 417 deletions(-) diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index f9f8c2efa..68abfb3be 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -232,6 +232,11 @@ namespace hex { DrawCallback callback; }; + struct MenuItem { + std::string unlocalizedName; + DrawCallback callback; + }; + struct SidebarItem { std::string icon; DrawCallback callback; @@ -242,6 +247,8 @@ namespace hex { u32 getDockSpaceId(); void registerMainMenuItem(const std::string &unlocalizedName, const impl::DrawCallback &function = []{}); + void addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function); + void addWelcomeScreenEntry(const impl::DrawCallback &function); void addFooterItem(const impl::DrawCallback &function); void addToolbarItem(const impl::DrawCallback &function); @@ -250,6 +257,8 @@ namespace hex { void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function); std::vector& getMainMenuItems(); + std::multimap& getMenuItems(); + std::vector& getWelcomeScreenEntries(); std::vector& getFooterItems(); std::vector& getToolbarItems(); diff --git a/lib/libimhex/include/hex/helpers/shared_data.hpp b/lib/libimhex/include/hex/helpers/shared_data.hpp index 3556ecdfa..fa082a4d5 100644 --- a/lib/libimhex/include/hex/helpers/shared_data.hpp +++ b/lib/libimhex/include/hex/helpers/shared_data.hpp @@ -78,6 +78,7 @@ namespace hex { static ImGuiID dockSpaceId; static std::vector mainMenuItems; + static std::multimap menuItems; static std::vector welcomeScreenEntries; static std::vector footerItems; static std::vector toolbarItems; diff --git a/lib/libimhex/include/hex/views/view.hpp b/lib/libimhex/include/hex/views/view.hpp index ebf7545cf..9ce7e9a7f 100644 --- a/lib/libimhex/include/hex/views/view.hpp +++ b/lib/libimhex/include/hex/views/view.hpp @@ -32,7 +32,6 @@ namespace hex { virtual void drawContent() = 0; virtual void drawAlwaysVisible() { } - virtual void drawMenu(); virtual bool isAvailable() const; virtual bool shouldProcess() const { return this->isAvailable() && this->getWindowOpenState(); } diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 667aa7cb4..4db8b5de5 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -300,6 +300,12 @@ namespace hex { getMainMenuItems().push_back({ unlocalizedName, function }); } + void ContentRegistry::Interface::addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function) { + log::info("Added new menu item to menu {} with priority {}", unlocalizedMainMenuName, priority); + + getMenuItems().insert({ priority, { unlocalizedMainMenuName, function }}); + } + void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::impl::DrawCallback &function) { getWelcomeScreenEntries().push_back(function); } @@ -323,9 +329,12 @@ namespace hex { } - std::vector &ContentRegistry::Interface::getMainMenuItems() { + std::vector& ContentRegistry::Interface::getMainMenuItems() { return SharedData::mainMenuItems; } + std::multimap& ContentRegistry::Interface::getMenuItems() { + return SharedData::menuItems; + } std::vector& ContentRegistry::Interface::getWelcomeScreenEntries() { return SharedData::welcomeScreenEntries; diff --git a/lib/libimhex/source/helpers/shared_data.cpp b/lib/libimhex/source/helpers/shared_data.cpp index ec06daa43..82bc44d9d 100644 --- a/lib/libimhex/source/helpers/shared_data.cpp +++ b/lib/libimhex/source/helpers/shared_data.cpp @@ -28,6 +28,8 @@ namespace hex { ImGuiID SharedData::dockSpaceId; std::vector SharedData::mainMenuItems; + std::multimap SharedData::menuItems; + std::vector SharedData::welcomeScreenEntries; std::vector SharedData::footerItems; std::vector SharedData::sidebarItems; diff --git a/lib/libimhex/source/views/view.cpp b/lib/libimhex/source/views/view.cpp index 78bff3e2b..ceeceebc7 100644 --- a/lib/libimhex/source/views/view.cpp +++ b/lib/libimhex/source/views/view.cpp @@ -12,8 +12,6 @@ namespace hex { View::View(std::string unlocalizedName) : m_unlocalizedViewName(unlocalizedName) { } - void View::drawMenu() { } - bool View::isAvailable() const { return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable(); } diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index 0f8aaf5e2..722080ba5 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -197,6 +197,8 @@ namespace hex::init { SharedData::welcomeScreenEntries.clear(); SharedData::footerItems.clear(); SharedData::toolbarItems.clear(); + SharedData::mainMenuItems.clear(); + SharedData::menuItems.clear(); SharedData::globalShortcuts.clear(); SharedData::runningTasks.clear(); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index f0a906e84..b5c46c9b4 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -437,8 +438,16 @@ namespace hex { } } - for (auto &[name, view] : ContentRegistry::Views::getEntries()) { - view->drawMenu(); + std::set encounteredMenus; + for (auto &[priority, menuItem] : ContentRegistry::Interface::getMenuItems()) { + if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) { + auto [iter, inserted] = encounteredMenus.insert(menuItem.unlocalizedName); + if (!inserted) + ImGui::Separator(); + + menuItem.callback(); + ImGui::EndMenu(); + } } this->drawTitleBar(); diff --git a/plugins/builtin/include/content/views/view_bookmarks.hpp b/plugins/builtin/include/content/views/view_bookmarks.hpp index d93187e84..1bc42d1c4 100644 --- a/plugins/builtin/include/content/views/view_bookmarks.hpp +++ b/plugins/builtin/include/content/views/view_bookmarks.hpp @@ -15,7 +15,6 @@ namespace hex::plugin::builtin { ~ViewBookmarks() override; void drawContent() override; - void drawMenu() override; }; } \ No newline at end of file diff --git a/plugins/builtin/include/content/views/view_command_palette.hpp b/plugins/builtin/include/content/views/view_command_palette.hpp index ab14d4644..16f57ce85 100644 --- a/plugins/builtin/include/content/views/view_command_palette.hpp +++ b/plugins/builtin/include/content/views/view_command_palette.hpp @@ -17,7 +17,7 @@ namespace hex::plugin::builtin { ~ViewCommandPalette() override; void drawContent() override; - void drawMenu() override; + [[nodiscard]] bool isAvailable() const override { return true; } [[nodiscard]] bool shouldProcess() const override { return true; } diff --git a/plugins/builtin/include/content/views/view_constants.hpp b/plugins/builtin/include/content/views/view_constants.hpp index 6aaa690f3..7c28d6543 100644 --- a/plugins/builtin/include/content/views/view_constants.hpp +++ b/plugins/builtin/include/content/views/view_constants.hpp @@ -26,7 +26,6 @@ namespace hex::plugin::builtin { ~ViewConstants() override; void drawContent() override; - void drawMenu() override; private: void reloadConstants(); diff --git a/plugins/builtin/include/content/views/view_data_inspector.hpp b/plugins/builtin/include/content/views/view_data_inspector.hpp index 8d77d390d..9c88073aa 100644 --- a/plugins/builtin/include/content/views/view_data_inspector.hpp +++ b/plugins/builtin/include/content/views/view_data_inspector.hpp @@ -18,7 +18,6 @@ namespace hex::plugin::builtin { ~ViewDataInspector() override; void drawContent() override; - void drawMenu() override; private: struct InspectorCacheEntry { diff --git a/plugins/builtin/include/content/views/view_data_processor.hpp b/plugins/builtin/include/content/views/view_data_processor.hpp index a2f4a816a..85f48efb5 100644 --- a/plugins/builtin/include/content/views/view_data_processor.hpp +++ b/plugins/builtin/include/content/views/view_data_processor.hpp @@ -20,7 +20,6 @@ namespace hex::plugin::builtin { ~ViewDataProcessor() override; void drawContent() override; - void drawMenu() override; private: std::list m_endNodes; diff --git a/plugins/builtin/include/content/views/view_diff.hpp b/plugins/builtin/include/content/views/view_diff.hpp index b506fd1ef..379b04ddc 100644 --- a/plugins/builtin/include/content/views/view_diff.hpp +++ b/plugins/builtin/include/content/views/view_diff.hpp @@ -19,7 +19,6 @@ namespace hex::plugin::builtin { ~ViewDiff() override; void drawContent() override; - void drawMenu() override; private: void drawDiffLine(const std::array &providerIds, u64 row) const; diff --git a/plugins/builtin/include/content/views/view_disassembler.hpp b/plugins/builtin/include/content/views/view_disassembler.hpp index 8641d8528..8b39bb229 100644 --- a/plugins/builtin/include/content/views/view_disassembler.hpp +++ b/plugins/builtin/include/content/views/view_disassembler.hpp @@ -27,7 +27,6 @@ namespace hex::plugin::builtin { ~ViewDisassembler() override; void drawContent() override; - void drawMenu() override; private: bool m_disassembling = false; diff --git a/plugins/builtin/include/content/views/view_hashes.hpp b/plugins/builtin/include/content/views/view_hashes.hpp index 6ec9c29a7..a469abaaf 100644 --- a/plugins/builtin/include/content/views/view_hashes.hpp +++ b/plugins/builtin/include/content/views/view_hashes.hpp @@ -16,7 +16,6 @@ namespace hex::plugin::builtin { ~ViewHashes() override; void drawContent() override; - void drawMenu() override; private: enum class HashFunctions { Crc8, Crc16, Crc32, Md5, Sha1, Sha224, Sha256, Sha384, Sha512 }; diff --git a/plugins/builtin/include/content/views/view_help.hpp b/plugins/builtin/include/content/views/view_help.hpp index 06bb584f6..feecdd04c 100644 --- a/plugins/builtin/include/content/views/view_help.hpp +++ b/plugins/builtin/include/content/views/view_help.hpp @@ -19,9 +19,8 @@ namespace hex::plugin::builtin { ~ViewHelp() override; void drawContent() override; - void drawMenu() override; - bool isAvailable() const override { return true; } + bool isAvailable() const override { return true; } bool hasViewMenuItemEntry() const override { return false; } ImVec2 getMinSize() const override { diff --git a/plugins/builtin/include/content/views/view_hexeditor.hpp b/plugins/builtin/include/content/views/view_hexeditor.hpp index c025b88b4..3e59dd09f 100644 --- a/plugins/builtin/include/content/views/view_hexeditor.hpp +++ b/plugins/builtin/include/content/views/view_hexeditor.hpp @@ -25,7 +25,6 @@ namespace hex::plugin::builtin { void drawContent() override; void drawAlwaysVisible() override; - void drawMenu() override; private: MemoryEditor m_memoryEditor; @@ -68,6 +67,7 @@ namespace hex::plugin::builtin { void registerEvents(); void registerShortcuts(); + void registerMenuItems(); }; } \ No newline at end of file diff --git a/plugins/builtin/include/content/views/view_information.hpp b/plugins/builtin/include/content/views/view_information.hpp index 364a04c7e..e06d5685a 100644 --- a/plugins/builtin/include/content/views/view_information.hpp +++ b/plugins/builtin/include/content/views/view_information.hpp @@ -18,7 +18,6 @@ namespace hex::plugin::builtin { ~ViewInformation() override; void drawContent() override; - void drawMenu() override; private: bool m_dataValid = false; diff --git a/plugins/builtin/include/content/views/view_patches.hpp b/plugins/builtin/include/content/views/view_patches.hpp index b02e30266..6b6f81603 100644 --- a/plugins/builtin/include/content/views/view_patches.hpp +++ b/plugins/builtin/include/content/views/view_patches.hpp @@ -17,7 +17,6 @@ namespace hex::plugin::builtin { ~ViewPatches() override; void drawContent() override; - void drawMenu() override; private: u64 m_selectedPatch; diff --git a/plugins/builtin/include/content/views/view_pattern_data.hpp b/plugins/builtin/include/content/views/view_pattern_data.hpp index abb868517..eacc184e2 100644 --- a/plugins/builtin/include/content/views/view_pattern_data.hpp +++ b/plugins/builtin/include/content/views/view_pattern_data.hpp @@ -25,7 +25,6 @@ namespace hex::plugin::builtin { ~ViewPatternData() override; void drawContent() override; - void drawMenu() override; private: std::vector m_sortedPatternData; diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index ea10217e8..2a31f62c1 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -20,7 +20,6 @@ namespace hex::plugin::builtin { ViewPatternEditor(); ~ViewPatternEditor() override; - void drawMenu() override; void drawAlwaysVisible() override; void drawContent() override; diff --git a/plugins/builtin/include/content/views/view_settings.hpp b/plugins/builtin/include/content/views/view_settings.hpp index 05b3c5038..f990b0539 100644 --- a/plugins/builtin/include/content/views/view_settings.hpp +++ b/plugins/builtin/include/content/views/view_settings.hpp @@ -13,9 +13,8 @@ namespace hex::plugin::builtin { ~ViewSettings() override; void drawContent() override; - void drawMenu() override; - [[nodiscard]] bool isAvailable() const override { return true; } + [[nodiscard]] bool isAvailable() const override { return true; } [[nodiscard]] bool hasViewMenuItemEntry() const override { return false; } [[nodiscard]] ImVec2 getMinSize() const override { return { 500, 300 }; } diff --git a/plugins/builtin/include/content/views/view_store.hpp b/plugins/builtin/include/content/views/view_store.hpp index ccde59d74..0f082f68c 100644 --- a/plugins/builtin/include/content/views/view_store.hpp +++ b/plugins/builtin/include/content/views/view_store.hpp @@ -33,7 +33,6 @@ namespace hex::plugin::builtin { ~ViewStore() override; void drawContent() override; - void drawMenu() override; [[nodiscard]] bool isAvailable() const override { return true; } [[nodiscard]] bool hasViewMenuItemEntry() const override { return false; } diff --git a/plugins/builtin/include/content/views/view_strings.hpp b/plugins/builtin/include/content/views/view_strings.hpp index ecb59f606..6167d7a84 100644 --- a/plugins/builtin/include/content/views/view_strings.hpp +++ b/plugins/builtin/include/content/views/view_strings.hpp @@ -20,7 +20,6 @@ namespace hex::plugin::builtin { ~ViewStrings() override; void drawContent() override; - void drawMenu() override; private: bool m_searching = false; diff --git a/plugins/builtin/include/content/views/view_tools.hpp b/plugins/builtin/include/content/views/view_tools.hpp index 1e9c86198..0409e5883 100644 --- a/plugins/builtin/include/content/views/view_tools.hpp +++ b/plugins/builtin/include/content/views/view_tools.hpp @@ -18,7 +18,6 @@ namespace hex::plugin::builtin { ~ViewTools() override; void drawContent() override; - void drawMenu() override; }; diff --git a/plugins/builtin/include/content/views/view_yara.hpp b/plugins/builtin/include/content/views/view_yara.hpp index 441301ff4..0cf91bbcd 100644 --- a/plugins/builtin/include/content/views/view_yara.hpp +++ b/plugins/builtin/include/content/views/view_yara.hpp @@ -13,7 +13,6 @@ namespace hex::plugin::builtin { ~ViewYara() override; void drawContent() override; - void drawMenu() override; private: struct YaraMatch { diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index e4f36d4ad..b2e0d7360 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -183,8 +183,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewBookmarks::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_command_palette.cpp b/plugins/builtin/source/content/views/view_command_palette.cpp index 6d0351acc..5723f63bd 100644 --- a/plugins/builtin/source/content/views/view_command_palette.cpp +++ b/plugins/builtin/source/content/views/view_command_palette.cpp @@ -74,10 +74,6 @@ namespace hex::plugin::builtin { } - void ViewCommandPalette::drawMenu() { - - } - std::vector ViewCommandPalette::getCommandResults(const std::string &input) { constexpr auto MatchCommand = [](const std::string &currCommand, const std::string &commandToMatch) -> std::pair { if (currCommand.empty()) { diff --git a/plugins/builtin/source/content/views/view_constants.cpp b/plugins/builtin/source/content/views/view_constants.cpp index 58d464cc6..40af8eb61 100644 --- a/plugins/builtin/source/content/views/view_constants.cpp +++ b/plugins/builtin/source/content/views/view_constants.cpp @@ -153,8 +153,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewConstants::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index e893947c5..99831929e 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -120,8 +120,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewDataInspector::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_data_processor.cpp b/plugins/builtin/source/content/views/view_data_processor.cpp index 15ed16cc3..75893472e 100644 --- a/plugins/builtin/source/content/views/view_data_processor.cpp +++ b/plugins/builtin/source/content/views/view_data_processor.cpp @@ -369,10 +369,6 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewDataProcessor::drawMenu() { - - } - std::string ViewDataProcessor::saveNodes() { using json = nlohmann::json; json output; diff --git a/plugins/builtin/source/content/views/view_diff.cpp b/plugins/builtin/source/content/views/view_diff.cpp index c636b4b73..bcd30012c 100644 --- a/plugins/builtin/source/content/views/view_diff.cpp +++ b/plugins/builtin/source/content/views/view_diff.cpp @@ -229,8 +229,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewDiff::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_disassembler.cpp b/plugins/builtin/source/content/views/view_disassembler.cpp index 8da63aae3..57e8417c5 100644 --- a/plugins/builtin/source/content/views/view_disassembler.cpp +++ b/plugins/builtin/source/content/views/view_disassembler.cpp @@ -317,8 +317,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewDisassembler::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_hashes.cpp b/plugins/builtin/source/content/views/view_hashes.cpp index 929cbcdcc..bdd8aa038 100644 --- a/plugins/builtin/source/content/views/view_hashes.cpp +++ b/plugins/builtin/source/content/views/view_hashes.cpp @@ -300,8 +300,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewHashes::drawMenu() { - - } - } diff --git a/plugins/builtin/source/content/views/view_help.cpp b/plugins/builtin/source/content/views/view_help.cpp index e99152f7e..ec54a9789 100644 --- a/plugins/builtin/source/content/views/view_help.cpp +++ b/plugins/builtin/source/content/views/view_help.cpp @@ -9,6 +9,19 @@ namespace hex::plugin::builtin { ViewHelp::ViewHelp() : View("hex.builtin.view.help.about.name") { + + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.help", 1000, [&, this] { + if (ImGui::MenuItem("hex.builtin.view.help.about.name"_lang, "")) { + View::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.help.about.name").c_str()); }); + this->m_aboutWindowOpen = true; + this->getWindowOpenState() = true; + } + + if (ImGui::MenuItem("hex.builtin.view.help.documentation"_lang, "")) { + hex::openWebpage("https://imhex.werwolv.net/docs"); + } + }); + } ViewHelp::~ViewHelp() { @@ -171,18 +184,4 @@ namespace hex::plugin::builtin { this->drawAboutPopup(); } - void ViewHelp::drawMenu() { - if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) { - if (ImGui::MenuItem("hex.builtin.view.help.about.name"_lang, "")) { - View::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.help.about.name").c_str()); }); - this->m_aboutWindowOpen = true; - this->getWindowOpenState() = true; - } - if (ImGui::MenuItem("hex.builtin.view.help.documentation"_lang, "")) { - hex::openWebpage("https://imhex.werwolv.net/docs"); - } - ImGui::EndMenu(); - } - } - } diff --git a/plugins/builtin/source/content/views/view_hexeditor.cpp b/plugins/builtin/source/content/views/view_hexeditor.cpp index c0a2546c4..76925eee9 100644 --- a/plugins/builtin/source/content/views/view_hexeditor.cpp +++ b/plugins/builtin/source/content/views/view_hexeditor.cpp @@ -156,6 +156,7 @@ namespace hex::plugin::builtin { registerEvents(); registerShortcuts(); + registerMenuItems(); } ViewHexEditor::~ViewHexEditor() { @@ -359,275 +360,6 @@ namespace hex::plugin::builtin { } } - void ViewHexEditor::drawMenu() { - auto provider = ImHexApi::Provider::get(); - bool providerValid = ImHexApi::Provider::isValid(); - - if (ImGui::BeginMenu("hex.builtin.menu.file"_lang)) { - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) { - - hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [](const auto &path) { - EventManager::post(path); - }); - } - - if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.open_recent"_lang, !SharedData::recentFilePaths.empty())) { - for (auto &path : SharedData::recentFilePaths) { - if (ImGui::MenuItem(fs::path(path).filename().string().c_str())) { - EventManager::post(path); - } - } - - ImGui::Separator(); - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.clear_recent"_lang)) { - SharedData::recentFilePaths.clear(); - ContentRegistry::Settings::write( - "hex.builtin.setting.imhex", - "hex.builtin.setting.imhex.recent_files", - std::vector{}); - } - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.open_other"_lang)) { - - for (const auto &unlocalizedProviderName : ContentRegistry::Provider::getEntries()) { - if (ImGui::MenuItem(LangEntry(unlocalizedProviderName))) { - EventManager::post(unlocalizedProviderName, nullptr); - } - } - - ImGui::EndMenu(); - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.save"_lang, "CTRL + S", false, providerValid && provider->isWritable())) { - save(); - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.save_as"_lang, "CTRL + SHIFT + S", false, providerValid && provider->isWritable())) { - saveAs(); - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.close"_lang, "", false, providerValid)) { - EventManager::post(); - ImHexApi::Provider::remove(ImHexApi::Provider::get()); - providerValid = false; - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.quit"_lang, "", false)) { - ImHexApi::Common::closeImHex(); - } - - ImGui::Separator(); - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.open_project"_lang, "")) { - hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.open_project"_lang, DialogMode::Open, { { "Project File", "hexproj" } }, [](const auto &path) { - ProjectFile::load(path); - }); - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.save_project"_lang, "", false, providerValid && provider->isWritable())) { - if (ProjectFile::getProjectFilePath() == "") { - hex::openFileBrowser("hex.builtin.view.hexeditor.save_project"_lang, DialogMode::Save, { { "Project File", "hexproj" } }, [](const auto &path) { - if (path.extension() == ".hexproj") { - ProjectFile::store(path); - } - else { - ProjectFile::store(path.string() + ".hexproj"); - } - }); - } - else - ProjectFile::store(); - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.load_encoding_file"_lang)) { - hex::openFileBrowser("hex.builtin.view.hexeditor.load_enconding_file"_lang, DialogMode::Open, { { "Thingy Table File", "tbl" } }, [this](const auto &path) { - this->m_currEncodingFile = EncodingFile(EncodingFile::Type::Thingy, path); - }); - } - - ImGui::Separator(); - - if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.import"_lang)) { - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.base64"_lang)) { - - hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.import.base64"_lang, DialogMode::Open, { }, [this](const auto &path) { - File file(path, File::Mode::Read); - if (!file.isValid()) { - View::showErrorPopup("hex.builtin.view.hexeditor.error.open"_lang); - return; - } - - auto base64 = file.readBytes(); - - if (!base64.empty()) { - this->m_dataToSave = crypt::decode64(base64); - - if (this->m_dataToSave.empty()) - View::showErrorPopup("hex.builtin.view.hexeditor.base64.import_error"_lang); - else - ImGui::OpenPopup("hex.builtin.view.hexeditor.save_data"_lang); - this->getWindowOpenState() = true; - } else View::showErrorPopup("hex.builtin.view.hexeditor.file_open_error"_lang); - }); - } - - ImGui::Separator(); - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.ips"_lang, nullptr, false, !this->m_processingImportExport)) { - - hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](const auto &path) { - this->m_processingImportExport = true; - std::thread([this, path] { - auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); - - auto patchData = File(path, File::Mode::Read).readBytes(); - auto patch = hex::loadIPSPatch(patchData); - - task.setMaxValue(patch.size()); - - auto provider = ImHexApi::Provider::get(); - - u64 progress = 0; - for (auto &[address, value] : patch) { - provider->addPatch(address, &value, 1); - progress++; - task.update(progress); - } - - provider->createUndoPoint(); - this->m_processingImportExport = false; - }).detach(); - - this->getWindowOpenState() = true; - }); - - - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.ips32"_lang, nullptr, false, !this->m_processingImportExport)) { - hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](const auto &path) { - this->m_processingImportExport = true; - std::thread([this, path] { - auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); - - auto patchData = File(path, File::Mode::Read).readBytes(); - auto patch = hex::loadIPS32Patch(patchData); - - task.setMaxValue(patch.size()); - - auto provider = ImHexApi::Provider::get(); - - u64 progress = 0; - for (auto &[address, value] : patch) { - provider->addPatch(address, &value, 1); - progress++; - task.update(progress); - } - - provider->createUndoPoint(); - this->m_processingImportExport = false; - }).detach(); - - this->getWindowOpenState() = true; - }); - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.script"_lang)) { - this->m_loaderScriptFilePath.clear(); - this->m_loaderScriptScriptPath.clear(); - View::doLater([]{ ImGui::OpenPopup("hex.builtin.view.hexeditor.script.title"_lang); }); - } - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.export"_lang, providerValid && provider->isWritable())) { - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.export.ips"_lang, nullptr, false, !this->m_processingImportExport)) { - Patches patches = provider->getPatches(); - if (!patches.contains(0x00454F45) && patches.contains(0x00454F46)) { - u8 value = 0; - provider->read(0x00454F45, &value, sizeof(u8)); - patches[0x00454F45] = value; - } - - this->m_processingImportExport = true; - std::thread([this, patches]{ - auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); - - this->m_dataToSave = generateIPSPatch(patches); - this->m_processingImportExport = false; - - View::doLater([this]{ - hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.export.title"_lang, DialogMode::Save, { }, [this](const auto &path) { - auto file = File(path, File::Mode::Create); - if (!file.isValid()) { - View::showErrorPopup("hex.builtin.view.hexeditor.error.create"_lang); - return; - } - - file.write(this->m_dataToSave); - }); - }); - }).detach(); - } - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.export.ips32"_lang, nullptr, false, !this->m_processingImportExport)) { - Patches patches = provider->getPatches(); - if (!patches.contains(0x00454F45) && patches.contains(0x45454F46)) { - u8 value = 0; - provider->read(0x45454F45, &value, sizeof(u8)); - patches[0x45454F45] = value; - } - - this->m_processingImportExport = true; - std::thread([this, patches]{ - auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); - - this->m_dataToSave = generateIPS32Patch(patches); - this->m_processingImportExport = false; - - View::doLater([this]{ - hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.export.title"_lang, DialogMode::Save, { }, [this](const auto &path) { - auto file = File(path, File::Mode::Create); - if (!file.isValid()) { - View::showErrorPopup("hex.builtin.view.hexeditor.error.create"_lang); - return; - } - - file.write(this->m_dataToSave); - }); - }); - }).detach(); - } - - ImGui::EndMenu(); - } - - - - ImGui::Separator(); - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.search"_lang, "CTRL + F")) { - this->getWindowOpenState() = true; - ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.search"_lang); - } - - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.goto"_lang, "CTRL + G")) { - this->getWindowOpenState() = true; - ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.goto"_lang); - } - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("hex.builtin.menu.edit"_lang)) { - this->drawEditPopup(); - ImGui::EndMenu(); - } - } - void ViewHexEditor::openFile(const fs::path &path) { hex::prv::Provider *provider = nullptr; EventManager::post("hex.builtin.provider.file", &provider); @@ -1225,4 +957,288 @@ namespace hex::plugin::builtin { } + void ViewHexEditor::registerMenuItems() { + + /* Basic operations */ + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1000, [&]{ + auto provider = ImHexApi::Provider::get(); + bool providerValid = ImHexApi::Provider::isValid(); + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) { + + hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [](const auto &path) { + EventManager::post(path); + }); + } + + if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.open_recent"_lang, !SharedData::recentFilePaths.empty())) { + for (auto &path : SharedData::recentFilePaths) { + if (ImGui::MenuItem(fs::path(path).filename().string().c_str())) { + EventManager::post(path); + } + } + + ImGui::Separator(); + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.clear_recent"_lang)) { + SharedData::recentFilePaths.clear(); + ContentRegistry::Settings::write( + "hex.builtin.setting.imhex", + "hex.builtin.setting.imhex.recent_files", + std::vector{}); + } + + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.open_other"_lang)) { + + for (const auto &unlocalizedProviderName : ContentRegistry::Provider::getEntries()) { + if (ImGui::MenuItem(LangEntry(unlocalizedProviderName))) { + EventManager::post(unlocalizedProviderName, nullptr); + } + } + + ImGui::EndMenu(); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.save"_lang, "CTRL + S", false, providerValid && provider->isWritable())) { + save(); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.save_as"_lang, "CTRL + SHIFT + S", false, providerValid && provider->isWritable())) { + saveAs(); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.close"_lang, "", false, providerValid)) { + EventManager::post(); + ImHexApi::Provider::remove(ImHexApi::Provider::get()); + providerValid = false; + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.quit"_lang, "", false)) { + ImHexApi::Common::closeImHex(); + } + }); + + + /* Metadata save/load */ + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1100, [&, this] { + auto provider = ImHexApi::Provider::get(); + bool providerValid = ImHexApi::Provider::isValid(); + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.open_project"_lang, "")) { + hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.open_project"_lang, DialogMode::Open, { { "Project File", "hexproj" } }, [](const auto &path) { + ProjectFile::load(path); + }); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.save_project"_lang, "", false, providerValid && provider->isWritable())) { + if (ProjectFile::getProjectFilePath() == "") { + hex::openFileBrowser("hex.builtin.view.hexeditor.save_project"_lang, DialogMode::Save, { { "Project File", "hexproj" } }, [](const auto &path) { + if (path.extension() == ".hexproj") { + ProjectFile::store(path); + } + else { + ProjectFile::store(path.string() + ".hexproj"); + } + }); + } + else + ProjectFile::store(); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.load_encoding_file"_lang)) { + hex::openFileBrowser("hex.builtin.view.hexeditor.load_enconding_file"_lang, DialogMode::Open, { { "Thingy Table File", "tbl" } }, [this](const auto &path) { + this->m_currEncodingFile = EncodingFile(EncodingFile::Type::Thingy, path); + }); + } + }); + + + /* Import / Export */ + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1200, [&, this] { + auto provider = ImHexApi::Provider::get(); + bool providerValid = ImHexApi::Provider::isValid(); + + /* Import */ + if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.import"_lang)) { + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.base64"_lang)) { + + hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.import.base64"_lang, DialogMode::Open, { }, [this](const auto &path) { + File file(path, File::Mode::Read); + if (!file.isValid()) { + View::showErrorPopup("hex.builtin.view.hexeditor.error.open"_lang); + return; + } + + auto base64 = file.readBytes(); + + if (!base64.empty()) { + this->m_dataToSave = crypt::decode64(base64); + + if (this->m_dataToSave.empty()) + View::showErrorPopup("hex.builtin.view.hexeditor.base64.import_error"_lang); + else + ImGui::OpenPopup("hex.builtin.view.hexeditor.save_data"_lang); + this->getWindowOpenState() = true; + } else View::showErrorPopup("hex.builtin.view.hexeditor.file_open_error"_lang); + }); + } + + ImGui::Separator(); + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.ips"_lang, nullptr, false, !this->m_processingImportExport)) { + + hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](const auto &path) { + this->m_processingImportExport = true; + std::thread([this, path] { + auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); + + auto patchData = File(path, File::Mode::Read).readBytes(); + auto patch = hex::loadIPSPatch(patchData); + + task.setMaxValue(patch.size()); + + auto provider = ImHexApi::Provider::get(); + + u64 progress = 0; + for (auto &[address, value] : patch) { + provider->addPatch(address, &value, 1); + progress++; + task.update(progress); + } + + provider->createUndoPoint(); + this->m_processingImportExport = false; + }).detach(); + + this->getWindowOpenState() = true; + }); + + + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.ips32"_lang, nullptr, false, !this->m_processingImportExport)) { + hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](const auto &path) { + this->m_processingImportExport = true; + std::thread([this, path] { + auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); + + auto patchData = File(path, File::Mode::Read).readBytes(); + auto patch = hex::loadIPS32Patch(patchData); + + task.setMaxValue(patch.size()); + + auto provider = ImHexApi::Provider::get(); + + u64 progress = 0; + for (auto &[address, value] : patch) { + provider->addPatch(address, &value, 1); + progress++; + task.update(progress); + } + + provider->createUndoPoint(); + this->m_processingImportExport = false; + }).detach(); + + this->getWindowOpenState() = true; + }); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.import.script"_lang)) { + this->m_loaderScriptFilePath.clear(); + this->m_loaderScriptScriptPath.clear(); + View::doLater([]{ ImGui::OpenPopup("hex.builtin.view.hexeditor.script.title"_lang); }); + } + + ImGui::EndMenu(); + } + + + /* Export */ + if (ImGui::BeginMenu("hex.builtin.view.hexeditor.menu.file.export"_lang, providerValid && provider->isWritable())) { + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.export.ips"_lang, nullptr, false, !this->m_processingImportExport)) { + Patches patches = provider->getPatches(); + if (!patches.contains(0x00454F45) && patches.contains(0x00454F46)) { + u8 value = 0; + provider->read(0x00454F45, &value, sizeof(u8)); + patches[0x00454F45] = value; + } + + this->m_processingImportExport = true; + std::thread([this, patches]{ + auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); + + this->m_dataToSave = generateIPSPatch(patches); + this->m_processingImportExport = false; + + View::doLater([this]{ + hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.export.title"_lang, DialogMode::Save, { }, [this](const auto &path) { + auto file = File(path, File::Mode::Create); + if (!file.isValid()) { + View::showErrorPopup("hex.builtin.view.hexeditor.error.create"_lang); + return; + } + + file.write(this->m_dataToSave); + }); + }); + }).detach(); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.export.ips32"_lang, nullptr, false, !this->m_processingImportExport)) { + Patches patches = provider->getPatches(); + if (!patches.contains(0x00454F45) && patches.contains(0x45454F46)) { + u8 value = 0; + provider->read(0x45454F45, &value, sizeof(u8)); + patches[0x45454F45] = value; + } + + this->m_processingImportExport = true; + std::thread([this, patches]{ + auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hexeditor.processing", 0); + + this->m_dataToSave = generateIPS32Patch(patches); + this->m_processingImportExport = false; + + View::doLater([this]{ + hex::openFileBrowser("hex.builtin.view.hexeditor.menu.file.export.title"_lang, DialogMode::Save, { }, [this](const auto &path) { + auto file = File(path, File::Mode::Create); + if (!file.isValid()) { + View::showErrorPopup("hex.builtin.view.hexeditor.error.create"_lang); + return; + } + + file.write(this->m_dataToSave); + }); + }); + }).detach(); + } + + ImGui::EndMenu(); + } + }); + + + /* Search / Goto */ + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1300, [&, this] { + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.search"_lang, "CTRL + F")) { + this->getWindowOpenState() = true; + ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.search"_lang); + } + + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.goto"_lang, "CTRL + G")) { + this->getWindowOpenState() = true; + ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.goto"_lang); + } + }); + + + /* Edit menu */ + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.edit", 1000, [&, this] { + this->drawEditPopup(); + }); + } + } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index 73b2bab19..1c642123a 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -233,8 +233,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewInformation::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_patches.cpp b/plugins/builtin/source/content/views/view_patches.cpp index 5695c8074..7a6d709ec 100644 --- a/plugins/builtin/source/content/views/view_patches.cpp +++ b/plugins/builtin/source/content/views/view_patches.cpp @@ -98,8 +98,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewPatches::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_pattern_data.cpp b/plugins/builtin/source/content/views/view_pattern_data.cpp index cfc95e4f5..b623742dc 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -69,8 +69,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewPatternData::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index ad018bfd0..e1f53d735 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -194,25 +194,8 @@ namespace hex::plugin::builtin { return false; } }); - } - - ViewPatternEditor::~ViewPatternEditor() { - delete this->m_evaluatorRuntime; - delete this->m_parserRuntime; - - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - EventManager::unsubscribe(this); - } - - void ViewPatternEditor::drawMenu() { - if (ImGui::BeginMenu("hex.builtin.menu.file"_lang)) { - - ImGui::Separator(); + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 2000, [&, this] { if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.load_pattern"_lang)) { this->m_selectedPatternFile = 0; @@ -238,9 +221,19 @@ namespace hex::plugin::builtin { file.write(this->m_textEditor.GetText()); }); } + }); + } - ImGui::EndMenu(); - } + ViewPatternEditor::~ViewPatternEditor() { + delete this->m_evaluatorRuntime; + delete this->m_parserRuntime; + + EventManager::unsubscribe(this); + EventManager::unsubscribe(this); + EventManager::unsubscribe(this); + EventManager::unsubscribe(this); + EventManager::unsubscribe(this); + EventManager::unsubscribe(this); } void ViewPatternEditor::drawContent() { diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index a279c5522..9a93b86f4 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -13,6 +13,13 @@ namespace hex::plugin::builtin { this->getWindowOpenState() = true; } }); + + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.help", 2000, [&, this] { + if (ImGui::MenuItem("hex.builtin.view.settings.name"_lang)) { + View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.view.settings.name").c_str()); }); + this->getWindowOpenState() = true; + } + }); } ViewSettings::~ViewSettings() { @@ -45,18 +52,4 @@ namespace hex::plugin::builtin { } - void ViewSettings::drawMenu() { - if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) { - - ImGui::Separator(); - - if (ImGui::MenuItem("hex.builtin.view.settings.name"_lang)) { - View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.view.settings.name").c_str()); }); - this->getWindowOpenState() = true; - } - - ImGui::EndMenu(); - } - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_store.cpp b/plugins/builtin/source/content/views/view_store.cpp index 279413423..50dea4caf 100644 --- a/plugins/builtin/source/content/views/view_store.cpp +++ b/plugins/builtin/source/content/views/view_store.cpp @@ -24,6 +24,13 @@ namespace hex::plugin::builtin { ViewStore::ViewStore() : View("hex.builtin.view.store.name") { this->refresh(); + + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.help", 3000, [&, this] { + if (ImGui::MenuItem("hex.builtin.view.store.name"_lang)) { + View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.view.store.name").c_str()); }); + this->getWindowOpenState() = true; + } + }); } ViewStore::~ViewStore() { } @@ -234,18 +241,6 @@ namespace hex::plugin::builtin { } } - void ViewStore::drawMenu() { - if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) { - if (ImGui::MenuItem("hex.builtin.view.store.name"_lang)) { - View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.view.store.name").c_str()); }); - this->getWindowOpenState() = true; - } - - ImGui::EndMenu(); - } - } - - void ViewStore::download(ImHexPath pathType, const std::string &fileName, const std::string &url, bool update) { if (!update) { this->m_downloadPath = hex::getPath(pathType).back() / fs::path(fileName); diff --git a/plugins/builtin/source/content/views/view_strings.cpp b/plugins/builtin/source/content/views/view_strings.cpp index 99296481e..cd431c037 100644 --- a/plugins/builtin/source/content/views/view_strings.cpp +++ b/plugins/builtin/source/content/views/view_strings.cpp @@ -242,8 +242,4 @@ namespace hex::plugin::builtin { } } - void ViewStrings::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_tools.cpp b/plugins/builtin/source/content/views/view_tools.cpp index 096df0404..9fb4df849 100644 --- a/plugins/builtin/source/content/views/view_tools.cpp +++ b/plugins/builtin/source/content/views/view_tools.cpp @@ -19,8 +19,4 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewTools::drawMenu() { - - } - } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_yara.cpp b/plugins/builtin/source/content/views/view_yara.cpp index 699179d34..93f44e569 100644 --- a/plugins/builtin/source/content/views/view_yara.cpp +++ b/plugins/builtin/source/content/views/view_yara.cpp @@ -129,10 +129,6 @@ namespace hex::plugin::builtin { ImGui::End(); } - void ViewYara::drawMenu() { - - } - void ViewYara::reloadRules() { this->m_rules.clear(); diff --git a/plugins/windows/include/views/view_tty_console.hpp b/plugins/windows/include/views/view_tty_console.hpp index 233898833..d1edb2c0c 100644 --- a/plugins/windows/include/views/view_tty_console.hpp +++ b/plugins/windows/include/views/view_tty_console.hpp @@ -18,7 +18,6 @@ namespace hex::plugin::windows { ~ViewTTYConsole() override; void drawContent() override; - void drawMenu() override; private: std::vector> m_comPorts; diff --git a/plugins/windows/source/views/view_tty_console.cpp b/plugins/windows/source/views/view_tty_console.cpp index 23ca3aef9..996748a79 100644 --- a/plugins/windows/source/views/view_tty_console.cpp +++ b/plugins/windows/source/views/view_tty_console.cpp @@ -157,10 +157,6 @@ namespace hex::plugin::windows { ImGui::End(); } - void ViewTTYConsole::drawMenu() { - - } - std::vector> ViewTTYConsole::getAvailablePorts() { std::vector> result; std::vector buffer(0xFFF, 0x00);