Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

theme: Implement icon theme reloading (#24449)

Finn Evers144487bf1ac3
diff --git a/crates/extension/src/extension_host_proxy.rs b/crates/extension/src/extension_host_proxy.rs
index 25d4a4e539c..a692795e87f 100644
--- a/crates/extension/src/extension_host_proxy.rs
+++ b/crates/extension/src/extension_host_proxy.rs
@@ -118,6 +118,8 @@ pub trait ExtensionThemeProxy: Send + Sync + 'static {
icons_root_dir: PathBuf,
fs: Arc<dyn Fs>,
) -> Task<Result<()>>;
+
+ fn reload_current_icon_theme(&self, cx: &mut App);
}
impl ExtensionThemeProxy for ExtensionHostProxy {
@@ -185,6 +187,14 @@ impl ExtensionThemeProxy for ExtensionHostProxy {
proxy.load_icon_theme(icon_theme_path, icons_root_dir, fs)
}
+
+ fn reload_current_icon_theme(&self, cx: &mut App) {
+ let Some(proxy) = self.theme_proxy.read().clone() else {
+ return;
+ };
+
+ proxy.reload_current_icon_theme(cx)
+ }
}
pub trait ExtensionGrammarProxy: Send + Sync + 'static {
diff --git a/crates/extension_host/src/extension_host.rs b/crates/extension_host/src/extension_host.rs
index 69c26d44a46..e1e866705ac 100644
--- a/crates/extension_host/src/extension_host.rs
+++ b/crates/extension_host/src/extension_host.rs
@@ -1292,6 +1292,7 @@ impl ExtensionStore {
this.wasm_extensions.extend(wasm_extensions);
this.proxy.reload_current_theme(cx);
+ this.proxy.reload_current_icon_theme(cx);
})
.ok();
})
diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs
index 2032b989839..f44e45d549d 100644
--- a/crates/theme/src/settings.rs
+++ b/crates/theme/src/settings.rs
@@ -164,6 +164,30 @@ impl ThemeSettings {
}
}
}
+
+ /// Reloads the current icon theme.
+ ///
+ /// Reads the [`ThemeSettings`] to know which icon theme should be loaded.
+ pub fn reload_current_icon_theme(cx: &mut App) {
+ let mut theme_settings = ThemeSettings::get_global(cx).clone();
+
+ let active_theme = theme_settings.active_icon_theme.clone();
+ let mut icon_theme_name = active_theme.name.as_ref();
+
+ // If the selected theme doesn't exist, fall back to the default theme.
+ let theme_registry = ThemeRegistry::global(cx);
+ if theme_registry
+ .get_icon_theme(icon_theme_name)
+ .ok()
+ .is_none()
+ {
+ icon_theme_name = DEFAULT_ICON_THEME_NAME;
+ };
+
+ if let Some(_theme) = theme_settings.switch_icon_theme(icon_theme_name, cx) {
+ ThemeSettings::override_global(theme_settings, cx);
+ }
+ }
}
/// The appearance of the system.
@@ -487,6 +511,24 @@ impl ThemeSettings {
self.active_theme = Arc::new(base_theme);
}
}
+
+ /// Switches to the icon theme with the given name, if it exists.
+ ///
+ /// Returns a `Some` containing the new icon theme if it was successful.
+ /// Returns `None` otherwise.
+ pub fn switch_icon_theme(&mut self, icon_theme: &str, cx: &mut App) -> Option<Arc<IconTheme>> {
+ let themes = ThemeRegistry::default_global(cx);
+
+ let mut new_icon_theme = None;
+
+ if let Some(icon_theme) = themes.get_icon_theme(icon_theme).log_err() {
+ self.active_icon_theme = icon_theme.clone();
+ new_icon_theme = Some(icon_theme);
+ cx.refresh_windows();
+ }
+
+ new_icon_theme
+ }
}
// TODO: Make private, change usages to use `get_ui_font_size` instead.
diff --git a/crates/theme_extension/src/theme_extension.rs b/crates/theme_extension/src/theme_extension.rs
index bce271840c9..83903da6c69 100644
--- a/crates/theme_extension/src/theme_extension.rs
+++ b/crates/theme_extension/src/theme_extension.rs
@@ -77,4 +77,8 @@ impl ExtensionThemeProxy for ThemeRegistryProxy {
.await
})
}
+
+ fn reload_current_icon_theme(&self, cx: &mut App) {
+ ThemeSettings::reload_current_icon_theme(cx)
+ }
}