Jazz2::Editor::ActionRegistry class

All actions of the level editor.

Public static functions

static auto ScopesOverlap(ActionScope a, ActionScope b) -> bool
Returns true if the shortcuts of actions of two scopes work at the same time.
static auto SelfTest() -> std::int32_t
Tests reading and writing shortcuts and the presets, returns the number of problems found.

Public functions

auto Add(StringView id, StringView label, EditorIcon icon, Function<void()>&& execute) -> EditorAction&
Adds an action.
auto Find(StringView id) -> EditorAction*
Returns an action, or nullptr.
auto Execute(StringView id) -> bool
Runs an action if it can be done now, returns false if it can't, an identifier no action has is logged as in Find().
auto HandleKey(const KeyboardEvent& event, ActionScope scope = ActionScope::Edit, bool repeat = false, EditorAction** ran = nullptr) -> bool
Runs the action whose shortcut matches a key and works in scope, returns true if there was one.
auto GetAll() const -> const SmallVector<std::unique_ptr<EditorAction>, 0>&
Returns all actions, in the order they were added.
auto FindByShortcut(const Shortcut& shortcut, const EditorAction* except = nullptr) -> EditorAction*
Returns the action that has a shortcut, or nullptr.
auto HasConflict(const EditorAction& action) const -> bool
Returns true if another action has the same shortcut as one of an action and they work at the same time, the first one of them runs then.
void CaptureDefaults()
Remembers the shortcuts of all actions as their defaults, after they're all added.
void ResetToDefaults()
Gives all actions their default shortcuts back.
auto LoadOverrides(StringView path) -> bool
Changes shortcuts as a file of the user says, Jazz2.EditorHotkeys.json.
auto SaveOverrides(StringView path) const -> bool
Saves the shortcuts that differ from the defaults, returns false if they can't be saved.
auto ExportKeymap(StringView path) const -> bool
Saves all shortcuts of all actions, to be read by ImportKeymap() elsewhere.
auto ImportKeymap(StringView path) -> bool
Gives all actions the shortcuts of a file written by ExportKeymap(), or of an override file, the rest their defaults.
void ApplyPreset(KeymapPreset preset, SmallVectorImpl<String>* cleared = nullptr)
Gives all actions the shortcuts of a preset.
auto MatchesWhileTyping(const KeyboardEvent& event) const -> bool
Returns true if a key runs an action that works while a text is typed, which is in the editor.

Function documentation

EditorAction* Jazz2::Editor::ActionRegistry::Find(StringView id)

Returns an action, or nullptr.

An identifier no action has is logged as a warning, once for each, so a typo in one shows in the log. Identifiers are in ActionIds.

bool Jazz2::Editor::ActionRegistry::HandleKey(const KeyboardEvent& event, ActionScope scope = ActionScope::Edit, bool repeat = false, EditorAction** ran = nullptr)

Runs the action whose shortcut matches a key and works in scope, returns true if there was one.

With repeat the key is held and repeats, an action that ignores it (see EditorAction::IgnoresRepeat) takes the key without running. ran, if given, gets the action that ran, or nullptr.

EditorAction* Jazz2::Editor::ActionRegistry::FindByShortcut(const Shortcut& shortcut, const EditorAction* except = nullptr)

Returns the action that has a shortcut, or nullptr.

If except is set, it's another action whose shortcut works when the one of except does.

bool Jazz2::Editor::ActionRegistry::LoadOverrides(StringView path)

Changes shortcuts as a file of the user says, Jazz2.EditorHotkeys.json.

The file has an object of action identifiers. Each has the shortcut as text, such as "Ctrl+Shift+Z" or "Mouse 4", or null for no shortcut, or an object of "Key" and "Alternate" if the other shortcut differs too. The form of older versions, [key, modifiers] with the key as a number of Keys, is still read. Actions not in it keep their defaults, a shortcut that can't be read is left out with a warning.

void Jazz2::Editor::ActionRegistry::ApplyPreset(KeymapPreset preset, SmallVectorImpl<String>* cleared = nullptr)

Gives all actions the shortcuts of a preset.

Starts from the defaults, the actions that had a key the preset gives to another one are left without it, their names are added to cleared. Actions the preset names that don't exist are left out.