1
0
mirror of synced 2024-11-24 15:50:16 +01:00

impr: Disable some more menu items when they're not useful

This commit is contained in:
WerWolv 2023-11-24 20:57:37 +01:00
parent b050039e35
commit 3c36ef2c69
4 changed files with 46 additions and 39 deletions

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -1178,6 +1178,9 @@ namespace hex::plugin::builtin {
);
}
}
},
[] {
return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid();
});
/* Paste */

View File

@ -1203,8 +1203,9 @@ 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,
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))
@ -1218,13 +1219,14 @@ namespace hex::plugin::builtin {
appendArray(type, size);
ImGui::EndMenu();
}
}, [this] {
return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && this->m_runningParsers == 0;
});
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] {
ImGui::EndMenu();
}
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(); });
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin"_lang, hasPlaceableTypes)) {
auto selection = ImHexApi::HexEditor::getSelection();
for (const auto &[typeName, type] : types) {
@ -1240,11 +1242,11 @@ namespace hex::plugin::builtin {
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(); });
return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && this->m_runningParsers == 0 && hasPlaceableTypes;
ImGui::EndMenu();
}
}, [this] {
return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && this->m_runningParsers == 0;
});
}