Mountain/Environment/TreeViewProvider/
Events.rs

1//! # Tree View Event Handlers
2//!
3//! Internal helper functions for handling user interaction events
4//! (expansion, selection).
5
6use CommonLibrary::Error::CommonError::CommonError;
7use log::info;
8use serde_json::json;
9use tauri::Emitter;
10
11use crate::Environment::Utility;
12
13/// Handles tree node expansion/collapse events.
14/// Called when a user expands or collapses a node in the tree view.
15pub(super) async fn on_tree_node_expanded(
16	env:&crate::Environment::MountainEnvironment::MountainEnvironment,
17	view_identifier:String,
18	element_handle:String,
19	is_expanded:bool,
20) -> Result<(), CommonError> {
21	info!(
22		"[TreeViewProvider] Node '{}' in view '{}' expanded: {}",
23		element_handle, view_identifier, is_expanded
24	);
25
26	// Persist expansion state in TreeViewStateDTO for state restoration
27
28	// Propagate to frontend
29	env.ApplicationHandle
30		.emit(
31			"sky://tree-view/node-expanded",
32			json!({
33				"ViewIdentifier": view_identifier,
34				"ElementHandle": element_handle,
35				"IsExpanded": is_expanded
36			}),
37		)
38		.map_err(|Error| {
39			CommonError::UserInterfaceInteraction { Reason:format!("Failed to emit node expanded event: {}", Error) }
40		})
41}
42
43/// Handles tree selection changes.
44/// Called when the user selects or deselects items in the tree view.
45pub(super) async fn on_tree_selection_changed(
46	env:&crate::Environment::MountainEnvironment::MountainEnvironment,
47	view_identifier:String,
48	selected_handles:Vec<String>,
49) -> Result<(), CommonError> {
50	info!(
51		"[TreeViewProvider] Selection changed in view '{}': {} items selected",
52		view_identifier,
53		selected_handles.len()
54	);
55
56	// Persist selection state in TreeViewStateDTO for state restoration
57
58	// Propagate to frontend
59	env.ApplicationHandle
60		.emit(
61			"sky://tree-view/selection-changed",
62			json!({
63				"ViewIdentifier": view_identifier,
64				"SelectedHandles": selected_handles
65			}),
66		)
67		.map_err(|Error| {
68			CommonError::UserInterfaceInteraction {
69				Reason:format!("Failed to emit selection changed event: {}", Error),
70			}
71		})
72}