From 7b2c919745ca3cb9328ba9e5534f5e942c35ae43 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 9 Mar 2025 18:42:04 -0400 Subject: [PATCH] Implement shortcut execution logic and update Cut command handling in EditorManager --- src/app/editor/editor_manager.cc | 8 ++++--- src/app/editor/system/shortcut_manager.cc | 29 +++++++++++++++++++++++ src/app/editor/system/shortcut_manager.h | 4 ++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/app/editor/editor_manager.cc b/src/app/editor/editor_manager.cc index b71a2d84..3fc00fdd 100644 --- a/src/app/editor/editor_manager.cc +++ b/src/app/editor/editor_manager.cc @@ -127,8 +127,9 @@ void EditorManager::Initialize(const std::string &filename) { {}, {}, { - {absl::StrCat(ICON_MD_CONTENT_CUT, " Cut"), "Cmd+X", - [&]() { status_ = current_editor_->Cut(); }}, + {absl::StrCat(ICON_MD_CONTENT_CUT, " Cut"), + context_.shortcut_manager.GetKeys("Cut"), + context_.shortcut_manager.GetCallback("Cut")}, {absl::StrCat(ICON_MD_CONTENT_COPY, " Copy"), "Cmd+C", [&]() { status_ = current_editor_->Copy(); }}, {absl::StrCat(ICON_MD_CONTENT_PASTE, " Paste"), "Cmd+V", @@ -181,7 +182,8 @@ void EditorManager::Initialize(const std::string &filename) { } absl::Status EditorManager::Update() { - ManageKeyboardShortcuts(); + // ManageKeyboardShortcuts(); + ExecuteShortcuts(context_.shortcut_manager); DrawMenuBar(); DrawPopups(); diff --git a/src/app/editor/system/shortcut_manager.cc b/src/app/editor/system/shortcut_manager.cc index a3d8d908..6aa25742 100644 --- a/src/app/editor/system/shortcut_manager.cc +++ b/src/app/editor/system/shortcut_manager.cc @@ -137,5 +137,34 @@ std::vector ParseShortcut(const std::string& shortcut) { return shortcuts; } +void ExecuteShortcuts(const ShortcutManager& shortcut_manager) { + // Check for keyboard shortcuts using the shortcut manager + for (const auto& shortcut : shortcut_manager.GetShortcuts()) { + bool ctrl_pressed = ImGui::GetIO().KeyCtrl; + bool alt_pressed = ImGui::GetIO().KeyAlt; + bool shift_pressed = ImGui::GetIO().KeyShift; + bool super_pressed = ImGui::GetIO().KeySuper; + bool keys_pressed = false; + // Check for all the keys in the shortcut + for (const auto& key : shortcut.second.keys) { + if (key == ImGuiMod_Ctrl) { + keys_pressed = ctrl_pressed; + } else if (key == ImGuiMod_Alt) { + keys_pressed = alt_pressed; + } else if (key == ImGuiMod_Shift) { + keys_pressed = shift_pressed; + } else if (key == ImGuiMod_Super) { + keys_pressed = super_pressed; + } else { + keys_pressed = ImGui::IsKeyDown(key); + } + + if (!keys_pressed) { + break; + } + } + } +} + } // namespace editor } // namespace yaze \ No newline at end of file diff --git a/src/app/editor/system/shortcut_manager.h b/src/app/editor/system/shortcut_manager.h index d6184420..29f8045d 100644 --- a/src/app/editor/system/shortcut_manager.h +++ b/src/app/editor/system/shortcut_manager.h @@ -55,10 +55,14 @@ class ShortcutManager { return PrintShortcut(shortcuts_.at(name).keys); } + auto GetShortcuts() const { return shortcuts_; } + private: std::unordered_map shortcuts_; }; +void ExecuteShortcuts(const ShortcutManager &shortcut_manager); + } // namespace editor } // namespace yaze