diff --git a/crates/collab2/src/tests/test_server.rs b/crates/collab2/src/tests/test_server.rs index de6f3e92a1..090a32d4ca 100644 --- a/crates/collab2/src/tests/test_server.rs +++ b/crates/collab2/src/tests/test_server.rs @@ -224,7 +224,7 @@ impl TestServer { }); cx.update(|cx| { - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); Project::init(&client, cx); client::init(&client, cx); language::init(cx); diff --git a/crates/command_palette2/src/command_palette.rs b/crates/command_palette2/src/command_palette.rs index 8138f025d3..31eb608ef5 100644 --- a/crates/command_palette2/src/command_palette.rs +++ b/crates/command_palette2/src/command_palette.rs @@ -456,7 +456,7 @@ mod tests { fn init_test(cx: &mut TestAppContext) -> Arc { cx.update(|cx| { let app_state = AppState::test(cx); - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); language::init(cx); editor::init(cx); workspace::init(app_state.clone(), cx); diff --git a/crates/editor2/src/display_map/inlay_map.rs b/crates/editor2/src/display_map/inlay_map.rs index a6bc6343f4..84fad96a48 100644 --- a/crates/editor2/src/display_map/inlay_map.rs +++ b/crates/editor2/src/display_map/inlay_map.rs @@ -1891,6 +1891,6 @@ mod tests { fn init_test(cx: &mut AppContext) { let store = SettingsStore::test(cx); cx.set_global(store); - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); } } diff --git a/crates/editor2/src/editor_tests.rs b/crates/editor2/src/editor_tests.rs index 63bc6179c2..bd69e7acdf 100644 --- a/crates/editor2/src/editor_tests.rs +++ b/crates/editor2/src/editor_tests.rs @@ -8277,7 +8277,7 @@ pub(crate) fn init_test(cx: &mut TestAppContext, f: fn(&mut AllLanguageSettingsC cx.update(|cx| { let store = SettingsStore::test(cx); cx.set_global(store); - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); client::init_settings(cx); language::init(cx); Project::init_settings(cx); diff --git a/crates/editor2/src/inlay_hint_cache.rs b/crates/editor2/src/inlay_hint_cache.rs index af9febf376..eba49ccbf7 100644 --- a/crates/editor2/src/inlay_hint_cache.rs +++ b/crates/editor2/src/inlay_hint_cache.rs @@ -3179,7 +3179,7 @@ all hints should be invalidated and requeried for all of its visible excerpts" cx.update(|cx| { let settings_store = SettingsStore::test(cx); cx.set_global(settings_store); - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); client::init_settings(cx); language::init(cx); Project::init_settings(cx); diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rs index 236bc15244..b2850761a9 100644 --- a/crates/file_finder2/src/file_finder.rs +++ b/crates/file_finder2/src/file_finder.rs @@ -1763,7 +1763,7 @@ mod tests { fn init_test(cx: &mut TestAppContext) -> Arc { cx.update(|cx| { let state = AppState::test(cx); - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); language::init(cx); super::init(cx); editor::init(cx); diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index f33633afb9..87edabab52 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -2785,7 +2785,7 @@ mod tests { let settings_store = SettingsStore::test(cx); cx.set_global(settings_store); init_settings(cx); - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); language::init(cx); editor::init_settings(cx); crate::init((), cx); @@ -2798,7 +2798,7 @@ mod tests { fn init_test_with_editor(cx: &mut TestAppContext) { cx.update(|cx| { let app_state = AppState::test(cx); - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); init_settings(cx); language::init(cx); editor::init(cx); diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index c4c1d75eac..20adc44c1a 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -60,7 +60,7 @@ fn main() { .unwrap(); cx.set_global(store); - theme2::init(cx); + theme2::init(theme2::LoadThemes::All, cx); let selector = story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace)); diff --git a/crates/terminal_view2/src/terminal_view.rs b/crates/terminal_view2/src/terminal_view.rs index 14391ca2b2..ad33716384 100644 --- a/crates/terminal_view2/src/terminal_view.rs +++ b/crates/terminal_view2/src/terminal_view.rs @@ -1126,7 +1126,7 @@ mod tests { pub async fn init_test(cx: &mut TestAppContext) -> (Model, View) { let params = cx.update(AppState::test); cx.update(|cx| { - theme::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); Project::init_settings(cx); language::init(cx); }); diff --git a/crates/theme2/src/registry.rs b/crates/theme2/src/registry.rs index 19af0ede51..919dd1b109 100644 --- a/crates/theme2/src/registry.rs +++ b/crates/theme2/src/registry.rs @@ -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 } } diff --git a/crates/theme2/src/settings.rs b/crates/theme2/src/settings.rs index 5e3329ffa1..071199d3d6 100644 --- a/crates/theme2/src/settings.rs +++ b/crates/theme2/src/settings.rs @@ -117,7 +117,7 @@ impl settings::Settings for ThemeSettings { user_values: &[&Self::FileContent], cx: &mut AppContext, ) -> Result { - let themes = cx.default_global::>(); + let themes = cx.default_global::(); let mut this = Self { ui_font_size: defaults.ui_font_size.unwrap_or(16.).into(), diff --git a/crates/theme2/src/theme2.rs b/crates/theme2/src/theme2.rs index b6790b5a6f..05e41ba368 100644 --- a/crates/theme2/src/theme2.rs +++ b/crates/theme2/src/theme2.rs @@ -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::().load_user_themes(), + } + ThemeSettings::register(cx); } diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index f28675661d..a146ad1822 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -355,7 +355,7 @@ impl AppState { let user_store = cx.build_model(|cx| UserStore::new(client.clone(), http_client, cx)); let workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); - theme2::init(cx); + theme2::init(theme2::LoadThemes::JustBase, cx); client2::init(&client, cx); crate::init_settings(cx); diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index ef65d00fc3..700660a9b7 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -140,7 +140,7 @@ fn main() { cx.set_global(client.clone()); - theme::init(cx); + theme::init(theme::LoadThemes::All, cx); project::Project::init(&client, cx); client::init(&client, cx); command_palette::init(cx);