Merge e9c2796034
into bd4e943597
This commit is contained in:
commit
5c354ef4b7
3 changed files with 48 additions and 2 deletions
|
@ -7,9 +7,11 @@ 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 +40,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 +83,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::Light,
|
||||
ThemeMode::System => {
|
||||
if cx.theme().appearance().is_light() {
|
||||
ThemeMode::Dark
|
||||
} else {
|
||||
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 {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -246,6 +246,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 and dark 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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue