Skip to main content

Mountain/ApplicationState/State/FeatureState/Decorations/
DecorationsState.rs

1use std::{
2	collections::HashMap,
3	sync::{Arc, Mutex as StandardMutex},
4};
5
6use serde_json::Value;
7
8use crate::dev_log;
9
10/// A single file/folder decoration: badge letter, tooltip, color hint.
11#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
12pub struct DecorationData {
13	/// Single character badge shown in the explorer (e.g. "M" for modified).
14	pub Badge:Option<String>,
15
16	/// Tooltip text displayed on hover.
17	pub Tooltip:Option<String>,
18
19	/// Color hint for the item label (theme color ID, e.g.
20	/// "gitDecoration.modifiedResourceForeground").
21	pub Color:Option<String>,
22
23	/// Whether to propagate the badge to parent folders.
24	pub Propagate:Option<bool>,
25}
26
27/// Stores per-URI file decorations (git badges, error squiggles, custom
28/// badges).
29#[derive(Clone)]
30pub struct DecorationsState {
31	Entries:Arc<StandardMutex<HashMap<String, Value>>>,
32}
33
34impl Default for DecorationsState {
35	fn default() -> Self {
36		dev_log!("decorations", "[DecorationsState] Initializing default decorations state...");
37
38		Self { Entries:Arc::new(StandardMutex::new(HashMap::new())) }
39	}
40}
41
42impl DecorationsState {
43	/// Return the JSON decoration value for a URI, or `None` when not set.
44	pub fn GetDecoration(&self, Uri:&str) -> Option<Value> {
45		self.Entries.lock().ok().and_then(|Guard| Guard.get(Uri).cloned())
46	}
47
48	/// Store or overwrite the decoration for a URI.
49	pub fn SetDecoration(&self, Uri:&str, Decoration:Value) {
50		if let Ok(mut Guard) = self.Entries.lock() {
51			Guard.insert(Uri.to_owned(), Decoration);
52
53			dev_log!("decorations", "[DecorationsState] Decoration set for: {}", Uri);
54		}
55	}
56
57	/// Remove the decoration for a URI.
58	pub fn ClearDecoration(&self, Uri:&str) {
59		if let Ok(mut Guard) = self.Entries.lock() {
60			Guard.remove(Uri);
61
62			dev_log!("decorations", "[DecorationsState] Decoration cleared for: {}", Uri);
63		}
64	}
65
66	/// Return all stored decorations as a cloned map.
67	pub fn GetAll(&self) -> HashMap<String, Value> {
68		self.Entries.lock().ok().map(|Guard| Guard.clone()).unwrap_or_default()
69	}
70}