Skip to main content

Mountain/RPC/CocoonService/GenericRequest/WindowDialogs/
ShowSaveDialog.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::SaveDialogOptionsDTO::SaveDialogOptionsDTO;
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 = SaveDialogOptionsDTO {
19		Base:CommonLibrary::UserInterface::DTO::DialogOptionsDTO::DialogOptionsDTO { Title, ..Default::default() },
20		..SaveDialogOptionsDTO::default()
21	};
22
23	match Env.ShowSaveDialog(Some(Options)).await {
24		Ok(Some(Path)) => super::super::FileSystem::OkResponse(RequestId, &json!(format!("file://{}", Path.display()))),
25
26		Ok(None) => super::super::FileSystem::OkResponse(RequestId, &Value::Null),
27
28		Err(Error) => super::super::FileSystem::ErrResponse(RequestId, -32000, Error.to_string()),
29	}
30}