Skip to main content

Mountain/RPC/CocoonService/GenericRequest/WindowDialogs/
ShowOpenDialog.rs

1#![allow(unused_variables, dead_code, unused_imports)]
2
3use serde_json::{Value, json};
4use tonic::Response;
5use CommonLibrary::UserInterface::UserInterfaceProvider::UserInterfaceProvider;
6
7use crate::{Environment::MountainEnvironment::MountainEnvironment, Vine::Generated::GenericResponse};
8
9pub async fn Fn(RequestId:u64, Params:Value, Env:&MountainEnvironment) -> Response<GenericResponse> {
10	use CommonLibrary::UserInterface::DTO::OpenDialogOptionsDTO::OpenDialogOptionsDTO;
11
12	let Title = Params
13		.get(0)
14		.and_then(|V| V.get("title"))
15		.and_then(|T| T.as_str())
16		.map(|S| S.to_string());
17
18	let Options = OpenDialogOptionsDTO {
19		Base:CommonLibrary::UserInterface::DTO::DialogOptionsDTO::DialogOptionsDTO { Title, ..Default::default() },
20		..OpenDialogOptionsDTO::default()
21	};
22
23	match Env.ShowOpenDialog(Some(Options)).await {
24		Ok(Some(Paths)) => {
25			let Uris:Vec<String> = Paths.iter().map(|P| format!("file://{}", P.display())).collect();
26
27			super::super::FileSystem::OkResponse(RequestId, &json!(Uris))
28		},
29
30		Ok(None) => super::super::FileSystem::OkResponse(RequestId, &json!(serde_json::Value::Array(vec![]))),
31
32		Err(Error) => super::super::FileSystem::ErrResponse(RequestId, -32000, Error.to_string()),
33	}
34}