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:
@@ -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()),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user