Mountain/RPC/CocoonService/GenericRequest/WindowDialogs/
ShowInputBox.rs1use serde_json::{Value, json};
2use tonic::Response;
3use CommonLibrary::UserInterface::UserInterfaceProvider::UserInterfaceProvider;
4use ::Vine::Generated::GenericResponse;
5
6use crate::Environment::MountainEnvironment::MountainEnvironment;
7
8pub async fn Fn(RequestId:u64, Params:Value, Env:&MountainEnvironment) -> Response<GenericResponse> {
9 use CommonLibrary::UserInterface::DTO::InputBoxOptionsDTO::InputBoxOptionsDTO;
10
11 let Opts = Params.get(0);
12
13 let Options = InputBoxOptionsDTO {
14 Prompt:Opts
15 .and_then(|V| V.get("prompt"))
16 .and_then(|P| P.as_str())
17 .map(|S| S.to_string()),
18
19 PlaceHolder:Opts
20 .and_then(|V| V.get("placeHolder"))
21 .and_then(|P| P.as_str())
22 .map(|S| S.to_string()),
23
24 IsPassword:Some(Opts.and_then(|V| V.get("password")).and_then(|B| B.as_bool()).unwrap_or(false)),
25
26 Value:Opts
27 .and_then(|V| V.get("value"))
28 .and_then(|V| V.as_str())
29 .map(|S| S.to_string()),
30
31 Title:None,
32
33 IgnoreFocusOut:None,
34 };
35
36 match Env.ShowInputBox(Some(Options)).await {
37 Ok(Some(Text)) => super::super::FileSystem::OkResponse(RequestId, &json!(Text)),
38
39 Ok(None) => super::super::FileSystem::OkResponse(RequestId, &Value::Null),
40
41 Err(Error) => super::super::FileSystem::ErrResponse(RequestId, -32000, Error.to_string()),
42 }
43}