Parameterize theme2::init to allow loading just the base theme (#3345)
This PR adds a parameter to the `theme2::init` method to indicate what the theme-loading behavior should be. This allows us to indicate when we want to load all of the additional built-in user themes (like in the Zed binary and in the storybook), and when we don't want to load the user themes (like in tests). We're using an enum over just a `bool` here for clarity at the call site. Release Notes: - N/A
This commit is contained in:
@@ -100,6 +100,11 @@ impl ThemeRegistry {
|
||||
.ok_or_else(|| anyhow!("theme not found: {}", name))
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub fn load_user_themes(&mut self) {
|
||||
#[cfg(not(feature = "importing-themes"))]
|
||||
self.insert_user_theme_familes(crate::all_user_themes());
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ThemeRegistry {
|
||||
@@ -110,9 +115,6 @@ impl Default for ThemeRegistry {
|
||||
|
||||
this.insert_theme_families([one_family()]);
|
||||
|
||||
#[cfg(not(feature = "importing-themes"))]
|
||||
this.insert_user_theme_familes(crate::all_user_themes());
|
||||
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ impl settings::Settings for ThemeSettings {
|
||||
user_values: &[&Self::FileContent],
|
||||
cx: &mut AppContext,
|
||||
) -> Result<Self> {
|
||||
let themes = cx.default_global::<Arc<ThemeRegistry>>();
|
||||
let themes = cx.default_global::<ThemeRegistry>();
|
||||
|
||||
let mut this = Self {
|
||||
ui_font_size: defaults.ui_font_size.unwrap_or(16.).into(),
|
||||
|
||||
@@ -31,8 +31,25 @@ pub enum Appearance {
|
||||
Dark,
|
||||
}
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum LoadThemes {
|
||||
/// Only load the base theme.
|
||||
///
|
||||
/// No user themes will be loaded.
|
||||
JustBase,
|
||||
|
||||
/// Load all of the built-in themes.
|
||||
All,
|
||||
}
|
||||
|
||||
pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
|
||||
cx.set_global(ThemeRegistry::default());
|
||||
|
||||
match themes_to_load {
|
||||
LoadThemes::JustBase => (),
|
||||
LoadThemes::All => cx.global_mut::<ThemeRegistry>().load_user_themes(),
|
||||
}
|
||||
|
||||
ThemeSettings::register(cx);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user