Skip to main content

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