Common/UserInterface/
ShowSaveDialog.rs

1//! # ShowSaveDialog Effect
2//!
3//! Defines the `ActionEffect` for showing a native file save dialog.
4
5use std::{path::PathBuf, sync::Arc};
6
7use super::{DTO::SaveDialogOptionsDTO::SaveDialogOptionsDTO, UserInterfaceProvider::UserInterfaceProvider};
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will display a native dialog for
11/// saving a file.
12///
13/// It uses the `UserInterfaceProvider` capability from the environment to
14/// orchestrate the interaction with the frontend.
15///
16/// # Parameters
17/// * `Options`: An `Option<SaveDialogOptionsDTO>` containing settings for the
18///   dialog, such as the title and default path.
19///
20/// # Returns
21/// An `ActionEffect` that resolves with an `Option<PathBuf>`, containing the
22/// path selected by the user for saving, or `None` if the dialog was
23/// cancelled.
24pub fn ShowSaveDialog(
25	Options:Option<SaveDialogOptionsDTO>,
26) -> ActionEffect<Arc<dyn UserInterfaceProvider>, CommonError, Option<PathBuf>> {
27	ActionEffect::New(Arc::new(move |Provider:Arc<dyn UserInterfaceProvider>| {
28		let OptionsClone = Options.clone();
29
30		Box::pin(async move { Provider.ShowSaveDialog(OptionsClone).await })
31	}))
32}