Common/Document/
SaveAllDocuments.rs

1//! # SaveAllDocuments Effect
2//!
3//! Defines the `ActionEffect` for saving all modified ("dirty") documents.
4
5use std::sync::Arc;
6
7use super::DocumentProvider::DocumentProvider;
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will save all documents that have
11/// unsaved changes.
12///
13/// It uses the `DocumentProvider` capability from the environment to perform
14/// the operation. This involves iterating through all open documents, checking
15/// their dirty state, and writing the modified ones to disk.
16///
17/// # Parameters
18/// * `IncludeUntitled`: If `true`, the operation will also attempt to save
19///   untitled documents. This will typically trigger a "Save As..." dialog (via
20///   the `UserInterfaceProvider`) for each untitled document.
21///
22/// # Returns
23/// An `ActionEffect` that resolves with a `Vec<bool>`, where each boolean
24/// corresponds to the success of saving a particular document.
25pub fn SaveAllDocuments(IncludeUntitled:bool) -> ActionEffect<Arc<dyn DocumentProvider>, CommonError, Vec<bool>> {
26	ActionEffect::New(Arc::new(move |Provider:Arc<dyn DocumentProvider>| {
27		Box::pin(async move { Provider.SaveAllDocuments(IncludeUntitled).await })
28	}))
29}