fix: Properly trigger shortcuts on selected view on macOS
This commit is contained in:
parent
f17d0d3ae1
commit
96afa650d1
@ -597,6 +597,12 @@ namespace hex {
|
||||
* @return The view if it exists, nullptr otherwise
|
||||
*/
|
||||
View* getViewByName(const UnlocalizedString &unlocalizedName);
|
||||
|
||||
/**
|
||||
* @brief Gets the currently focused view
|
||||
* @return The view that is focused right now. nullptr if none is focused
|
||||
*/
|
||||
View* getFocusedView();
|
||||
}
|
||||
|
||||
/* Tools Registry. Allows adding new entries to the tools window */
|
||||
|
@ -135,7 +135,13 @@ namespace hex {
|
||||
*/
|
||||
static void processGlobals(bool ctrl, bool alt, bool shift, bool super, u32 keyCode);
|
||||
|
||||
static void runShortcut(const Shortcut &shortcut, const View *view = nullptr);
|
||||
/**
|
||||
* @brief Runs the callback of a shortcut as if it was pressed on the keyboard
|
||||
* @param shortcut Shortcut to run
|
||||
* @param view View the shortcut belongs to or nullptr to run a global shortcut
|
||||
* @return True if a callback was executed, false if not
|
||||
*/
|
||||
static bool runShortcut(const Shortcut &shortcut, const View *view = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Clear all shortcuts
|
||||
|
@ -736,6 +736,15 @@ namespace hex {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
View* getFocusedView() {
|
||||
for (const auto &[unlocalizedName, view] : *impl::s_views) {
|
||||
if (view->isFocused())
|
||||
return view.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace ContentRegistry::Tools {
|
||||
|
@ -315,11 +315,12 @@ namespace hex {
|
||||
return pressedShortcut;
|
||||
}
|
||||
|
||||
static void processShortcut(Shortcut shortcut, const std::map<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) {
|
||||
if (s_paused) return;
|
||||
static bool processShortcut(Shortcut shortcut, const std::map<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) {
|
||||
if (s_paused)
|
||||
return true;
|
||||
|
||||
if (ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId))
|
||||
return;
|
||||
return true;
|
||||
|
||||
const bool currentlyTyping = ImGui::GetIO().WantTextInput;
|
||||
|
||||
@ -338,15 +339,19 @@ namespace hex {
|
||||
if (!entry.unlocalizedName.empty()) {
|
||||
s_lastShortcutMainMenu = entry.unlocalizedName.front();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ShortcutManager::runShortcut(const Shortcut &shortcut, const View *view) {
|
||||
bool ShortcutManager::runShortcut(const Shortcut &shortcut, const View *view) {
|
||||
if (view == nullptr)
|
||||
processShortcut(shortcut, s_globalShortcuts);
|
||||
return processShortcut(shortcut, s_globalShortcuts);
|
||||
else
|
||||
processShortcut(shortcut, view->m_shortcuts);
|
||||
return processShortcut(shortcut, view->m_shortcuts);
|
||||
}
|
||||
|
||||
void ShortcutManager::process(const View *currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) {
|
||||
|
@ -51,8 +51,9 @@ namespace hex::plugin::builtin {
|
||||
if (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback())) {
|
||||
if (shortcut == Shortcut::None)
|
||||
callback();
|
||||
else
|
||||
ShortcutManager::runShortcut(shortcut, view);
|
||||
else {
|
||||
ShortcutManager::runShortcut(shortcut, ContentRegistry::Views::getFocusedView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bool isSubmenu = (menuItems.begin() + 1)->get() == ContentRegistry::Interface::impl::SubMenuValue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user