Skip to main content

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

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