Mountain/RPC/CocoonService/GenericRequest/WindowDialogs/
ShowOpenDialog.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::OpenDialogOptionsDTO::OpenDialogOptionsDTO;
10
11 let Title = Params
12 .get(0)
13 .and_then(|V| V.get("title"))
14 .and_then(|T| T.as_str())
15 .map(|S| S.to_string());
16
17 let Options = OpenDialogOptionsDTO {
18 Base:CommonLibrary::UserInterface::DTO::DialogOptionsDTO::DialogOptionsDTO { Title, ..Default::default() },
19 ..OpenDialogOptionsDTO::default()
20 };
21
22 match Env.ShowOpenDialog(Some(Options)).await {
23 Ok(Some(Paths)) => {
24 let Uris:Vec<String> = Paths.iter().map(|P| format!("file://{}", P.display())).collect();
25
26 super::super::FileSystem::OkResponse(RequestId, &json!(Uris))
27 },
28
29 Ok(None) => super::super::FileSystem::OkResponse(RequestId, &json!(serde_json::Value::Array(vec![]))),
30
31 Err(Error) => super::super::FileSystem::ErrResponse(RequestId, -32000, Error.to_string()),
32 }
33}