From 989f7f76789809f099bbf6ec29b92b8b749f7f60 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 30 Nov 2025 16:40:23 +0100 Subject: [PATCH] impr: Add option to ShortcutManager to get a shortcut by its name --- .../include/hex/api/shortcut_manager.hpp | 2 ++ lib/libimhex/source/api/shortcut_manager.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/libimhex/include/hex/api/shortcut_manager.hpp b/lib/libimhex/include/hex/api/shortcut_manager.hpp index 3d92c0579..ddb0d975e 100644 --- a/lib/libimhex/include/hex/api/shortcut_manager.hpp +++ b/lib/libimhex/include/hex/api/shortcut_manager.hpp @@ -151,6 +151,8 @@ EXPORT_MODULE namespace hex { */ static void clearShortcuts(); + static Shortcut getShortcutByName(const std::vector &unlocalizedName, const View *view = nullptr); + static void resumeShortcuts(); static void pauseShortcuts(); diff --git a/lib/libimhex/source/api/shortcut_manager.cpp b/lib/libimhex/source/api/shortcut_manager.cpp index 8d0ff6b8f..7f0a8e9dd 100644 --- a/lib/libimhex/source/api/shortcut_manager.cpp +++ b/lib/libimhex/source/api/shortcut_manager.cpp @@ -387,6 +387,24 @@ namespace hex { s_globalShortcuts->clear(); } + Shortcut ShortcutManager::getShortcutByName(const std::vector &unlocalizedName, const View *view) { + if (view != nullptr) { + for (const auto &[shortcut, entry] : view->m_shortcuts) { + if (entry.unlocalizedName == unlocalizedName) { + return entry.shortcut; + } + } + } else { + for (const auto &[shortcut, entry] : *s_globalShortcuts) { + if (entry.unlocalizedName == unlocalizedName) { + return entry.shortcut; + } + } + } + + return Shortcut::None; + } + void ShortcutManager::resumeShortcuts() { s_paused = false; }