diff options
| author | Teddy Wing | 2018-09-25 13:25:20 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-09-25 13:25:20 +0200 |
| commit | 7a52917130bba42a772b278cce0db63db4fb43d5 (patch) | |
| tree | ca259c7b48cd18b0a4fc8dcdf7eae28ee83dadf1 /src | |
| parent | 69343f6d6ae1524adeba78e31efa48dca78f0d2b (diff) | |
| download | dome-key-map-7a52917130bba42a772b278cce0db63db4fb43d5.tar.bz2 | |
run_key_action_for_mode(): Get `MapGroup` from state
Now that there can be a `MapGroup` in the `State`, get it from there.
This will allow us to get the `MapGroup` from a configuration file.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cocoa_bridge.rs | 150 |
1 files changed, 77 insertions, 73 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index b941f7f..8e3b0ad 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -250,88 +250,92 @@ mode <play><up> { "; // Figure out how to persist this without re-parsing - let map_group = MapGroup::parse(sample_maps).unwrap(); - - let map = map_group.maps.get(trigger); - let mode = map_group.modes.get(trigger); - - if let Some(in_mode) = state.in_mode.clone() { - if let Some(mode) = map_group.modes.get(&in_mode) { - // Deactivate mode by pressing current mode trigger - if &in_mode[..] == trigger { - state.in_mode = None; - - return Some(KeyActionResult::new(ActionKind::Mode)) + // let map_group = MapGroup::parse(sample_maps).unwrap(); + match state.map_group { + Some(ref map_group) => { + let map = map_group.maps.get(trigger); + let mode = map_group.modes.get(trigger); + + if let Some(in_mode) = state.in_mode.clone() { + if let Some(mode) = map_group.modes.get(&in_mode) { + // Deactivate mode by pressing current mode trigger + if &in_mode[..] == trigger { + state.in_mode = None; + + return Some(KeyActionResult::new(ActionKind::Mode)) + } + + if let Some(map) = mode.get(trigger) { + return match map.kind { + MapKind::Map => { + Some( + KeyActionResult::new(ActionKind::Map) + .with_action(&map.action) + .in_mode(trigger) + ) + }, + MapKind::Command => { + Some( + KeyActionResult::new(ActionKind::Command) + .in_mode(trigger) + ) + }, + } + } + } } - if let Some(map) = mode.get(trigger) { - return match map.kind { - MapKind::Map => { - Some( - KeyActionResult::new(ActionKind::Map) - .with_action(&map.action) - .in_mode(trigger) - ) - }, - MapKind::Command => { - Some( - KeyActionResult::new(ActionKind::Command) - .in_mode(trigger) - ) - }, + // TODO: make sure this doesn't run when in_mode + if in_mode.is_none() { + if let Some(map) = map { + return match map.kind { + MapKind::Map => { + type_string(&map.action, &[], 0.0, 0.0); + + Some( + KeyActionResult::new(ActionKind::Map) + .with_action(&map.action) + ) + }, + MapKind::Command => { + Some( + KeyActionResult::new(ActionKind::Command) + ) + }, + // MapKind::Mode => { + // TODO: Maybe make a new type just for KeyActionResult that + // combines regular MapKinds and Mode + // }, + } } } - } - } - // TODO: make sure this doesn't run when in_mode - if in_mode.is_none() { - if let Some(map) = map { - return match map.kind { - MapKind::Map => { - type_string(&map.action, &[], 0.0, 0.0); - - Some( - KeyActionResult::new(ActionKind::Map) - .with_action(&map.action) - ) - }, - MapKind::Command => { - Some( - KeyActionResult::new(ActionKind::Command) - ) - }, - // MapKind::Mode => { - // TODO: Maybe make a new type just for KeyActionResult that - // combines regular MapKinds and Mode - // }, + if let Some(mode) = mode { + state.in_mode = Some(trigger.to_vec()); + + return Some( + KeyActionResult::new(ActionKind::Mode) + .in_mode(trigger) + ) } - } - } - if let Some(mode) = mode { - state.in_mode = Some(trigger.to_vec()); + // match map_group.get(trigger) { + // Some(map_action) => { + // Some(KeyActionResult { + // action: map_action.action, + // kind: MapKind::Map, + // }) + // }, + // None => { + // // TODO: Figure out how to error + // None + // }, + // } - return Some( - KeyActionResult::new(ActionKind::Mode) - .in_mode(trigger) - ) + None + }, + None => None, } - - // match map_group.get(trigger) { - // Some(map_action) => { - // Some(KeyActionResult { - // action: map_action.action, - // kind: MapKind::Map, - // }) - // }, - // None => { - // // TODO: Figure out how to error - // None - // }, - // } - - None } // fn run_command(command: Action) -> Result { |
