Common/UserInterface/ShowOpenDialog.rs
1// File: Common/Source/UserInterface/ShowOpenDialog.rs
2// Role: Defines the `ShowOpenDialog` ActionEffect.
3// Responsibilities:
4// - Provide a declarative effect for showing a native file or folder open
5// dialog.
6// - This effect abstracts the "what" (show an open dialog) from the "how"
7// (the UserInterfaceProvider implementation).
8
9//! # ShowOpenDialog Effect
10//!
11//! Defines the `ActionEffect` for showing a native file or folder open dialog.
12
13use std::{path::PathBuf, sync::Arc};
14
15use super::{DTO::OpenDialogOptionsDTO::OpenDialogOptionsDTO, UserInterfaceProvider::UserInterfaceProvider};
16use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
17
18/// Creates an effect that, when executed, will display a native dialog for
19/// opening files or folders.
20///
21/// It uses the `UserInterfaceProvider` capability from the environment to
22/// orchestrate the interaction with the frontend, which is responsible for
23/// showing the actual OS-level dialog.
24///
25/// # Parameters
26/// * `Options`: An `Option<OpenDialogOptionsDTO>` containing settings for the
27/// dialog, such as the title, whether to allow multiple selections, and if it
28/// should select folders instead of files.
29///
30/// # Returns
31/// An `ActionEffect` that resolves with an `Option<Vec<PathBuf>>`, containing
32/// the list of paths selected by the user, or `None` if the dialog was
33/// cancelled.
34pub fn ShowOpenDialog(
35 Options:Option<OpenDialogOptionsDTO>,
36) -> ActionEffect<Arc<dyn UserInterfaceProvider>, CommonError, Option<Vec<PathBuf>>> {
37 ActionEffect::New(Arc::new(move |Provider:Arc<dyn UserInterfaceProvider>| {
38 let OptionsClone = Options.clone();
39
40 Box::pin(async move { Provider.ShowOpenDialog(OptionsClone).await })
41 }))
42}