Add keybinding save and load functionality to CommandManager

This commit is contained in:
scawful
2024-11-10 09:03:50 -05:00
parent d7f62f4fd4
commit d118857e2e
3 changed files with 29 additions and 1 deletions

View File

@@ -92,7 +92,6 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
absl::Status status_; absl::Status status_;
ImVector<int> active_tabs_;
std::vector<Editor *> active_editors_; std::vector<Editor *> active_editors_;
emu::Emulator emulator_; emu::Emulator emulator_;

View File

@@ -1,5 +1,7 @@
#include "command_manager.h" #include "command_manager.h"
#include <fstream>
#include "imgui/imgui.h" #include "imgui/imgui.h"
namespace yaze { namespace yaze {
@@ -79,6 +81,30 @@ void CommandManager::InitializeDefaults() {
{"H", {[]() { /* Help logic */ }, 'H', "Help", "Show help information"}}}; {"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 editor
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

@@ -43,6 +43,9 @@ class CommandManager {
void InitializeDefaults(); void InitializeDefaults();
void SaveKeybindings(const std::string& filepath);
void LoadKeybindings(const std::string& filepath);
private: private:
std::unordered_map<std::string, CommandInfo> commands_; std::unordered_map<std::string, CommandInfo> commands_;
}; };