gfx/key_mapping_editor.h
KeyMappingEditorComponent: letting the user choose the keys.
#include <sonore/gfx/key_mapping_editor.h>- 1type
- Guides: The native editor
On this page
Design notes
What it edits
commands.h's CommandManager: named commands with a category and default keys, and the table of which keys reach which command. This lists the commands under their categories with their keys drawn as keycaps beside them. A click on "+" -- or Return on a row -- waits for a key and assigns it; a click on a keycap offers to change or remove it; Delete removes a row's last key; and "Reset to defaults" puts every key back where the plugin registered it. saveMappings() on the manager is what an owner writes to its settings when onMappingsChanged fires.
A key belongs to one command
CommandManager already enforces that -- assigning a key takes it from whoever had it -- and silently. That is right for code and wrong for a person: pressing Ctrl+S for "Save As" and finding "Save" has lost its key next time they reach for it is the bug report this editor would generate. So a key that is already taken is a QUESTION, asked in an AlertOverlay, naming the command that would lose it; "Reassign" moves it and "Cancel" changes nothing.
Capturing a key
While waiting, the editor holds the keyboard and the next key IS the answer -- Tab and Return included, since both are keys somebody may want. Escape alone cancels, which leaves Escape itself unassignable from here; a command that wants it registers it as a default. A click anywhere cancels too.
Types 1
class KeyMappingEditorComponent : public Widget
A list of a CommandManager's commands, by category, where the user assigns and removes their keys -- the reference's KeyMappingEditorComponent. The file comment covers what each click and key does, and why a key that is already taken is asked about rather than silently moved.
Holds a REFERENCE to the manager, which must outlive it, and edits the manager's table directly; persisting it is the owner's job, with saveMappings() from onMappingsChanged. The list is read once on construction: call refresh() after registering more commands. Message thread only.