Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Command/TreeView/
GetTreeViewItem.rs

1//! Tauri command - fetch a single tree item's metadata (label, icon,
2//! description, command, contextValue) by its element handle.
3
4use std::sync::Arc;
5
6use CommonLibrary::{
7	Environment::Requires::Requires,
8	TreeView::TreeViewProvider::TreeViewProvider as CommonTreeViewProvider,
9};
10use serde_json::{Value, json};
11use tauri::{AppHandle, Manager, State, Wry, command};
12
13use crate::{
14	ApplicationState::State::ApplicationState::ApplicationState,
15	Environment::MountainEnvironment::MountainEnvironment,
16	RunTime::ApplicationRunTime::ApplicationRunTime,
17	dev_log,
18};
19
20#[command]
21pub async fn GetTreeViewItem(
22	ApplicationHandle:AppHandle<Wry>,
23
24	_State:State<'_, Arc<ApplicationState>>,
25
26	ViewId:String,
27
28	ElementHandle:String,
29) -> Result<Value, String> {
30	dev_log!("commands", "getting TreeView item for '{}', element: {}", ViewId, ElementHandle);
31
32	let RunTime = ApplicationHandle.state::<Arc<ApplicationRunTime>>().inner().clone();
33
34	let Environment:Arc<MountainEnvironment> = RunTime.Environment.clone();
35
36	let TreeProvider:Arc<dyn CommonTreeViewProvider> = Environment.Require();
37
38	match TreeProvider.GetTreeItem(ViewId.clone(), ElementHandle).await {
39		Ok(Item) => Ok(json!(Item)),
40
41		Err(Error) => {
42			let ErrorMessage = format!("Failed to get tree item for view '{}': {}", ViewId, Error);
43
44			dev_log!("commands", "error: {}", ErrorMessage);
45
46			Err(ErrorMessage)
47		},
48	}
49}