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