Skip to main content

Mountain/Command/TreeView/
GetTreeViewItem.rs

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