Implement shortcut execution logic and update Cut command handling in EditorManager
This commit is contained in:
@@ -127,8 +127,9 @@ void EditorManager::Initialize(const std::string &filename) {
|
|||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
{absl::StrCat(ICON_MD_CONTENT_CUT, " Cut"), "Cmd+X",
|
{absl::StrCat(ICON_MD_CONTENT_CUT, " Cut"),
|
||||||
[&]() { status_ = current_editor_->Cut(); }},
|
context_.shortcut_manager.GetKeys("Cut"),
|
||||||
|
context_.shortcut_manager.GetCallback("Cut")},
|
||||||
{absl::StrCat(ICON_MD_CONTENT_COPY, " Copy"), "Cmd+C",
|
{absl::StrCat(ICON_MD_CONTENT_COPY, " Copy"), "Cmd+C",
|
||||||
[&]() { status_ = current_editor_->Copy(); }},
|
[&]() { status_ = current_editor_->Copy(); }},
|
||||||
{absl::StrCat(ICON_MD_CONTENT_PASTE, " Paste"), "Cmd+V",
|
{absl::StrCat(ICON_MD_CONTENT_PASTE, " Paste"), "Cmd+V",
|
||||||
@@ -181,7 +182,8 @@ void EditorManager::Initialize(const std::string &filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
absl::Status EditorManager::Update() {
|
absl::Status EditorManager::Update() {
|
||||||
ManageKeyboardShortcuts();
|
// ManageKeyboardShortcuts();
|
||||||
|
ExecuteShortcuts(context_.shortcut_manager);
|
||||||
|
|
||||||
DrawMenuBar();
|
DrawMenuBar();
|
||||||
DrawPopups();
|
DrawPopups();
|
||||||
|
|||||||
@@ -137,5 +137,34 @@ std::vector<ImGuiKey> ParseShortcut(const std::string& shortcut) {
|
|||||||
return shortcuts;
|
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 editor
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
@@ -55,10 +55,14 @@ class ShortcutManager {
|
|||||||
return PrintShortcut(shortcuts_.at(name).keys);
|
return PrintShortcut(shortcuts_.at(name).keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto GetShortcuts() const { return shortcuts_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, Shortcut> shortcuts_;
|
std::unordered_map<std::string, Shortcut> shortcuts_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ExecuteShortcuts(const ShortcutManager &shortcut_manager);
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user