Mountain/IPC/WindServiceHandlers/UI/
Keybinding.rs1#![allow(non_snake_case, unused_variables)]
2use std::sync::Arc;
8
9use serde_json::{Value, json};
10
11use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
12
13pub async fn KeybindingAdd(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
14 let CommandId = Arguments
15 .first()
16 .and_then(|V| V.as_str())
17 .ok_or("keybinding:add requires commandId".to_string())?
18 .to_owned();
19 let KeyExpression = Arguments
20 .get(1)
21 .and_then(|V| V.as_str())
22 .ok_or("keybinding:add requires keybinding".to_string())?
23 .to_owned();
24 let When = Arguments.get(2).and_then(|V| V.as_str()).map(str::to_owned);
25 RunTime
26 .Environment
27 .ApplicationState
28 .Feature
29 .Keybindings
30 .AddKeybinding(CommandId, KeyExpression, When);
31 Ok(Value::Null)
32}
33
34pub async fn KeybindingRemove(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
35 let CommandId = Arguments
36 .first()
37 .and_then(|V| V.as_str())
38 .ok_or("keybinding:remove requires commandId".to_string())?;
39 RunTime
40 .Environment
41 .ApplicationState
42 .Feature
43 .Keybindings
44 .RemoveKeybinding(CommandId);
45 Ok(Value::Null)
46}
47
48pub async fn KeybindingLookup(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
49 let CommandId = Arguments
50 .first()
51 .and_then(|V| V.as_str())
52 .ok_or("keybinding:lookup requires commandId".to_string())?;
53 let Binding = RunTime
54 .Environment
55 .ApplicationState
56 .Feature
57 .Keybindings
58 .LookupKeybinding(CommandId);
59 Ok(Binding.map(|B| json!(B)).unwrap_or(Value::Null))
60}
61
62pub async fn KeybindingGetAll(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
63 let All = RunTime.Environment.ApplicationState.Feature.Keybindings.GetAllKeybindings();
64 Ok(json!(All))
65}