From d118857e2e5d1e2bd5b622a8b0a2c2f4bb585dd7 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 10 Nov 2024 09:03:50 -0500 Subject: [PATCH] Add keybinding save and load functionality to CommandManager --- src/app/editor/editor_manager.h | 1 - src/app/editor/system/command_manager.cc | 26 ++++++++++++++++++++++++ src/app/editor/system/command_manager.h | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/app/editor/editor_manager.h b/src/app/editor/editor_manager.h index a542f178..0fe459e5 100644 --- a/src/app/editor/editor_manager.h +++ b/src/app/editor/editor_manager.h @@ -92,7 +92,6 @@ class EditorManager : public SharedRom, public core::ExperimentFlags { absl::Status status_; - ImVector active_tabs_; std::vector active_editors_; emu::Emulator emulator_; diff --git a/src/app/editor/system/command_manager.cc b/src/app/editor/system/command_manager.cc index e14e48a3..30512971 100644 --- a/src/app/editor/system/command_manager.cc +++ b/src/app/editor/system/command_manager.cc @@ -1,5 +1,7 @@ #include "command_manager.h" +#include + #include "imgui/imgui.h" namespace yaze { @@ -79,6 +81,30 @@ void CommandManager::InitializeDefaults() { {"H", {[]() { /* Help logic */ }, 'H', "Help", "Show help information"}}}; } +void CommandManager::SaveKeybindings(const std::string& filepath) { + std::ofstream out(filepath); + if (out.is_open()) { + for (const auto& [shortcut, info] : commands_) { + out << shortcut << " " << info.mnemonic << " " << info.name << " " + << info.desc << "\n"; + } + out.close(); + } +} + +void CommandManager::LoadKeybindings(const std::string& filepath) { + std::ifstream in(filepath); + if (in.is_open()) { + commands_.clear(); + std::string shortcut, name, desc; + char mnemonic; + while (in >> shortcut >> mnemonic >> name >> desc) { + commands_[shortcut] = {nullptr, mnemonic, name, desc}; + } + in.close(); + } +} + } // namespace editor } // namespace app } // namespace yaze diff --git a/src/app/editor/system/command_manager.h b/src/app/editor/system/command_manager.h index e9e62732..543345b8 100644 --- a/src/app/editor/system/command_manager.h +++ b/src/app/editor/system/command_manager.h @@ -43,6 +43,9 @@ class CommandManager { void InitializeDefaults(); + void SaveKeybindings(const std::string& filepath); + void LoadKeybindings(const std::string& filepath); + private: std::unordered_map commands_; };