mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
sys: Moved to a better shortcut handling system
This commit is contained in:
37
plugins/libimhex/source/api/keybinding.cpp
Normal file
37
plugins/libimhex/source/api/keybinding.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <hex/api/keybinding.hpp>
|
||||
#include <hex/helpers/shared_data.hpp>
|
||||
#include <imgui.h>
|
||||
|
||||
#include <hex/views/view.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
void ShortcutManager::addGlobalShortcut(const Shortcut &shortcut, const std::function<void()> &callback) {
|
||||
SharedData::globalShortcuts.insert({ shortcut, callback });
|
||||
}
|
||||
|
||||
void ShortcutManager::addShortcut(View *view, const Shortcut &shortcut, const std::function<void()> &callback) {
|
||||
view->m_shortcuts.insert({ shortcut, callback });
|
||||
}
|
||||
|
||||
void ShortcutManager::process(View *currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) {
|
||||
Shortcut pressedShortcut;
|
||||
|
||||
if (ctrl)
|
||||
pressedShortcut += CTRL;
|
||||
if (alt)
|
||||
pressedShortcut += ALT;
|
||||
if (shift)
|
||||
pressedShortcut += SHIFT;
|
||||
if (super)
|
||||
pressedShortcut += SUPER;
|
||||
|
||||
pressedShortcut += static_cast<Keys>(keyCode);
|
||||
|
||||
if (focused && currentView->m_shortcuts.contains(pressedShortcut))
|
||||
currentView->m_shortcuts[pressedShortcut]();
|
||||
else if (SharedData::globalShortcuts.contains(pressedShortcut))
|
||||
SharedData::globalShortcuts[pressedShortcut]();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,8 @@ namespace hex {
|
||||
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::footerItems;
|
||||
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::toolbarItems;
|
||||
|
||||
std::map<Shortcut, std::function<void()>> SharedData::globalShortcuts;
|
||||
|
||||
std::mutex SharedData::tasksMutex;
|
||||
std::list<Task*> SharedData::runningTasks;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace hex {
|
||||
View::View(std::string unlocalizedName) : m_unlocalizedViewName(unlocalizedName) { }
|
||||
|
||||
void View::drawMenu() { }
|
||||
bool View::handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) { return false; }
|
||||
|
||||
bool View::isAvailable() {
|
||||
return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable();
|
||||
|
||||
Reference in New Issue
Block a user