Add theme mode toggle action

Fixes #35552
This commit is contained in:
Eduardo Alba 2025-08-06 00:14:45 -04:00
parent 6b77654f66
commit 903935fd88
3 changed files with 46 additions and 2 deletions

View file

@ -7,9 +7,9 @@ use gpui::{
Window, actions,
};
use picker::{Picker, PickerDelegate};
use settings::{SettingsStore, update_settings_file};
use settings::{Settings as _, SettingsStore, update_settings_file};
use std::sync::Arc;
use theme::{Appearance, Theme, ThemeMeta, ThemeRegistry, ThemeSettings};
use theme::{Appearance, Theme, ThemeMeta, ThemeMode, ThemeRegistry, ThemeSelection, ThemeSettings};
use ui::{ListItem, ListItemSpacing, prelude::*, v_flex};
use util::ResultExt;
use workspace::{ModalView, Workspace, ui::HighlightedLabel, with_active_or_new_workspace};
@ -38,6 +38,11 @@ pub fn init(cx: &mut App) {
toggle_icon_theme_selector(workspace, &action, window, cx);
});
});
cx.on_action(|_: &zed_actions::theme_selector::ToggleMode, cx| {
with_active_or_new_workspace(cx, |workspace, window, cx| {
toggle_theme_mode(workspace, window, cx);
});
});
}
fn toggle_theme_selector(
@ -76,6 +81,35 @@ fn toggle_icon_theme_selector(
});
}
fn toggle_theme_mode(
workspace: &mut Workspace,
_window: &mut Window,
cx: &mut Context<Workspace>,
) {
let current_settings = ThemeSettings::get_global(cx);
let current_selection = current_settings.theme_selection.as_ref();
let new_mode = match current_selection {
Some(ThemeSelection::Dynamic { mode, .. }) => {
match mode {
ThemeMode::Light => ThemeMode::Dark,
ThemeMode::Dark => ThemeMode::System,
ThemeMode::System => ThemeMode::Light,
}
}
Some(ThemeSelection::Static(_)) => ThemeMode::Light,
None => ThemeMode::Light
};
let fs = workspace.app_state().fs.clone();
update_settings_file::<ThemeSettings>(fs, cx, move |settings, _| {
settings.set_mode(new_mode);
});
ThemeSettings::reload_current_theme(cx);
}
impl ModalView for ThemeSelector {}
struct ThemeSelector {

View file

@ -32,6 +32,10 @@ pub fn app_menus() -> Vec<Menu> {
"Select Theme...",
zed_actions::theme_selector::Toggle::default(),
),
MenuItem::action(
"Toggle Theme Mode",
zed_actions::theme_selector::ToggleMode,
),
],
}),
MenuItem::separator(),

View file

@ -243,6 +243,12 @@ pub mod theme_selector {
/// A list of theme names to filter the theme selector down to.
pub themes_filter: Option<Vec<String>>,
}
/// Toggles between light, dark, and system theme modes.
#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
#[action(namespace = theme_selector)]
#[serde(deny_unknown_fields)]
pub struct ToggleMode;
}
pub mod icon_theme_selector {