diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 6bc3bbde0..b43892092 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -241,7 +241,9 @@ namespace hex { if (ImGui::MenuItem(Lang(name), shortcut.toString().c_str(), false, enabledCallback())) callback(); } else { - if (ImGui::BeginMenu(Lang(name), *(menuItems.begin() + 1) == ContentRegistry::Interface::impl::SubMenuValue ? enabledCallback() : true)) { + bool isSubmenu = *(menuItems.begin() + 1) == ContentRegistry::Interface::impl::SubMenuValue; + + if (ImGui::BeginMenu(Lang(name), isSubmenu ? enabledCallback() : true)) { createNestedMenu({ menuItems.begin() + 1, menuItems.end() }, shortcut, callback, enabledCallback); ImGui::EndMenu(); } diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp index 320edd2f2..5baf14702 100644 --- a/plugins/builtin/source/content/main_menu_items.cpp +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -513,7 +513,7 @@ namespace hex::plugin::builtin { if (view->hasViewMenuItemEntry()) { auto &state = view->getWindowOpenState(); - if (ImGui::MenuItem(Lang(view->getUnlocalizedName()), "", &state)) + if (ImGui::MenuItem(Lang(view->getUnlocalizedName()), "", &state, ImHexApi::Provider::isValid())) view->setWindowJustOpened(state); } } diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 61935a9be..e8a942098 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -1178,6 +1178,9 @@ namespace hex::plugin::builtin { ); } } + }, + [] { + return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid(); }); /* Paste */ diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index b2d44588d..d2e9c6c63 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1203,49 +1203,51 @@ namespace hex::plugin::builtin { }}; /* Place pattern... */ - ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.edit.place_pattern", "hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin" }, 3000, - [&, this] { - if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.single"_lang)) { - for (const auto &[type, size] : Types) - if (ImGui::MenuItem(type)) - appendVariable(type); - ImGui::EndMenu(); - } + ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.edit.place_pattern" }, 3000, + [&, this] { + if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin"_lang)) { + if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.single"_lang)) { + for (const auto &[type, size] : Types) + if (ImGui::MenuItem(type)) + appendVariable(type); + ImGui::EndMenu(); + } - if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.array"_lang)) { - for (const auto &[type, size] : Types) - if (ImGui::MenuItem(type)) - appendArray(type, size); - ImGui::EndMenu(); - } - }, [this] { - return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && this->m_runningParsers == 0; - }); + if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.array"_lang)) { + for (const auto &[type, size] : Types) + if (ImGui::MenuItem(type)) + appendArray(type, size); + ImGui::EndMenu(); + } - ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.edit.place_pattern", "hex.builtin.view.pattern_editor.menu.edit.place_pattern.custom" }, 3050, - [&, this] { - const auto &types = this->m_parserRuntime->getInternals().parser->getTypes(); - auto selection = ImHexApi::HexEditor::getSelection(); + ImGui::EndMenu(); + } - for (const auto &[typeName, type] : types) { - if (type->isTemplateType()) - continue; + const auto &types = this->m_parserRuntime->getInternals().parser->getTypes(); + bool hasPlaceableTypes = std::any_of(types.begin(), types.end(), [](const auto &type) { return !type.second->isTemplateType(); }); - createNestedMenu(hex::splitString(typeName, "::"), [&, this] { - std::string variableName; - for (char &c : hex::replaceStrings(typeName, "::", "_")) - variableName += static_cast(std::tolower(c)); - variableName += hex::format("_at_0x{:02X}", selection->getStartAddress()); + if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin"_lang, hasPlaceableTypes)) { + auto selection = ImHexApi::HexEditor::getSelection(); - appendEditorText(hex::format("{0} {1} @ 0x{2:02X};", typeName, variableName, selection->getStartAddress())); - }); - } - }, [this] { - const auto &types = this->m_parserRuntime->getInternals().parser->getTypes(); - bool hasPlaceableTypes = std::any_of(types.begin(), types.end(), [](const auto &type) { return !type.second->isTemplateType(); }); + for (const auto &[typeName, type] : types) { + if (type->isTemplateType()) + continue; - return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && this->m_runningParsers == 0 && hasPlaceableTypes; - }); + createNestedMenu(hex::splitString(typeName, "::"), [&, this] { + std::string variableName; + for (char &c : hex::replaceStrings(typeName, "::", "_")) + variableName += static_cast(std::tolower(c)); + variableName += hex::format("_at_0x{:02X}", selection->getStartAddress()); + + appendEditorText(hex::format("{0} {1} @ 0x{2:02X};", typeName, variableName, selection->getStartAddress())); + }); + } + + ImGui::EndMenu(); + } + }, [this] { + return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && this->m_runningParsers == 0; + }); } void ViewPatternEditor::registerHandlers() {