Revert "Remove cx from ThemeSettings (#38836)" (#39691)

This reverts commit a2a7bd139a.

This caused themes to not load correctly on startup, you needed to edit
your settings.

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin
2025-10-07 15:45:20 +00:00
committed by GitHub
parent e765818487
commit 41cf114d8a
60 changed files with 423 additions and 360 deletions
@@ -7,10 +7,7 @@ use gpui::{
use picker::{Picker, PickerDelegate};
use settings::{Settings as _, SettingsStore, update_settings_file};
use std::sync::Arc;
use theme::{
Appearance, IconThemeName, IconThemeSelection, SystemAppearance, ThemeMeta, ThemeRegistry,
ThemeSettings,
};
use theme::{Appearance, IconTheme, ThemeMeta, ThemeRegistry, ThemeSettings};
use ui::{ListItem, ListItemSpacing, prelude::*, v_flex};
use util::ResultExt;
use workspace::{ModalView, ui::HighlightedLabel};
@@ -54,9 +51,9 @@ pub(crate) struct IconThemeSelectorDelegate {
fs: Arc<dyn Fs>,
themes: Vec<ThemeMeta>,
matches: Vec<StringMatch>,
original_theme: IconThemeName,
original_theme: Arc<IconTheme>,
selection_completed: bool,
selected_theme: Option<IconThemeName>,
selected_theme: Option<Arc<IconTheme>>,
selected_index: usize,
selector: WeakEntity<IconThemeSelector>,
}
@@ -69,9 +66,7 @@ impl IconThemeSelectorDelegate {
cx: &mut Context<IconThemeSelector>,
) -> Self {
let theme_settings = ThemeSettings::get_global(cx);
let original_theme = theme_settings
.icon_theme
.name(SystemAppearance::global(cx).0);
let original_theme = theme_settings.active_icon_theme.clone();
let registry = ThemeRegistry::global(cx);
let mut themes = registry
@@ -112,18 +107,29 @@ impl IconThemeSelectorDelegate {
selector,
};
this.select_if_matching(&original_theme.0);
this.select_if_matching(&original_theme.name);
this
}
fn show_selected_theme(
&mut self,
cx: &mut Context<Picker<IconThemeSelectorDelegate>>,
) -> Option<IconThemeName> {
let mat = self.matches.get(self.selected_index)?;
let name = IconThemeName(mat.string.clone().into());
Self::set_icon_theme(name.clone(), cx);
Some(name)
) -> Option<Arc<IconTheme>> {
if let Some(mat) = self.matches.get(self.selected_index) {
let registry = ThemeRegistry::global(cx);
match registry.get_icon_theme(&mat.string) {
Ok(theme) => {
Self::set_icon_theme(theme.clone(), cx);
Some(theme)
}
Err(err) => {
log::error!("error loading icon theme {}: {err}", mat.string);
None
}
}
} else {
None
}
}
fn select_if_matching(&mut self, theme_name: &str) {
@@ -134,11 +140,12 @@ impl IconThemeSelectorDelegate {
.unwrap_or(self.selected_index);
}
fn set_icon_theme(name: IconThemeName, cx: &mut App) {
SettingsStore::update_global(cx, |store, _| {
fn set_icon_theme(theme: Arc<IconTheme>, cx: &mut App) {
SettingsStore::update_global(cx, |store, cx| {
let mut theme_settings = store.get::<ThemeSettings>(None).clone();
theme_settings.icon_theme = IconThemeSelection::Static(name);
theme_settings.active_icon_theme = theme;
store.override_global(theme_settings);
cx.refresh_windows();
});
}
}
@@ -163,9 +170,7 @@ impl PickerDelegate for IconThemeSelectorDelegate {
self.selection_completed = true;
let theme_settings = ThemeSettings::get_global(cx);
let theme_name = theme_settings
.icon_theme
.name(SystemAppearance::global(cx).0);
let theme_name = theme_settings.active_icon_theme.name.clone();
telemetry::event!(
"Settings Changed",
@@ -176,7 +181,7 @@ impl PickerDelegate for IconThemeSelectorDelegate {
let appearance = Appearance::from(window.appearance());
update_settings_file(self.fs.clone(), cx, move |settings, _| {
theme::set_icon_theme(settings, theme_name, appearance);
theme::set_icon_theme(settings, theme_name.to_string(), appearance);
});
self.selector
@@ -263,7 +268,7 @@ impl PickerDelegate for IconThemeSelectorDelegate {
.matches
.iter()
.enumerate()
.find(|(_, mtch)| mtch.string.as_str() == selected.0.as_ref())
.find(|(_, mtch)| mtch.string == selected.name)
.map(|(ix, _)| ix)
.unwrap_or_default();
} else {
+4 -3
View File
@@ -203,11 +203,12 @@ impl ThemeSelectorDelegate {
}
fn set_theme(theme: Arc<Theme>, cx: &mut App) {
SettingsStore::update_global(cx, |store, _| {
SettingsStore::update_global(cx, |store, cx| {
let mut theme_settings = store.get::<ThemeSettings>(None).clone();
let name = theme.as_ref().name.clone().into();
theme_settings.theme = theme::ThemeSelection::Static(theme::ThemeName(name));
theme_settings.active_theme = theme;
theme_settings.apply_theme_overrides();
store.override_global(theme_settings);
cx.refresh_windows();
});
}
}