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