Mountain/IPC/WindServiceHandler/
QuickInput.rs1#![allow(non_snake_case)]
2
3use std::sync::Arc;
6
7use serde_json::{Value, json};
8
9use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
10
11pub async fn handle_quick_input_show_quick_pick(
14 Runtime:Arc<ApplicationRunTime>,
15 Args:Vec<Value>,
16) -> Result<Value, String> {
17 use CommonLibrary::UserInterface::{
18 DTO::{QuickPickItemDTO::QuickPickItemDTO, QuickPickOptionsDTO::QuickPickOptionsDTO},
19 UserInterfaceProvider::UserInterfaceProvider,
20 };
21
22 let Items:Vec<QuickPickItemDTO> = Args
23 .first()
24 .and_then(|V| V.as_array())
25 .map(|Arr| {
26 Arr.iter()
27 .filter_map(|Item| {
28 let Label = Item.get("label").and_then(|L| L.as_str()).unwrap_or("").to_string();
29 let Description = Item.get("description").and_then(|D| D.as_str()).map(|S| S.to_string());
30 let Detail = Item.get("detail").and_then(|D| D.as_str()).map(|S| S.to_string());
31 let Picked = Item.get("picked").and_then(|P| P.as_bool()).unwrap_or(false);
32 Some(QuickPickItemDTO { Label, Description, Detail, Picked:Some(Picked), AlwaysShow:Some(false) })
33 })
34 .collect()
35 })
36 .unwrap_or_default();
37
38 let Options = QuickPickOptionsDTO {
39 PlaceHolder:Args
40 .get(1)
41 .and_then(|V| V.get("placeholder"))
42 .and_then(|P| P.as_str())
43 .map(|S| S.to_string()),
44 CanPickMany:Some(
45 Args.get(1)
46 .and_then(|V| V.get("canPickMany"))
47 .and_then(|B| B.as_bool())
48 .unwrap_or(false),
49 ),
50 Title:Args
51 .get(1)
52 .and_then(|V| V.get("title"))
53 .and_then(|T| T.as_str())
54 .map(|S| S.to_string()),
55 ..Default::default()
56 };
57
58 let PickResult = Runtime
59 .Environment
60 .ShowQuickPick(Items, Some(Options))
61 .await
62 .map_err(|Error| format!("quickInput:showQuickPick failed: {}", Error))?;
63
64 match PickResult {
65 Some(Labels) => Ok(Labels.into_iter().next().map(|S| json!(S)).unwrap_or(Value::Null)),
66 None => Ok(Value::Null),
67 }
68}
69
70pub async fn handle_quick_input_show_input_box(
73 Runtime:Arc<ApplicationRunTime>,
74 Args:Vec<Value>,
75) -> Result<Value, String> {
76 use CommonLibrary::UserInterface::{
77 DTO::InputBoxOptionsDTO::InputBoxOptionsDTO,
78 UserInterfaceProvider::UserInterfaceProvider,
79 };
80
81 let Opts = Args.first();
82 let Options = InputBoxOptionsDTO {
83 Prompt:Opts
84 .and_then(|V| V.get("prompt"))
85 .and_then(|P| P.as_str())
86 .map(|S| S.to_string()),
87 PlaceHolder:Opts
88 .and_then(|V| V.get("placeholder"))
89 .and_then(|P| P.as_str())
90 .map(|S| S.to_string()),
91 IsPassword:Some(Opts.and_then(|V| V.get("password")).and_then(|B| B.as_bool()).unwrap_or(false)),
92 Value:Opts
93 .and_then(|V| V.get("value"))
94 .and_then(|V| V.as_str())
95 .map(|S| S.to_string()),
96 Title:Opts
97 .and_then(|V| V.get("title"))
98 .and_then(|T| T.as_str())
99 .map(|S| S.to_string()),
100 IgnoreFocusOut:None,
101 };
102
103 let InputResult = Runtime
104 .Environment
105 .ShowInputBox(Some(Options))
106 .await
107 .map_err(|Error| format!("quickInput:showInputBox failed: {}", Error))?;
108
109 Ok(InputResult.map(|S| json!(S)).unwrap_or(Value::Null))
110}