diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 2f83611bd..f987939bb 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -5,6 +5,7 @@
+
diff --git a/include/window.hpp b/include/window.hpp
index ea45b9757..596bbe4f1 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -68,6 +68,7 @@ namespace hex {
std::filesystem::path m_safetyBackupPath;
std::list m_popupsToOpen;
+ std::vector m_pressedKeys;
};
}
\ No newline at end of file
diff --git a/plugins/builtin/include/content/views/view_command_palette.hpp b/plugins/builtin/include/content/views/view_command_palette.hpp
index 15121cdd8..534c1dda3 100644
--- a/plugins/builtin/include/content/views/view_command_palette.hpp
+++ b/plugins/builtin/include/content/views/view_command_palette.hpp
@@ -23,8 +23,6 @@ namespace hex::plugin::builtin {
bool isAvailable() override { return true; }
bool shouldProcess() override { return true; }
- bool handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) override;
-
bool hasViewMenuItemEntry() override { return false; }
ImVec2 getMinSize() override { return ImVec2(400, 100); }
ImVec2 getMaxSize() override { return ImVec2(400, 100); }
diff --git a/plugins/builtin/include/content/views/view_hexeditor.hpp b/plugins/builtin/include/content/views/view_hexeditor.hpp
index 448235bed..e6ea73bff 100644
--- a/plugins/builtin/include/content/views/view_hexeditor.hpp
+++ b/plugins/builtin/include/content/views/view_hexeditor.hpp
@@ -26,7 +26,6 @@ namespace hex::plugin::builtin {
void drawContent() override;
void drawAlwaysVisible() override;
void drawMenu() override;
- bool handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) override;
private:
MemoryEditor m_memoryEditor;
@@ -72,6 +71,8 @@ namespace hex::plugin::builtin {
void copyHexView() const;
void copyHexViewHTML() const;
+ void registerEvents();
+ void registerShortcuts();
};
}
\ No newline at end of file
diff --git a/plugins/builtin/source/content/views/view_command_palette.cpp b/plugins/builtin/source/content/views/view_command_palette.cpp
index 765a94c9b..6d0351acc 100644
--- a/plugins/builtin/source/content/views/view_command_palette.cpp
+++ b/plugins/builtin/source/content/views/view_command_palette.cpp
@@ -6,6 +6,12 @@ namespace hex::plugin::builtin {
ViewCommandPalette::ViewCommandPalette() : View("hex.builtin.view.command_palette.name") {
this->m_commandBuffer.resize(1024, 0x00);
+
+ ShortcutManager::addGlobalShortcut(CTRL + SHIFT + Keys::P, [this] {
+ EventManager::post("hex.builtin.view.command_palette.name"_lang);
+ this->m_commandPaletteOpen = true;
+ this->m_justOpened = true;
+ });
}
ViewCommandPalette::~ViewCommandPalette() {
@@ -72,19 +78,6 @@ namespace hex::plugin::builtin {
}
- bool ViewCommandPalette::handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) {
- if (ctrl && shift && keys['P']) {
- View::doLater([this] {
- ImGui::OpenPopup("hex.builtin.view.command_palette.name"_lang);
- this->m_commandPaletteOpen = true;
- this->m_justOpened = true;
- });
- return true;
- }
-
- return false;
- }
-
std::vector ViewCommandPalette::getCommandResults(const std::string &input) {
constexpr auto MatchCommand = [](const std::string &currCommand, const std::string &commandToMatch) -> std::pair {
if (currCommand.empty()) {
diff --git a/plugins/builtin/source/content/views/view_hexeditor.cpp b/plugins/builtin/source/content/views/view_hexeditor.cpp
index 0933b0be9..c77e3b6f1 100644
--- a/plugins/builtin/source/content/views/view_hexeditor.cpp
+++ b/plugins/builtin/source/content/views/view_hexeditor.cpp
@@ -141,134 +141,8 @@ namespace hex::plugin::builtin {
return { std::string(decoded), advance, color };
};
- EventManager::subscribe(this, [this](const std::string &filePath) {
- this->openFile(filePath);
- this->getWindowOpenState() = true;
- });
-
- EventManager::subscribe(this, [this](Region region) {
- auto provider = ImHexApi::Provider::get();
- auto page = provider->getPageOfAddress(region.address);
-
- if (!page.has_value())
- return;
-
- if (region.size != 0) {
- provider->setCurrentPage(page.value());
- u64 start = region.address - provider->getBaseAddress() - provider->getCurrentPageAddress();
- this->m_memoryEditor.GotoAddrAndSelect(start, start + region.size - 1);
- }
-
- EventManager::post(Region { this->m_memoryEditor.DataPreviewAddr, (this->m_memoryEditor.DataPreviewAddrEnd - this->m_memoryEditor.DataPreviewAddr) + 1});
- });
-
- EventManager::subscribe(this, []() {
- EventManager::post(ProjectFile::getFilePath());
- });
-
- EventManager::subscribe(this, [](GLFWwindow *window) {
- if (ProjectFile::hasUnsavedChanges()) {
- glfwSetWindowShouldClose(window, GLFW_FALSE);
- View::doLater([] { ImGui::OpenPopup("hex.builtin.view.hexeditor.exit_application.title"_lang); });
- }
- });
-
- EventManager::subscribe(this, [this]() {
- this->m_highlightedBytes.clear();
-
- for (const auto &pattern : SharedData::patternData) {
- this->m_highlightedBytes.merge(pattern->getHighlightedAddresses());
- }
- });
-
- EventManager::subscribe(this, [this](std::string name) {
- if (name == "Create File") {
- hex::openFileBrowser("hex.builtin.view.hexeditor.create_file"_lang, DialogMode::Save, { }, [this](auto path) {
- if (!this->createFile(path)) {
- View::showErrorPopup("hex.builtin.view.hexeditor.error.create"_lang);
- return;
- }
-
- EventManager::post(path);
- this->getWindowOpenState() = true;
- });
- } else if (name == "Open File") {
- hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](auto path) {
- EventManager::post(path);
- this->getWindowOpenState() = true;
- });
- } else if (name == "Open Project") {
- hex::openFileBrowser("hex.builtin.view.hexeditor.open_project"_lang, DialogMode::Open, { { "Project File", "hexproj" } }, [this](auto path) {
- ProjectFile::load(path);
- this->getWindowOpenState() = true;
- });
- }
- });
-
- EventManager::subscribe(this, [this] {
- {
- auto alpha = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha");
-
- if (alpha.is_number())
- this->m_highlightAlpha = alpha;
- }
-
- {
- auto columnCount = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.column_count");
-
- if (columnCount.is_number())
- this->m_memoryEditor.Cols = static_cast(columnCount);
- }
-
- {
- auto hexii = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.hexii");
-
- if (hexii.is_number())
- this->m_memoryEditor.OptShowHexII = static_cast(hexii);
- }
-
- {
- auto ascii = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.ascii");
-
- if (ascii.is_number())
- this->m_memoryEditor.OptShowAscii = static_cast(ascii);
- }
-
- {
- auto advancedDecoding = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding");
-
- if (advancedDecoding.is_number())
- this->m_memoryEditor.OptShowAdvancedDecoding = static_cast(advancedDecoding);
- }
-
- {
- auto greyOutZeros = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.grey_zeros");
-
- if (greyOutZeros.is_number())
- this->m_memoryEditor.OptGreyOutZeroes = static_cast(greyOutZeros);
- }
-
- {
- auto upperCaseHex = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.uppercase_hex");
-
- if (upperCaseHex.is_number())
- this->m_memoryEditor.OptUpperCaseHex = static_cast(upperCaseHex);
- }
-
- {
- auto showExtraInfo = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.extra_info");
-
- if (showExtraInfo.is_number())
- this->m_memoryEditor.OptShowExtraInfo = static_cast(showExtraInfo);
- }
- });
-
- EventManager::subscribe(this, [this](auto ®ion) {
- u64 address = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
- size_t size = std::abs(s64(this->m_memoryEditor.DataPreviewAddrEnd) - s64(this->m_memoryEditor.DataPreviewAddr)) + 1;
-
- region = Region { address, size };
- });
+ registerEvents();
+ registerShortcuts();
}
ViewHexEditor::~ViewHexEditor() {
@@ -635,57 +509,6 @@ namespace hex::plugin::builtin {
}
}
- bool ViewHexEditor::handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) {
- if (ctrl && shift && keys['S']) {
- saveAs();
- return true;
- } else if (ctrl && keys['S']) {
- save();
- return true;
- }
-
- ON_SCOPE_EXIT { ImGui::End(); };
- if (ImGui::Begin(View::toWindowName("hex.builtin.view.hexeditor.name").c_str())) {
-
- if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) {
- if (ctrl && keys['Z']) {
- if (ImHexApi::Provider::isValid())
- ImHexApi::Provider::get()->undo();
- return true;
- } else if (ctrl && keys['Y']) {
- if (ImHexApi::Provider::isValid())
- ImHexApi::Provider::get()->redo();
- } else if (ctrl && keys['F']) {
- ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.search"_lang);
- return true;
- } else if (ctrl && keys['G']) {
- ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.goto"_lang);
- return true;
- } else if (ctrl && keys['O']) {
- hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [](auto path) {
- EventManager::post(path);
- });
- return true;
- } else if (ctrl && keys['C']) {
- this->copyBytes();
- return true;
- } else if (ctrl && shift && keys['C']) {
- this->copyString();
- return true;
- } else if (ctrl && keys['V']) {
- this->pasteBytes();
- return true;
- } else if (ctrl && keys['A']) {
- auto provider = ImHexApi::Provider::get();
- EventManager::post(Region { provider->getBaseAddress(), provider->getActualSize() });
- return true;
- }
- }
- }
-
- return false;
- }
-
bool ViewHexEditor::createFile(const std::string &path) {
#if defined(OS_WINDOWS)
std::wstring widePath;
@@ -1361,4 +1184,190 @@ R"(
}
}
+ void ViewHexEditor::registerEvents() {
+ EventManager::subscribe(this, [this](const std::string &filePath) {
+ this->openFile(filePath);
+ this->getWindowOpenState() = true;
+ });
+
+ EventManager::subscribe(this, [this](Region region) {
+ auto provider = ImHexApi::Provider::get();
+ auto page = provider->getPageOfAddress(region.address);
+
+ if (!page.has_value())
+ return;
+
+ if (region.size != 0) {
+ provider->setCurrentPage(page.value());
+ u64 start = region.address - provider->getBaseAddress() - provider->getCurrentPageAddress();
+ this->m_memoryEditor.GotoAddrAndSelect(start, start + region.size - 1);
+ }
+
+ EventManager::post(Region { this->m_memoryEditor.DataPreviewAddr, (this->m_memoryEditor.DataPreviewAddrEnd - this->m_memoryEditor.DataPreviewAddr) + 1});
+ });
+
+ EventManager::subscribe(this, []() {
+ EventManager::post(ProjectFile::getFilePath());
+ });
+
+ EventManager::subscribe(this, [](GLFWwindow *window) {
+ if (ProjectFile::hasUnsavedChanges()) {
+ glfwSetWindowShouldClose(window, GLFW_FALSE);
+ View::doLater([] { ImGui::OpenPopup("hex.builtin.view.hexeditor.exit_application.title"_lang); });
+ }
+ });
+
+ EventManager::subscribe(this, [this]() {
+ this->m_highlightedBytes.clear();
+
+ for (const auto &pattern : SharedData::patternData) {
+ this->m_highlightedBytes.merge(pattern->getHighlightedAddresses());
+ }
+ });
+
+ EventManager::subscribe(this, [this](std::string name) {
+ if (name == "Create File") {
+ hex::openFileBrowser("hex.builtin.view.hexeditor.create_file"_lang, DialogMode::Save, { }, [this](auto path) {
+ if (!this->createFile(path)) {
+ View::showErrorPopup("hex.builtin.view.hexeditor.error.create"_lang);
+ return;
+ }
+
+ EventManager::post(path);
+ this->getWindowOpenState() = true;
+ });
+ } else if (name == "Open File") {
+ hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](auto path) {
+ EventManager::post(path);
+ this->getWindowOpenState() = true;
+ });
+ } else if (name == "Open Project") {
+ hex::openFileBrowser("hex.builtin.view.hexeditor.open_project"_lang, DialogMode::Open, { { "Project File", "hexproj" } }, [this](auto path) {
+ ProjectFile::load(path);
+ this->getWindowOpenState() = true;
+ });
+ }
+ });
+
+ EventManager::subscribe(this, [this] {
+ {
+ auto alpha = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha");
+
+ if (alpha.is_number())
+ this->m_highlightAlpha = alpha;
+ }
+
+ {
+ auto columnCount = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.column_count");
+
+ if (columnCount.is_number())
+ this->m_memoryEditor.Cols = static_cast(columnCount);
+ }
+
+ {
+ auto hexii = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.hexii");
+
+ if (hexii.is_number())
+ this->m_memoryEditor.OptShowHexII = static_cast(hexii);
+ }
+
+ {
+ auto ascii = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.ascii");
+
+ if (ascii.is_number())
+ this->m_memoryEditor.OptShowAscii = static_cast(ascii);
+ }
+
+ {
+ auto advancedDecoding = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding");
+
+ if (advancedDecoding.is_number())
+ this->m_memoryEditor.OptShowAdvancedDecoding = static_cast(advancedDecoding);
+ }
+
+ {
+ auto greyOutZeros = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.grey_zeros");
+
+ if (greyOutZeros.is_number())
+ this->m_memoryEditor.OptGreyOutZeroes = static_cast(greyOutZeros);
+ }
+
+ {
+ auto upperCaseHex = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.uppercase_hex");
+
+ if (upperCaseHex.is_number())
+ this->m_memoryEditor.OptUpperCaseHex = static_cast(upperCaseHex);
+ }
+
+ {
+ auto showExtraInfo = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.extra_info");
+
+ if (showExtraInfo.is_number())
+ this->m_memoryEditor.OptShowExtraInfo = static_cast(showExtraInfo);
+ }
+ });
+
+ EventManager::subscribe(this, [this](auto ®ion) {
+ u64 address = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
+ size_t size = std::abs(s64(this->m_memoryEditor.DataPreviewAddrEnd) - s64(this->m_memoryEditor.DataPreviewAddr)) + 1;
+
+ region = Region { address, size };
+ });
+ }
+
+ void ViewHexEditor::registerShortcuts() {
+ ShortcutManager::addGlobalShortcut(CTRL + Keys::S, [] {
+ save();
+ });
+
+ ShortcutManager::addGlobalShortcut(CTRL + SHIFT + Keys::S, [] {
+ saveAs();
+ });
+
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::Z, [] {
+ if (ImHexApi::Provider::isValid())
+ ImHexApi::Provider::get()->undo();
+ });
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::Y, [] {
+ if (ImHexApi::Provider::isValid())
+ ImHexApi::Provider::get()->redo();
+ });
+
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::F, [] {
+ ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.search"_lang);
+ });
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::G, [] {
+ ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), "hex.builtin.view.hexeditor.menu.file.goto"_lang);
+ });
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::O, [] {
+ hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [](auto path) {
+ EventManager::post(path);
+ });
+ });
+
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::C, [this] {
+ this->copyBytes();
+ });
+
+ ShortcutManager::addShortcut(this, CTRL + SHIFT + Keys::C, [this] {
+ this->copyString();
+ });
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::V, [this] {
+ this->pasteBytes();
+ });
+
+ ShortcutManager::addShortcut(this, CTRL + Keys::A, [this] {
+ auto provider = ImHexApi::Provider::get();
+ EventManager::post(Region { provider->getBaseAddress(), provider->getActualSize() });
+ });
+
+ }
+
}
\ No newline at end of file
diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp
index 5a3b69f2a..950a8db6f 100644
--- a/plugins/builtin/source/plugin_builtin.cpp
+++ b/plugins/builtin/source/plugin_builtin.cpp
@@ -1,5 +1,7 @@
#include
+#include
+
namespace hex::plugin::builtin {
void registerViews();
diff --git a/plugins/libimhex/CMakeLists.txt b/plugins/libimhex/CMakeLists.txt
index a952c53e9..dee134bb5 100644
--- a/plugins/libimhex/CMakeLists.txt
+++ b/plugins/libimhex/CMakeLists.txt
@@ -104,6 +104,7 @@ set(LIBIMHEX_SOURCES
source/api/imhex_api.cpp
source/api/content_registry.cpp
source/api/task.cpp
+ source/api/keybinding.cpp
source/data_processor/attribute.cpp
source/data_processor/link.cpp
@@ -134,8 +135,7 @@ set(LIBIMHEX_SOURCES
source/providers/provider.cpp
source/views/view.cpp
-
- )
+)
if (APPLE)
set(OSX_11_0_SDK_PATH /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk)
diff --git a/plugins/libimhex/include/hex/api/imhex_api.hpp b/plugins/libimhex/include/hex/api/imhex_api.hpp
index d763be2fb..bfd543a7b 100644
--- a/plugins/libimhex/include/hex/api/imhex_api.hpp
+++ b/plugins/libimhex/include/hex/api/imhex_api.hpp
@@ -8,6 +8,7 @@
#include
#include
+#include
namespace hex {
diff --git a/plugins/libimhex/include/hex/api/keybinding.hpp b/plugins/libimhex/include/hex/api/keybinding.hpp
new file mode 100644
index 000000000..de667f46f
--- /dev/null
+++ b/plugins/libimhex/include/hex/api/keybinding.hpp
@@ -0,0 +1,184 @@
+#pragma once
+
+#include
+#include
+
+#include
+#include