Common/Document/
SaveDocumentAs.rs

1// File: Common/Source/Document/SaveDocumentAs.rs
2// Role: Defines the `SaveDocumentAs` ActionEffect.
3// Responsibilities:
4//   - Provide a declarative effect for saving a text document to a new
5//     location.
6//   - This effect abstracts the "what" (save a document as) from the "how" (the
7//     DocumentProvider implementation).
8
9//! # SaveDocumentAs Effect
10//!
11//! Defines the `ActionEffect` for saving a document to a new location.
12
13use std::sync::Arc;
14
15use url::Url;
16
17use super::DocumentProvider::DocumentProvider;
18use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
19
20/// Creates an effect that, when executed, will save a document to a new
21/// location. This is typically used for "Save As..." functionality.
22///
23/// It uses the `DocumentProvider` capability from the environment to perform
24/// the operation. If `NewTargetURI` is `None`, the provider is expected to
25/// interact with the user (via the `UserInterfaceProvider`) to prompt for a
26/// new save location.
27///
28/// # Parameters
29/// * `OriginalURI`: The `Url` of the document to save.
30/// * `NewTargetURI`: An optional `Url` for the new save location. If `None`, a
31///   save dialog should be shown to the user.
32///
33/// # Returns
34/// An `ActionEffect` that resolves with an `Option<Url>`, containing the
35/// final `Url` of the saved file or `None` if the operation was cancelled.
36pub fn SaveDocumentAs(
37	OriginalURI:Url,
38
39	NewTargetURI:Option<Url>,
40) -> ActionEffect<Arc<dyn DocumentProvider>, CommonError, Option<Url>> {
41	ActionEffect::New(Arc::new(move |Provider:Arc<dyn DocumentProvider>| {
42		let OriginalURIClone = OriginalURI.clone();
43
44		let NewTargetURIClone = NewTargetURI.clone();
45
46		Box::pin(async move { Provider.SaveDocumentAs(OriginalURIClone, NewTargetURIClone).await })
47	}))
48}