Rename ThemeMode to ThemeAppearanceMode (#42279)

There was a TODO in `crates/settings/src/settings_content/theme.rs` to
make this rename.

This PR is just splitting off this change from
https://github.com/zed-industries/zed/pull/40035 to make reviewing that
one a bit easier since that PR is a bit more involved than expected.

Release Notes:

- N/A

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
This commit is contained in:
Connor Tsui
2025-11-10 14:26:01 -07:00
committed by GitHub
parent efcd7f7d10
commit a44fc9a1de
5 changed files with 53 additions and 45 deletions
+23 -14
View File
@@ -5,7 +5,7 @@ use fs::Fs;
use gpui::{Action, App, IntoElement};
use settings::{BaseKeymap, Settings, update_settings_file};
use theme::{
Appearance, SystemAppearance, ThemeMode, ThemeName, ThemeRegistry, ThemeSelection,
Appearance, SystemAppearance, ThemeAppearanceMode, ThemeName, ThemeRegistry, ThemeSelection,
ThemeSettings,
};
use ui::{
@@ -44,8 +44,8 @@ fn render_theme_section(tab_index: &mut isize, cx: &mut App) -> impl IntoElement
let theme_mode = theme_selection
.mode()
.unwrap_or_else(|| match *system_appearance {
Appearance::Light => ThemeMode::Light,
Appearance::Dark => ThemeMode::Dark,
Appearance::Light => ThemeAppearanceMode::Light,
Appearance::Dark => ThemeAppearanceMode::Dark,
});
return v_flex()
@@ -54,7 +54,12 @@ fn render_theme_section(tab_index: &mut isize, cx: &mut App) -> impl IntoElement
h_flex().justify_between().child(Label::new("Theme")).child(
ToggleButtonGroup::single_row(
"theme-selector-onboarding-dark-light",
[ThemeMode::Light, ThemeMode::Dark, ThemeMode::System].map(|mode| {
[
ThemeAppearanceMode::Light,
ThemeAppearanceMode::Dark,
ThemeAppearanceMode::System,
]
.map(|mode| {
const MODE_NAMES: [SharedString; 3] = [
SharedString::new_static("Light"),
SharedString::new_static("Dark"),
@@ -100,13 +105,13 @@ fn render_theme_section(tab_index: &mut isize, cx: &mut App) -> impl IntoElement
let theme_mode = theme_selection
.mode()
.unwrap_or_else(|| match *system_appearance {
Appearance::Light => ThemeMode::Light,
Appearance::Dark => ThemeMode::Dark,
Appearance::Light => ThemeAppearanceMode::Light,
Appearance::Dark => ThemeAppearanceMode::Dark,
});
let appearance = match theme_mode {
ThemeMode::Light => Appearance::Light,
ThemeMode::Dark => Appearance::Dark,
ThemeMode::System => *system_appearance,
ThemeAppearanceMode::Light => Appearance::Light,
ThemeAppearanceMode::Dark => Appearance::Dark,
ThemeAppearanceMode::System => *system_appearance,
};
let current_theme_name: SharedString = theme_selection.name(appearance).0.into();
@@ -164,7 +169,7 @@ fn render_theme_section(tab_index: &mut isize, cx: &mut App) -> impl IntoElement
}
})
.map(|this| {
if theme_mode == ThemeMode::System {
if theme_mode == ThemeAppearanceMode::System {
let (light, dark) = (
theme_registry.get(LIGHT_THEMES[index]).unwrap(),
theme_registry.get(DARK_THEMES[index]).unwrap(),
@@ -189,23 +194,27 @@ fn render_theme_section(tab_index: &mut isize, cx: &mut App) -> impl IntoElement
})
}
fn write_mode_change(mode: ThemeMode, cx: &mut App) {
fn write_mode_change(mode: ThemeAppearanceMode, cx: &mut App) {
let fs = <dyn Fs>::global(cx);
update_settings_file(fs, cx, move |settings, _cx| {
theme::set_mode(settings, mode);
});
}
fn write_theme_change(theme: impl Into<Arc<str>>, theme_mode: ThemeMode, cx: &mut App) {
fn write_theme_change(
theme: impl Into<Arc<str>>,
theme_mode: ThemeAppearanceMode,
cx: &mut App,
) {
let fs = <dyn Fs>::global(cx);
let theme = theme.into();
update_settings_file(fs, cx, move |settings, cx| {
if theme_mode == ThemeMode::System {
if theme_mode == ThemeAppearanceMode::System {
let (light_theme, dark_theme) =
get_theme_family_themes(&theme).unwrap_or((theme.as_ref(), theme.as_ref()));
settings.theme.theme = Some(settings::ThemeSelection::Dynamic {
mode: ThemeMode::System,
mode: ThemeAppearanceMode::System,
light: ThemeName(light_theme.into()),
dark: ThemeName(dark_theme.into()),
});
@@ -157,7 +157,7 @@ pub enum ThemeSelection {
Dynamic {
/// The mode used to determine which theme to use.
#[serde(default)]
mode: ThemeMode,
mode: ThemeAppearanceMode,
/// The theme to use for light mode.
light: ThemeName,
/// The theme to use for dark mode.
@@ -186,7 +186,7 @@ pub enum IconThemeSelection {
Dynamic {
/// The mode used to determine which theme to use.
#[serde(default)]
mode: ThemeMode,
mode: ThemeAppearanceMode,
/// The icon theme to use for light mode.
light: IconThemeName,
/// The icon theme to use for dark mode.
@@ -194,7 +194,6 @@ pub enum IconThemeSelection {
},
}
// TODO: Rename ThemeMode -> ThemeAppearanceMode
/// The mode use to select a theme.
///
/// `Light` and `Dark` will select their respective themes.
@@ -215,7 +214,7 @@ pub enum IconThemeSelection {
strum::VariantNames,
)]
#[serde(rename_all = "snake_case")]
pub enum ThemeMode {
pub enum ThemeAppearanceMode {
/// Use the specified `light` theme.
Light,
+8 -8
View File
@@ -300,9 +300,9 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
settings::ThemeSelection::Static(_) => return,
settings::ThemeSelection::Dynamic { mode, light, dark } => {
match mode {
theme::ThemeMode::Light => light.clone(),
theme::ThemeMode::Dark => dark.clone(),
theme::ThemeMode::System => dark.clone(), // no cx, can't determine correct choice
theme::ThemeAppearanceMode::Light => light.clone(),
theme::ThemeAppearanceMode::Dark => dark.clone(),
theme::ThemeAppearanceMode::System => dark.clone(), // no cx, can't determine correct choice
}
},
};
@@ -315,7 +315,7 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
};
settings::ThemeSelection::Dynamic {
mode: settings::ThemeMode::System,
mode: settings::ThemeAppearanceMode::System,
light: static_name.clone(),
dark: static_name,
}
@@ -470,9 +470,9 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
settings::IconThemeSelection::Static(_) => return,
settings::IconThemeSelection::Dynamic { mode, light, dark } => {
match mode {
theme::ThemeMode::Light => light.clone(),
theme::ThemeMode::Dark => dark.clone(),
theme::ThemeMode::System => dark.clone(), // no cx, can't determine correct choice
theme::ThemeAppearanceMode::Light => light.clone(),
theme::ThemeAppearanceMode::Dark => dark.clone(),
theme::ThemeAppearanceMode::System => dark.clone(), // no cx, can't determine correct choice
}
},
};
@@ -485,7 +485,7 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
};
settings::IconThemeSelection::Dynamic {
mode: settings::ThemeMode::System,
mode: settings::ThemeAppearanceMode::System,
light: static_name.clone(),
dark: static_name,
}
+1 -1
View File
@@ -486,7 +486,7 @@ fn init_renderers(cx: &mut App) {
.add_basic_renderer::<settings::PaneSplitDirectionVertical>(render_dropdown)
.add_basic_renderer::<settings::DocumentColorsRenderMode>(render_dropdown)
.add_basic_renderer::<settings::ThemeSelectionDiscriminants>(render_dropdown)
.add_basic_renderer::<settings::ThemeMode>(render_dropdown)
.add_basic_renderer::<settings::ThemeAppearanceMode>(render_dropdown)
.add_basic_renderer::<settings::ThemeName>(render_theme_picker)
.add_basic_renderer::<settings::IconThemeSelectionDiscriminants>(render_dropdown)
.add_basic_renderer::<settings::IconThemeName>(render_icon_theme_picker)
+18 -18
View File
@@ -11,7 +11,7 @@ use gpui::{
use refineable::Refineable;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
pub use settings::{FontFamilyName, IconThemeName, ThemeMode, ThemeName};
pub use settings::{FontFamilyName, IconThemeName, ThemeAppearanceMode, ThemeName};
use settings::{RegisterSetting, Settings, SettingsContent};
use std::sync::Arc;
@@ -208,7 +208,7 @@ pub enum ThemeSelection {
Dynamic {
/// The mode used to determine which theme to use.
#[serde(default)]
mode: ThemeMode,
mode: ThemeAppearanceMode,
/// The theme to use for light mode.
light: ThemeName,
/// The theme to use for dark mode.
@@ -233,9 +233,9 @@ impl ThemeSelection {
match self {
Self::Static(theme) => theme.clone(),
Self::Dynamic { mode, light, dark } => match mode {
ThemeMode::Light => light.clone(),
ThemeMode::Dark => dark.clone(),
ThemeMode::System => match system_appearance {
ThemeAppearanceMode::Light => light.clone(),
ThemeAppearanceMode::Dark => dark.clone(),
ThemeAppearanceMode::System => match system_appearance {
Appearance::Light => light.clone(),
Appearance::Dark => dark.clone(),
},
@@ -244,7 +244,7 @@ impl ThemeSelection {
}
/// Returns the [ThemeMode] for the [ThemeSelection].
pub fn mode(&self) -> Option<ThemeMode> {
pub fn mode(&self) -> Option<ThemeAppearanceMode> {
match self {
ThemeSelection::Static(_) => None,
ThemeSelection::Dynamic { mode, .. } => Some(*mode),
@@ -260,7 +260,7 @@ pub enum IconThemeSelection {
/// A dynamic icon theme selection, which can change based on the [`ThemeMode`].
Dynamic {
/// The mode used to determine which theme to use.
mode: ThemeMode,
mode: ThemeAppearanceMode,
/// The icon theme to use for light mode.
light: IconThemeName,
/// The icon theme to use for dark mode.
@@ -285,9 +285,9 @@ impl IconThemeSelection {
match self {
Self::Static(theme) => theme.clone(),
Self::Dynamic { mode, light, dark } => match mode {
ThemeMode::Light => light.clone(),
ThemeMode::Dark => dark.clone(),
ThemeMode::System => match system_appearance {
ThemeAppearanceMode::Light => light.clone(),
ThemeAppearanceMode::Dark => dark.clone(),
ThemeAppearanceMode::System => match system_appearance {
Appearance::Light => light.clone(),
Appearance::Dark => dark.clone(),
},
@@ -296,7 +296,7 @@ impl IconThemeSelection {
}
/// Returns the [`ThemeMode`] for the [`IconThemeSelection`].
pub fn mode(&self) -> Option<ThemeMode> {
pub fn mode(&self) -> Option<ThemeAppearanceMode> {
match self {
IconThemeSelection::Static(_) => None,
IconThemeSelection::Dynamic { mode, .. } => Some(*mode),
@@ -315,9 +315,9 @@ pub fn set_theme(
let theme_to_update = match selection {
settings::ThemeSelection::Static(theme) => theme,
settings::ThemeSelection::Dynamic { mode, light, dark } => match mode {
ThemeMode::Light => light,
ThemeMode::Dark => dark,
ThemeMode::System => match appearance {
ThemeAppearanceMode::Light => light,
ThemeAppearanceMode::Dark => dark,
ThemeAppearanceMode::System => match appearance {
Appearance::Light => light,
Appearance::Dark => dark,
},
@@ -342,9 +342,9 @@ pub fn set_icon_theme(
let icon_theme_to_update = match selection {
settings::IconThemeSelection::Static(theme) => theme,
settings::IconThemeSelection::Dynamic { mode, light, dark } => match mode {
ThemeMode::Light => light,
ThemeMode::Dark => dark,
ThemeMode::System => match appearance {
ThemeAppearanceMode::Light => light,
ThemeAppearanceMode::Dark => dark,
ThemeAppearanceMode::System => match appearance {
Appearance::Light => light,
Appearance::Dark => dark,
},
@@ -358,7 +358,7 @@ pub fn set_icon_theme(
}
/// Sets the mode for the theme.
pub fn set_mode(content: &mut SettingsContent, mode: ThemeMode) {
pub fn set_mode(content: &mut SettingsContent, mode: ThemeAppearanceMode) {
let theme = content.theme.as_mut();
if let Some(selection) = theme.theme.as_mut() {