Common/UserInterface/
UserInterfaceProvider.rs

1//! # UserInterfaceProvider Trait
2//!
3//! Defines the abstract service trait for all modal user interface
4//! interactions.
5
6use std::path::PathBuf;
7
8use async_trait::async_trait;
9use serde_json::Value;
10
11use super::DTO::{
12	InputBoxOptionsDTO::InputBoxOptionsDTO,
13	MessageSeverity::MessageSeverity,
14	OpenDialogOptionsDTO::OpenDialogOptionsDTO,
15	QuickPickItemDTO::QuickPickItemDTO,
16	QuickPickOptionsDTO::QuickPickOptionsDTO,
17	SaveDialogOptionsDTO::SaveDialogOptionsDTO,
18};
19use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
20
21/// An abstract service contract for an environment component that can perform
22/// UI interactions that require user input, such as showing dialogs, messages,
23
24/// and quick pick menus.
25///
26/// This trait is implemented by `MountainEnvironment`, and the methods are
27/// typically handled by sending events to the `Sky` frontend and awaiting a
28/// response.
29#[async_trait]
30pub trait UserInterfaceProvider: Environment + Send + Sync {
31	/// Shows a message to the user with a given severity and optional action
32	/// buttons.
33	///
34	/// # Returns
35	/// A `Result` containing an `Option<String>` with the title of the clicked
36	/// action button, or `None` if the message was dismissed.
37	async fn ShowMessage(
38		&self,
39
40		Severity:MessageSeverity,
41
42		Message:String,
43
44		Options:Option<Value>,
45	) -> Result<Option<String>, CommonError>;
46
47	/// Shows a dialog for opening files or folders.
48	///
49	/// # Returns
50	/// A `Result` containing an `Option<Vec<PathBuf>>` with the selected
51	/// paths, or `None` if the dialog was cancelled.
52	async fn ShowOpenDialog(&self, Options:Option<OpenDialogOptionsDTO>) -> Result<Option<Vec<PathBuf>>, CommonError>;
53
54	/// Shows a dialog for saving a file.
55	///
56	/// # Returns
57	/// A `Result` containing the selected save path as an `Option<PathBuf>`, or
58	/// `None` if the dialog was cancelled.
59	async fn ShowSaveDialog(&self, Options:Option<SaveDialogOptionsDTO>) -> Result<Option<PathBuf>, CommonError>;
60
61	/// Shows a quick pick list to the user.
62	///
63	/// # Returns
64	/// A `Result` containing an `Option<Vec<String>>` with the labels of the
65	/// selected items, or `None` if the quick pick was cancelled.
66	async fn ShowQuickPick(
67		&self,
68
69		Items:Vec<QuickPickItemDTO>,
70
71		Options:Option<QuickPickOptionsDTO>,
72	) -> Result<Option<Vec<String>>, CommonError>;
73
74	/// Shows an input box to solicit a string input from the user.
75	///
76	/// # Returns
77	/// A `Result` containing the string entered by the user as an
78	/// `Option<String>`, or `None` if the input box was cancelled.
79	async fn ShowInputBox(&self, Options:Option<InputBoxOptionsDTO>) -> Result<Option<String>, CommonError>;
80}