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	/// Tooltip text displayed on hover.
16	pub Tooltip:Option<String>,
17	/// Color hint for the item label (theme color ID, e.g.
18	/// "gitDecoration.modifiedResourceForeground").
19	pub Color:Option<String>,
20	/// Whether to propagate the badge to parent folders.
21	pub Propagate:Option<bool>,
22}
23
24/// Stores per-URI file decorations (git badges, error squiggles, custom
25/// badges).
26#[derive(Clone)]
27pub struct DecorationsState {
28	Entries:Arc<StandardMutex<HashMap<String, Value>>>,
29}
30
31impl Default for DecorationsState {
32	fn default() -> Self {
33		dev_log!("decorations", "[DecorationsState] Initializing default decorations state...");
34		Self { Entries:Arc::new(StandardMutex::new(HashMap::new())) }
35	}
36}
37
38impl DecorationsState {
39	/// Return the JSON decoration value for a URI, or `None` when not set.
40	pub fn GetDecoration(&self, Uri:&str) -> Option<Value> {
41		self.Entries.lock().ok().and_then(|Guard| Guard.get(Uri).cloned())
42	}
43
44	/// Store or overwrite the decoration for a URI.
45	pub fn SetDecoration(&self, Uri:&str, Decoration:Value) {
46		if let Ok(mut Guard) = self.Entries.lock() {
47			Guard.insert(Uri.to_owned(), Decoration);
48			dev_log!("decorations", "[DecorationsState] Decoration set for: {}", Uri);
49		}
50	}
51
52	/// Remove the decoration for a URI.
53	pub fn ClearDecoration(&self, Uri:&str) {
54		if let Ok(mut Guard) = self.Entries.lock() {
55			Guard.remove(Uri);
56			dev_log!("decorations", "[DecorationsState] Decoration cleared for: {}", Uri);
57		}
58	}
59
60	/// Return all stored decorations as a cloned map.
61	pub fn GetAll(&self) -> HashMap<String, Value> {
62		self.Entries.lock().ok().map(|Guard| Guard.clone()).unwrap_or_default()
63	}
64}