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, IPC::SkyEvent::SkyEvent};
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
17	view_identifier:String,
18
19	element_handle:String,
20
21	is_expanded:bool,
22) -> Result<(), CommonError> {
23	dev_log!(
24		"extensions",
25		"[TreeViewProvider] Node '{}' in view '{}' expanded: {}",
26		element_handle,
27		view_identifier,
28		is_expanded
29	);
30
31	// Persist expansion state in TreeViewStateDTO for state restoration
32
33	// Propagate to frontend
34	env.ApplicationHandle
35		.emit(
36			SkyEvent::TreeViewNodeExpanded.AsStr(),
37			json!({
38				"viewId": view_identifier,
39				"elementHandle": element_handle,
40				"expanded": is_expanded
41			}),
42		)
43		.map_err(|Error| {
44			CommonError::UserInterfaceInteraction { Reason:format!("Failed to emit node expanded event: {}", Error) }
45		})
46}
47
48/// Handles tree selection changes.
49/// Called when the user selects or deselects items in the tree view.
50pub(super) async fn on_tree_selection_changed(
51	env:&crate::Environment::MountainEnvironment::MountainEnvironment,
52
53	view_identifier:String,
54
55	selected_handles:Vec<String>,
56) -> Result<(), CommonError> {
57	dev_log!(
58		"extensions",
59		"[TreeViewProvider] Selection changed in view '{}': {} items selected",
60		view_identifier,
61		selected_handles.len()
62	);
63
64	// Persist selection state in TreeViewStateDTO for state restoration
65
66	// Propagate to frontend
67	env.ApplicationHandle
68		.emit(
69			SkyEvent::TreeViewSelectionChanged.AsStr(),
70			json!({
71				"viewId": view_identifier,
72				"selectedHandles": selected_handles
73			}),
74		)
75		.map_err(|Error| {
76			CommonError::UserInterfaceInteraction {
77				Reason:format!("Failed to emit selection changed event: {}", Error),
78			}
79		})
80}