pub struct Keymap { /* private fields */ }Expand description
Default shortcuts plus user overrides, indexed for lookup by chord.
Implementations§
Source§impl Keymap
impl Keymap
Sourcepub fn new<'a>(
platform: Platform,
defaults: impl IntoIterator<Item = (&'a str, Option<&'a str>)>,
) -> Self
pub fn new<'a>( platform: Platform, defaults: impl IntoIterator<Item = (&'a str, Option<&'a str>)>, ) -> Self
A keymap from (command id, default shortcut text) pairs. Commands without a default key
(None) are known, so the user can bind them. Unparseable defaults are skipped and listed
in Keymap::invalid_defaults.
Sourcepub fn from_registry<S: Host>(
registry: &Registry<S>,
platform: Platform,
) -> Self
pub fn from_registry<S: Host>( registry: &Registry<S>, platform: Platform, ) -> Self
The default keymap of a command table.
pub fn platform(&self) -> Platform
Sourcepub fn invalid_defaults(&self) -> &[(String, String)]
pub fn invalid_defaults(&self) -> &[(String, String)]
Default shortcuts that did not parse: (command id, text).
Sourcepub fn lookup(&self, chord: &Chord) -> Option<&str>
pub fn lookup(&self, chord: &Chord) -> Option<&str>
The command a chord runs (user bindings first, then declaration order).
Sourcepub fn commands_for(&self, chord: &Chord) -> Vec<&str>
pub fn commands_for(&self, chord: &Chord) -> Vec<&str>
Every command bound to a chord, in lookup order.
Sourcepub fn keys_for(&self, id: &str) -> &[Chord]
pub fn keys_for(&self, id: &str) -> &[Chord]
The keys that run a command now (its overrides, else its defaults).
Sourcepub fn default_keys(&self, id: &str) -> &[Chord]
pub fn default_keys(&self, id: &str) -> &[Chord]
The default keys of a command.
Sourcepub fn bind(&mut self, id: &str, keys: Vec<Chord>) -> bool
pub fn bind(&mut self, id: &str, keys: Vec<Chord>) -> bool
Replace a command’s keys (an empty list unbinds it). Returns false for an unknown command.
pub fn reset_all(&mut self)
Sourcepub fn would_conflict(&self, id: &str, chord: &Chord) -> Vec<&str>
pub fn would_conflict(&self, id: &str, chord: &Chord) -> Vec<&str>
Commands other than id that already use chord (to warn before binding).
Sourcepub fn conflicts(&self) -> Vec<Conflict>
pub fn conflicts(&self) -> Vec<Conflict>
Every chord claimed by more than one command, sorted by chord.
Sourcepub fn apply_overrides(&mut self, overrides: &Overrides) -> usize
pub fn apply_overrides(&mut self, overrides: &Overrides) -> usize
Apply saved overrides. Never fails: unknown commands and keys that don’t parse are skipped (their count is returned), and the input is capped.
Sourcepub fn apply_overrides_json(&mut self, value: &Value) -> usize
pub fn apply_overrides_json(&mut self, value: &Value) -> usize
Read overrides from a settings value ({"bindings": {...}}); anything malformed is ignored.