| 155 | } |
| 156 | |
| 157 | void KeybindingsMenu::setKeybinding(KeyChord desc) { |
| 158 | if (!m_activeKeybinding) |
| 159 | return; |
| 160 | |
| 161 | auto out = inputDescriptorToJson(desc); |
| 162 | |
| 163 | auto config = Root::singleton().configuration(); |
| 164 | auto base = config->get("bindings"); |
| 165 | |
| 166 | auto action = m_childToAction.get(m_activeKeybinding); |
| 167 | auto key = InterfaceActionNames.getRight(action); |
| 168 | |
| 169 | auto bindings = OrderedHashSet<Json>::from(base.get(key).toArray()); |
| 170 | |
| 171 | if (bindings.contains(out)) |
| 172 | bindings.clear(); |
| 173 | |
| 174 | bindings.add(out); |
| 175 | |
| 176 | if (bindings.size() > m_maxBindings) |
| 177 | bindings.removeFirst(); |
| 178 | |
| 179 | base = base.set(key, JsonArray::from(bindings)); |
| 180 | |
| 181 | config->set("bindings", base); |
| 182 | |
| 183 | StringList buttonText; |
| 184 | |
| 185 | for (auto const& entry : base.get(key).iterateArray()) { |
| 186 | try { |
| 187 | auto stored = inputDescriptorFromJson(entry); |
| 188 | buttonText.push_back(printInputDescriptor(stored)); |
| 189 | } catch (StarException const& e) { |
| 190 | buttonText.push_back("unknown"); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | convert<ButtonWidget>(m_activeKeybinding)->setText(buttonText.join(", ")); |
| 195 | |
| 196 | apply(); |
| 197 | exitActiveMode(); |
| 198 | } |
| 199 | |
| 200 | void KeybindingsMenu::clearActive() { |
| 201 | if (!m_activeKeybinding) |
nothing calls this directly
no test coverage detected