mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
fix: Wrong menu items getting triggered when same shortcut is defined in multiple views
This commit is contained in:
@@ -867,7 +867,7 @@ EXPORT_MODULE namespace hex {
|
||||
const std::vector<UnlocalizedString> &unlocalizedMainMenuNames,
|
||||
const Icon &icon,
|
||||
u32 priority,
|
||||
const Shortcut &shortcut,
|
||||
Shortcut shortcut,
|
||||
const impl::MenuCallback &function,
|
||||
const impl::EnabledCallback& enabledCallback = []{ return true; },
|
||||
const impl::SelectedCallback &selectedCallback = []{ return false; },
|
||||
|
||||
@@ -950,7 +950,7 @@ namespace hex {
|
||||
addMenuItem(unlocalizedMainMenuNames, "", priority, shortcut, function, enabledCallback, []{ return false; }, view);
|
||||
}
|
||||
|
||||
void addMenuItem(const std::vector<UnlocalizedString> &unlocalizedMainMenuNames, const Icon &icon, u32 priority, const Shortcut &shortcut, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback, const impl::SelectedCallback &selectedCallback, View *view) {
|
||||
void addMenuItem(const std::vector<UnlocalizedString> &unlocalizedMainMenuNames, const Icon &icon, u32 priority, Shortcut shortcut, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback, const impl::SelectedCallback &selectedCallback, View *view) {
|
||||
log::debug("Added new menu item to menu {} with priority {}", unlocalizedMainMenuNames[0].get(), priority);
|
||||
|
||||
Icon coloredIcon = icon;
|
||||
@@ -962,6 +962,10 @@ namespace hex {
|
||||
});
|
||||
|
||||
if (shortcut != Shortcut::None) {
|
||||
if (view != nullptr && !shortcut.isLocal()) {
|
||||
shortcut += CurrentView;
|
||||
}
|
||||
|
||||
if (shortcut.isLocal() && view != nullptr)
|
||||
ShortcutManager::addShortcut(view, shortcut, unlocalizedMainMenuNames, function, enabledCallback);
|
||||
else
|
||||
|
||||
@@ -421,22 +421,22 @@ namespace hex::plugin::builtin {
|
||||
|
||||
/* Import */
|
||||
{
|
||||
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.file", "hex.builtin.menu.file.import" }, ICON_VS_SIGN_IN, 2140, []{}, noRunningTaskAndValidProvider);
|
||||
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.file", "hex.builtin.menu.file.import" }, ICON_VS_SIGN_IN, 5140, []{}, noRunningTaskAndValidProvider);
|
||||
|
||||
/* IPS */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.ips"}, ICON_VS_GIT_PULL_REQUEST_NEW_CHANGES, 2150,
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.ips"}, ICON_VS_GIT_PULL_REQUEST_NEW_CHANGES, 5150,
|
||||
Shortcut::None,
|
||||
importIPSPatch,
|
||||
noRunningTaskAndWritableProvider);
|
||||
|
||||
/* IPS32 */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.ips32"}, ICON_VS_GIT_PULL_REQUEST_NEW_CHANGES, 2200,
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.ips32"}, ICON_VS_GIT_PULL_REQUEST_NEW_CHANGES, 5200,
|
||||
Shortcut::None,
|
||||
importIPS32Patch,
|
||||
noRunningTaskAndWritableProvider);
|
||||
|
||||
/* Modified File */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.modified_file" }, ICON_VS_FILES, 2300,
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.modified_file" }, ICON_VS_FILES, 5300,
|
||||
Shortcut::None,
|
||||
importModifiedFile,
|
||||
noRunningTaskAndWritableProvider);
|
||||
|
||||
@@ -606,10 +606,10 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Views::getViewByName("hex.builtin.view.hex_editor.name"));
|
||||
|
||||
|
||||
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.file", "hex.builtin.menu.file.import" }, 3000);
|
||||
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.file", "hex.builtin.menu.file.import" }, 5400);
|
||||
|
||||
/* Import bookmarks */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.bookmark" }, ICON_VS_BOOKMARK, 3050, Shortcut::None, [this]{
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.bookmark" }, ICON_VS_BOOKMARK, 5500, Shortcut::None, [this]{
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { { "Bookmarks File", "hexbm"} }, [&, this](const std::fs::path &path) {
|
||||
try {
|
||||
this->importBookmarks(ImHexApi::Provider::get(), nlohmann::json::parse(wolv::io::File(path, wolv::io::File::Mode::Read).readString()));
|
||||
|
||||
@@ -398,7 +398,7 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
|
||||
/* Import Nodes */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.data_processor" }, ICON_VS_CHIP, 4050, Shortcut::None, [this]{
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.data_processor" }, ICON_VS_CHIP, 5600, Shortcut::None, [this]{
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
|
||||
[&](const std::fs::path &path) {
|
||||
wolv::io::File file(path, wolv::io::File::Mode::Read);
|
||||
@@ -707,10 +707,11 @@ namespace hex::plugin::builtin {
|
||||
|
||||
// Draw custom nodes submenu
|
||||
if (ImGui::BeginMenu("hex.builtin.nodes.custom"_lang)) {
|
||||
ImGui::Separator();
|
||||
if (!m_customNodes.empty())
|
||||
ImGui::Separator();
|
||||
|
||||
// Draw entries for each custom node
|
||||
for (auto &customNode : m_customNodes) {
|
||||
for (const auto &customNode : m_customNodes) {
|
||||
if (ImGui::MenuItem(customNode.name.c_str())) {
|
||||
node = loadNode(customNode.data);
|
||||
}
|
||||
|
||||
@@ -1212,7 +1212,7 @@ namespace hex::plugin::builtin {
|
||||
this);
|
||||
|
||||
/* Load Encoding File */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.custom_encoding" }, "あ", 5050, Shortcut::None,
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.custom_encoding" }, "あ", 5700, Shortcut::None,
|
||||
[this]{
|
||||
const auto basePaths = paths::Encodings.read();
|
||||
std::vector<std::fs::path> paths;
|
||||
|
||||
@@ -997,15 +997,15 @@ namespace hex::plugin::builtin {
|
||||
|
||||
const bool hasSelection = m_consoleEditor.get(provider).HasSelection();
|
||||
if (ImGui::BeginPopup("##console_context_menu")) {
|
||||
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.copy"_lang, Shortcut(CTRLCMD + Keys::C).toString().c_str(), false, hasSelection)) {
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.hex_editor.menu.edit.copy"_lang, ICON_VS_COPY, Shortcut(CTRLCMD + Keys::C).toString().c_str(), false, hasSelection)) {
|
||||
m_consoleEditor.get(provider).Copy();
|
||||
}
|
||||
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.select_all"_lang, Shortcut(CTRLCMD + Keys::A).toString().c_str())) {
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.hex_editor.menu.edit.select_all"_lang, ICON_VS_LIST_FLAT, Shortcut(CTRLCMD + Keys::A).toString().c_str())) {
|
||||
m_consoleEditor.get(provider).SelectAll();
|
||||
}
|
||||
ImGui::Separator();
|
||||
// Search and replace entries
|
||||
if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.find"_lang, Shortcut(CTRLCMD + Keys::F).toString().c_str())) {
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.pattern_editor.menu.find"_lang, ICON_VS_SEARCH, Shortcut(CTRLCMD + Keys::F).toString().c_str())) {
|
||||
m_openFindReplacePopUp = true;
|
||||
m_replaceMode = false;
|
||||
}
|
||||
@@ -1018,7 +1018,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.goto_line"_lang, Shortcut(ALT + Keys::G).toString().c_str()))
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.pattern_editor.menu.goto_line"_lang, ICON_VS_DEBUG_STEP_INTO, Shortcut(ALT + Keys::G).toString().c_str()))
|
||||
m_openGotoLinePopUp = true;
|
||||
|
||||
|
||||
@@ -2052,63 +2052,66 @@ namespace hex::plugin::builtin {
|
||||
}, [] { return true; },
|
||||
this);
|
||||
|
||||
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.edit" }, 1600, this);
|
||||
|
||||
/* Find */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.find" }, ICON_VS_SEARCH, 1700, CTRLCMD + Keys::F, [this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.find" }, ICON_VS_SEARCH, 1700, CTRLCMD + Keys::F, [this] {
|
||||
m_replaceMode = false;
|
||||
m_openFindReplacePopUp = true;
|
||||
}, [] { return true; },
|
||||
this);
|
||||
|
||||
/* Find Next */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.find_next" }, 1800, Keys::F3, [this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.find_next" }, 1800, Keys::F3, [this] {
|
||||
m_consoleEditor->GetFindReplaceHandler()->FindMatch(&*m_textEditor, true);
|
||||
}, [this] { return ImHexApi::Provider::isValid() && !m_consoleEditor->GetFindReplaceHandler()->GetFindWord().empty(); },
|
||||
[]{ return false; },
|
||||
this);
|
||||
|
||||
/* Find Previous */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.find_previous" }, 1900, Keys::F3, [this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.find_previous" }, 1900, Keys::F3, [this] {
|
||||
m_consoleEditor->GetFindReplaceHandler()->FindMatch(&*m_textEditor, true);
|
||||
}, [this] { return ImHexApi::Provider::isValid() && !m_consoleEditor->GetFindReplaceHandler()->GetFindWord().empty(); },
|
||||
[]{ return false; },
|
||||
this);
|
||||
|
||||
/* Replace */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.replace" }, ICON_VS_REPLACE, 2000, CTRLCMD + Keys::H, [this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.replace" }, ICON_VS_REPLACE, 2000, CTRLCMD + Keys::H, [this] {
|
||||
m_replaceMode = true;
|
||||
m_openFindReplacePopUp = true;
|
||||
}, [] { return true; },
|
||||
this);
|
||||
|
||||
/* Replace Next */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.replace_next" }, 2100, Shortcut::None, [this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.replace_next" }, 2100, Shortcut::None, [this] {
|
||||
m_consoleEditor->GetFindReplaceHandler()->Replace(&*m_textEditor, true);
|
||||
}, [this] { return ImHexApi::Provider::isValid() && !m_consoleEditor->GetFindReplaceHandler()->GetReplaceWord().empty(); },
|
||||
[]{ return false; },
|
||||
this);
|
||||
|
||||
/* Replace Previous */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.replace_previous" }, 2200, Shortcut::None, [this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.replace_previous" }, 2200, Shortcut::None, [this] {
|
||||
m_consoleEditor->GetFindReplaceHandler()->Replace(&*m_textEditor, false);
|
||||
}, [this] { return ImHexApi::Provider::isValid() && !m_consoleEditor->GetFindReplaceHandler()->GetReplaceWord().empty(); },
|
||||
[]{ return false; },
|
||||
this);
|
||||
|
||||
/* Replace All */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.replace_all" }, ICON_VS_REPLACE_ALL, 2300, Shortcut::None, [this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.replace_all" }, ICON_VS_REPLACE_ALL, 2300, Shortcut::None, [this] {
|
||||
m_consoleEditor->GetFindReplaceHandler()->ReplaceAll(&*m_textEditor);
|
||||
}, [this] { return ImHexApi::Provider::isValid() && !m_consoleEditor->GetFindReplaceHandler()->GetReplaceWord().empty(); },
|
||||
this);
|
||||
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.goto_line" }, ICON_VS_DEBUG_STEP_INTO, 2400, CTRLCMD + Keys::G, [this] {
|
||||
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.file" }, 2400, this);
|
||||
|
||||
/* Goto Line */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.pattern_editor.menu.goto_line" }, ICON_VS_DEBUG_STEP_INTO, 2500, CTRLCMD + Keys::G, [this] {
|
||||
m_openGotoLinePopUp = true;
|
||||
}, [] { return true; },
|
||||
this);
|
||||
|
||||
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.file" }, 4200, this);
|
||||
|
||||
/* Import Pattern */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.pattern" }, ICON_VS_FILE_CODE, 4050, Shortcut::None,
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.pattern" }, ICON_VS_FILE_CODE, 5600, Shortcut::None,
|
||||
m_importPatternFile, ImHexApi::Provider::isValid);
|
||||
|
||||
/* Export Pattern */
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace hex::plugin::builtin {
|
||||
if (shortcut == Shortcut::None)
|
||||
callback();
|
||||
else {
|
||||
if (!ShortcutManager::runShortcut(shortcut, ContentRegistry::Views::getFocusedView())) {
|
||||
if (!ShortcutManager::runShortcut(shortcut, View::getLastFocusedView())) {
|
||||
if (!ShortcutManager::runShortcut(shortcut)) {
|
||||
callback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user