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
|
* @return The view if it exists, nullptr otherwise
|
||||||
*/
|
*/
|
||||||
View* getViewByName(const UnlocalizedString &unlocalizedName);
|
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 */
|
/* 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 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
|
* @brief Clear all shortcuts
|
||||||
|
@ -736,6 +736,15 @@ namespace hex {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View* getFocusedView() {
|
||||||
|
for (const auto &[unlocalizedName, view] : *impl::s_views) {
|
||||||
|
if (view->isFocused())
|
||||||
|
return view.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ContentRegistry::Tools {
|
namespace ContentRegistry::Tools {
|
||||||
|
@ -315,11 +315,12 @@ namespace hex {
|
|||||||
return pressedShortcut;
|
return pressedShortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void processShortcut(Shortcut shortcut, const std::map<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) {
|
static bool processShortcut(Shortcut shortcut, const std::map<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) {
|
||||||
if (s_paused) return;
|
if (s_paused)
|
||||||
|
return true;
|
||||||
|
|
||||||
if (ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId))
|
if (ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId))
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
const bool currentlyTyping = ImGui::GetIO().WantTextInput;
|
const bool currentlyTyping = ImGui::GetIO().WantTextInput;
|
||||||
|
|
||||||
@ -338,15 +339,19 @@ namespace hex {
|
|||||||
if (!entry.unlocalizedName.empty()) {
|
if (!entry.unlocalizedName.empty()) {
|
||||||
s_lastShortcutMainMenu = entry.unlocalizedName.front();
|
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)
|
if (view == nullptr)
|
||||||
processShortcut(shortcut, s_globalShortcuts);
|
return processShortcut(shortcut, s_globalShortcuts);
|
||||||
else
|
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) {
|
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 (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback())) {
|
||||||
if (shortcut == Shortcut::None)
|
if (shortcut == Shortcut::None)
|
||||||
callback();
|
callback();
|
||||||
else
|
else {
|
||||||
ShortcutManager::runShortcut(shortcut, view);
|
ShortcutManager::runShortcut(shortcut, ContentRegistry::Views::getFocusedView());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool isSubmenu = (menuItems.begin() + 1)->get() == ContentRegistry::Interface::impl::SubMenuValue;
|
bool isSubmenu = (menuItems.begin() + 1)->get() == ContentRegistry::Interface::impl::SubMenuValue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user