Skip to main content

Mountain/IPC/WindServiceHandlers/UI/
QuickInputShowQuickPick.rs

1#![allow(unused_variables)]
2
3//! Wire method: `quickInput:showQuickPick`.
4
5use std::sync::Arc;
6
7use serde_json::{Value, json};
8
9use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
10
11pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
12	use CommonLibrary::UserInterface::{
13		DTO::{QuickPickItemDTO::QuickPickItemDTO, QuickPickOptionsDTO::QuickPickOptionsDTO},
14		UserInterfaceProvider::UserInterfaceProvider,
15	};
16
17	let Items:Vec<QuickPickItemDTO> = Arguments
18		.first()
19		.and_then(|V| V.as_array())
20		.map(|Arr| {
21			Arr.iter()
22				.filter_map(|Item| {
23					let Label = Item.get("label").and_then(|L| L.as_str()).unwrap_or("").to_string();
24					let Description = Item.get("description").and_then(|D| D.as_str()).map(|S| S.to_string());
25					let Detail = Item.get("detail").and_then(|D| D.as_str()).map(|S| S.to_string());
26					let Picked = Item.get("picked").and_then(|P| P.as_bool()).unwrap_or(false);
27					Some(QuickPickItemDTO { Label, Description, Detail, Picked:Some(Picked), AlwaysShow:Some(false) })
28				})
29				.collect()
30		})
31		.unwrap_or_default();
32
33	let Options = QuickPickOptionsDTO {
34		PlaceHolder:Arguments
35			.get(1)
36			.and_then(|V| V.get("placeholder"))
37			.and_then(|P| P.as_str())
38			.map(|S| S.to_string()),
39
40		CanPickMany:Some(
41			Arguments
42				.get(1)
43				.and_then(|V| V.get("canPickMany"))
44				.and_then(|B| B.as_bool())
45				.unwrap_or(false),
46		),
47
48		Title:Arguments
49			.get(1)
50			.and_then(|V| V.get("title"))
51			.and_then(|T| T.as_str())
52			.map(|S| S.to_string()),
53		..Default::default()
54	};
55
56	let Result = RunTime
57		.Environment
58		.ShowQuickPick(Items, Some(Options))
59		.await
60		.map_err(|Error| format!("quickInput:showQuickPick failed: {}", Error))?;
61
62	match Result {
63		Some(Labels) => Ok(Labels.into_iter().next().map(|S| json!(S)).unwrap_or(Value::Null)),
64
65		None => Ok(Value::Null),
66	}
67}