impr: Disable some more menu items when they're not useful
This commit is contained in:
parent
b050039e35
commit
3c36ef2c69
@ -241,7 +241,9 @@ namespace hex {
|
|||||||
if (ImGui::MenuItem(Lang(name), shortcut.toString().c_str(), false, enabledCallback()))
|
if (ImGui::MenuItem(Lang(name), shortcut.toString().c_str(), false, enabledCallback()))
|
||||||
callback();
|
callback();
|
||||||
} else {
|
} 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);
|
createNestedMenu({ menuItems.begin() + 1, menuItems.end() }, shortcut, callback, enabledCallback);
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,7 @@ namespace hex::plugin::builtin {
|
|||||||
if (view->hasViewMenuItemEntry()) {
|
if (view->hasViewMenuItemEntry()) {
|
||||||
auto &state = view->getWindowOpenState();
|
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->setWindowJustOpened(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1178,6 +1178,9 @@ namespace hex::plugin::builtin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[] {
|
||||||
|
return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid();
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Paste */
|
/* Paste */
|
||||||
|
@ -1203,49 +1203,51 @@ namespace hex::plugin::builtin {
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
/* Place pattern... */
|
/* 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] {
|
[&, this] {
|
||||||
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.single"_lang)) {
|
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin"_lang)) {
|
||||||
for (const auto &[type, size] : Types)
|
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.single"_lang)) {
|
||||||
if (ImGui::MenuItem(type))
|
for (const auto &[type, size] : Types)
|
||||||
appendVariable(type);
|
if (ImGui::MenuItem(type))
|
||||||
ImGui::EndMenu();
|
appendVariable(type);
|
||||||
}
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.array"_lang)) {
|
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.array"_lang)) {
|
||||||
for (const auto &[type, size] : Types)
|
for (const auto &[type, size] : Types)
|
||||||
if (ImGui::MenuItem(type))
|
if (ImGui::MenuItem(type))
|
||||||
appendArray(type, size);
|
appendArray(type, size);
|
||||||
ImGui::EndMenu();
|
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,
|
ImGui::EndMenu();
|
||||||
[&, this] {
|
}
|
||||||
const auto &types = this->m_parserRuntime->getInternals().parser->getTypes();
|
|
||||||
auto selection = ImHexApi::HexEditor::getSelection();
|
|
||||||
|
|
||||||
for (const auto &[typeName, type] : types) {
|
const auto &types = this->m_parserRuntime->getInternals().parser->getTypes();
|
||||||
if (type->isTemplateType())
|
bool hasPlaceableTypes = std::any_of(types.begin(), types.end(), [](const auto &type) { return !type.second->isTemplateType(); });
|
||||||
continue;
|
|
||||||
|
|
||||||
createNestedMenu(hex::splitString(typeName, "::"), [&, this] {
|
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin"_lang, hasPlaceableTypes)) {
|
||||||
std::string variableName;
|
auto selection = ImHexApi::HexEditor::getSelection();
|
||||||
for (char &c : hex::replaceStrings(typeName, "::", "_"))
|
|
||||||
variableName += static_cast<char>(std::tolower(c));
|
|
||||||
variableName += hex::format("_at_0x{:02X}", selection->getStartAddress());
|
|
||||||
|
|
||||||
appendEditorText(hex::format("{0} {1} @ 0x{2:02X};", typeName, variableName, selection->getStartAddress()));
|
for (const auto &[typeName, type] : types) {
|
||||||
});
|
if (type->isTemplateType())
|
||||||
}
|
continue;
|
||||||
}, [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;
|
createNestedMenu(hex::splitString(typeName, "::"), [&, this] {
|
||||||
});
|
std::string variableName;
|
||||||
|
for (char &c : hex::replaceStrings(typeName, "::", "_"))
|
||||||
|
variableName += static_cast<char>(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() {
|
void ViewPatternEditor::registerHandlers() {
|
||||||
|
Loading…
Reference in New Issue
Block a user