Mountain/ApplicationState/State/WorkspaceState/
WorkspaceState.rs1use std::sync::{
42 Arc,
43 Mutex as StandardMutex,
44 atomic::{AtomicBool, Ordering as AtomicOrdering},
45};
46
47use crate::{
48 ApplicationState::DTO::{WindowStateDTO::WindowStateDTO, WorkspaceFolderStateDTO::WorkspaceFolderStateDTO},
49 dev_log,
50};
51
52#[derive(Clone)]
54pub struct State {
55 pub WorkspaceFolders:Arc<StandardMutex<Vec<WorkspaceFolderStateDTO>>>,
57
58 pub WorkspaceConfigurationPath:Arc<StandardMutex<Option<std::path::PathBuf>>>,
60
61 pub IsTrusted:Arc<AtomicBool>,
63
64 pub WindowState:Arc<StandardMutex<WindowStateDTO>>,
66
67 pub ActiveDocumentURI:Arc<StandardMutex<Option<String>>>,
69}
70
71impl Default for State {
72 fn default() -> Self {
73 dev_log!("workspaces", "[WorkspaceState] Initializing default workspace state...");
74
75 Self {
76 WorkspaceFolders:Arc::new(StandardMutex::new(Vec::new())),
77 WorkspaceConfigurationPath:Arc::new(StandardMutex::new(None)),
78 IsTrusted:Arc::new(AtomicBool::new(false)),
79 WindowState:Arc::new(StandardMutex::new(WindowStateDTO::default())),
80 ActiveDocumentURI:Arc::new(StandardMutex::new(None)),
81 }
82 }
83}
84
85impl State {
86 pub fn GetTrustStatus(&self) -> bool { self.IsTrusted.load(AtomicOrdering::Relaxed) }
88
89 pub fn SetTrustStatus(&self, trusted:bool) {
91 self.IsTrusted.store(trusted, AtomicOrdering::Relaxed);
92 dev_log!("workspaces", "[WorkspaceState] Trust status set to: {}", trusted);
93 }
94
95 pub fn GetConfigurationPath(&self) -> Option<std::path::PathBuf> {
97 self.WorkspaceConfigurationPath.lock().ok().and_then(|guard| guard.clone())
98 }
99
100 pub fn SetConfigurationPath(&self, path:Option<std::path::PathBuf>) {
102 if let Ok(mut guard) = self.WorkspaceConfigurationPath.lock() {
103 *guard = path.clone();
104 dev_log!("workspaces", "[WorkspaceState] Configuration path updated to: {:?}", path);
105 }
106 }
107
108 pub fn GetActiveDocumentURI(&self) -> Option<String> {
110 self.ActiveDocumentURI.lock().ok().and_then(|guard| guard.clone())
111 }
112
113 pub fn SetActiveDocumentURI(&self, uri:Option<String>) {
115 if let Ok(mut guard) = self.ActiveDocumentURI.lock() {
116 *guard = uri.clone();
117 dev_log!("workspaces", "[WorkspaceState] Active document URI updated to: {:?}", uri);
118 }
119 }
120
121 pub fn GetWorkspaceFolders(&self) -> Vec<WorkspaceFolderStateDTO> {
123 self.WorkspaceFolders.lock().ok().map(|guard| guard.clone()).unwrap_or_default()
124 }
125
126 pub fn SetWorkspaceFolders(&self, folders:Vec<WorkspaceFolderStateDTO>) {
128 if let Ok(mut guard) = self.WorkspaceFolders.lock() {
129 *guard = folders;
130 dev_log!(
131 "workspaces",
132 "[WorkspaceState] Workspace folders updated ({} folders)",
133 guard.len()
134 );
135 }
136 }
137
138 pub fn GetWindowState(&self) -> WindowStateDTO {
140 self.WorkspaceFolders
141 .lock()
142 .ok()
143 .and_then(|_| self.WindowState.lock().ok().map(|guard| guard.clone()))
144 .unwrap_or_default()
145 }
146
147 pub fn SetWindowState(&self, state:WindowStateDTO) {
149 if let Ok(mut guard) = self.WindowState.lock() {
150 *guard = state;
151 dev_log!("workspaces", "[WorkspaceState] Window state updated");
152 }
153 }
154}