Implement shortcut execution logic and update Cut command handling in EditorManager

This commit is contained in:
scawful
2025-03-09 18:42:04 -04:00
parent 02ae11ec9e
commit 7b2c919745
3 changed files with 38 additions and 3 deletions

View File

@@ -137,5 +137,34 @@ std::vector<ImGuiKey> 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

View File

@@ -55,10 +55,14 @@ class ShortcutManager {
return PrintShortcut(shortcuts_.at(name).keys);
}
auto GetShortcuts() const { return shortcuts_; }
private:
std::unordered_map<std::string, Shortcut> shortcuts_;
};
void ExecuteShortcuts(const ShortcutManager &shortcut_manager);
} // namespace editor
} // namespace yaze