MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / readFromConfig

Method readFromConfig

src/openboardview/UI/Keyboard/KeyBindings.cpp:99–141  ·  view source on GitHub ↗

Serialization/deserialization use '|' to specify multiple bindings and '~' to combine with modifiers, so they cannot be used in key names

Source from the content-addressed store, hash-verified

97
98// Serialization/deserialization use '|' to specify multiple bindings and '~' to combine with modifiers, so they cannot be used in key names
99void KeyBindings::readFromConfig(Confparse &obvconfig) {
100 for (auto &keybinding : keybindings) {
101 auto confline = obvconfig.ParseStr(("KeyBinding" + keybinding.first).c_str(), nullptr);
102 if (confline == nullptr)
103 continue;
104
105 // Multiple bindings for a single function are combined with bindingSeparator '|'
106 std::vector<KeyBinding> bindings;
107 for (auto &kbs : split_string(confline, bindingSeparator)) {
108 //Modifiers combined with modifierSeparator '~' to key, key always specified last
109 auto keyNames = split_string(kbs, modifierSeparator);
110 if (keyNames.empty())
111 continue;
112
113 std::vector<ImGuiKey> keys;
114 keys.reserve(keyNames.size());
115
116 // Parse key names to ImGui keys
117 std::transform(keyNames.begin(), keyNames.end(), std::back_inserter(keys), [this](std::string &keyName) -> ImGuiKey {
118 // Replace some serialization-compatible keys with the ImGui-compatible name
119 auto deserializedNameIt = deserializeName.find(keyName);
120 if (deserializedNameIt != deserializeName.end()) {
121 keyName = deserializedNameIt->second;
122 }
123
124 auto key = nameToKey.find(keyName);
125 if (key == nameToKey.end()) {
126 SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Unknown key name: %s", keyName.c_str());
127 return ImGuiKey_None;
128 } else {
129 return key->second;
130 }
131 });
132
133 std::vector<ImGuiKey> modifiers(keys.begin(), keys.end()-1);
134
135 bindings.push_back({keys.back(), modifiers});
136 }
137 keybinding.second = bindings;
138 }
139
140 writeToConfig(obvconfig);
141}
142
143void KeyBindings::writeToConfig(Confparse &obvconfig) {
144 for (auto &keybinding : keybindings) {

Callers

nothing calls this directly

Calls 2

split_stringFunction · 0.85
ParseStrMethod · 0.80

Tested by

no test coverage detected