Common/WorkSpace/
OpenFile.rs

1//! # OpenFile Effect
2//!
3//! Defines the `ActionEffect` for requesting that a file be opened in an
4//! editor.
5
6use std::{path::PathBuf, sync::Arc};
7
8use super::WorkSpaceProvider::WorkSpaceProvider;
9use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
10
11/// Creates an effect that, when executed, will request that the host
12/// application open the specified file path in an editor.
13///
14/// It uses the `WorkSpaceProvider` capability from the environment. The actual
15/// implementation will likely involve creating a new document model (if one
16/// doesn't exist) and sending an event to the UI to reveal an editor for it.
17///
18/// # Parameters
19/// * `Path`: The `PathBuf` of the file to open.
20///
21/// # Returns
22/// An `ActionEffect` that resolves to `()` on success.
23pub fn OpenFile(Path:PathBuf) -> ActionEffect<Arc<dyn WorkSpaceProvider>, CommonError, ()> {
24	ActionEffect::New(Arc::new(move |Provider:Arc<dyn WorkSpaceProvider>| {
25		let PathClone = Path.clone();
26
27		Box::pin(async move { Provider.OpenFile(PathClone).await })
28	}))
29}