config: Allow receiving a string repr of a shortcut
This commit is contained in:
parent
f9dc67a24a
commit
98b869c15a
1 changed files with 30 additions and 0 deletions
|
|
@ -54,6 +54,36 @@ pub struct StaticConfig {
|
||||||
pub data_control_enabled: bool,
|
pub data_control_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StaticConfig {
|
||||||
|
pub fn get_shortcut_for_action(&self, action: &Action) -> Option<String> {
|
||||||
|
let possible_variants = self
|
||||||
|
.key_bindings
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, a)| *a == action)
|
||||||
|
.map(|(b, _)| b)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
possible_variants
|
||||||
|
.iter()
|
||||||
|
.find(|b| b.key.is_none()) // prefer short bindings
|
||||||
|
.or_else(|| {
|
||||||
|
possible_variants
|
||||||
|
.iter() // prefer bindings containing arrow keys
|
||||||
|
.find(|b| {
|
||||||
|
matches!(
|
||||||
|
b.key,
|
||||||
|
Some(Keysym::Down)
|
||||||
|
| Some(Keysym::Up)
|
||||||
|
| Some(Keysym::Left)
|
||||||
|
| Some(Keysym::Right)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.or_else(|| possible_variants.first()) // take the first one
|
||||||
|
.map(|binding| binding.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DynamicConfig {
|
pub struct DynamicConfig {
|
||||||
outputs: (Option<PathBuf>, OutputsConfig),
|
outputs: (Option<PathBuf>, OutputsConfig),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue