From d88132034587a36704ef81f748c678389ac24ac7 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 8 Sep 2022 15:06:08 -0700 Subject: [PATCH] Finished internal themes --- .gitignore | 1 + assets/themes/.gitkeep | 0 crates/collab/src/integration_tests.rs | 2 +- crates/theme/src/theme_registry.rs | 13 +++++++++++-- crates/workspace/src/workspace.rs | 2 +- crates/zed/src/main.rs | 2 +- crates/zed/src/settings_file.rs | 2 +- crates/zed/src/zed.rs | 2 +- 8 files changed, 17 insertions(+), 7 deletions(-) delete mode 100644 assets/themes/.gitkeep diff --git a/.gitignore b/.gitignore index fcebdc84a2..1b39c0720c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /crates/collab/static/styles.css /vendor/bin /assets/themes/*.json +/assets/themes/internal/*.json \ No newline at end of file diff --git a/assets/themes/.gitkeep b/assets/themes/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/crates/collab/src/integration_tests.rs b/crates/collab/src/integration_tests.rs index 905aa328f2..c037d9719a 100644 --- a/crates/collab/src/integration_tests.rs +++ b/crates/collab/src/integration_tests.rs @@ -5220,7 +5220,7 @@ impl TestServer { user_store: user_store.clone(), project_store: project_store.clone(), languages: Arc::new(LanguageRegistry::new(Task::ready(()))), - themes: ThemeRegistry::new((), cx.font_cache()), + themes: ThemeRegistry::new((), cx.font_cache(), false), fs: fs.clone(), build_window_options: Default::default, initialize_workspace: |_, _, _| unimplemented!(), diff --git a/crates/theme/src/theme_registry.rs b/crates/theme/src/theme_registry.rs index af4b02a86a..98bd4e301e 100644 --- a/crates/theme/src/theme_registry.rs +++ b/crates/theme/src/theme_registry.rs @@ -10,20 +10,28 @@ pub struct ThemeRegistry { themes: Mutex>>, theme_data: Mutex>>, font_cache: Arc, + internal: bool, } impl ThemeRegistry { - pub fn new(source: impl AssetSource, font_cache: Arc) -> Arc { + pub fn new(source: impl AssetSource, font_cache: Arc, internal: bool) -> Arc { Arc::new(Self { assets: Box::new(source), themes: Default::default(), theme_data: Default::default(), font_cache, + internal, }) } pub fn list(&self) -> impl Iterator + '_ { - self.assets.list("themes/").into_iter().filter_map(|path| { + let mut dirs = self.assets.list("themes/"); + + if self.internal { + dirs.extend(self.assets.list("themes/internal/")) + }; + + dirs.into_iter().filter_map(|path| { let filename = path.strip_prefix("themes/")?; let theme_name = filename.strip_suffix(".json")?; self.get(theme_name).ok().map(|theme| theme.meta.clone()) @@ -50,6 +58,7 @@ impl ThemeRegistry { serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_slice(&theme_json)) })?; + // Reset name to be the file path, so that we can use it to access the stored themes theme.meta.name = name.into(); let theme = Arc::new(theme); self.themes.lock().insert(name.to_string(), theme.clone()); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 9f6c7f1612..1d4bed7a94 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -860,7 +860,7 @@ impl AppState { let client = Client::new(http_client.clone()); let project_store = cx.add_model(|_| ProjectStore::new(project::Db::open_fake())); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx)); - let themes = ThemeRegistry::new((), cx.font_cache().clone()); + let themes = ThemeRegistry::new((), cx.font_cache().clone(), false); Arc::new(Self { client, themes, diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 1db6656fb3..0edebeed7e 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -85,7 +85,7 @@ fn main() { } }); - let themes = ThemeRegistry::new(Assets, app.font_cache()); + let themes = ThemeRegistry::new(Assets, app.font_cache(), internal); let default_settings = Settings::defaults(Assets, &app.font_cache(), &themes); let config_files = load_config_files(&app, fs.clone()); diff --git a/crates/zed/src/settings_file.rs b/crates/zed/src/settings_file.rs index 6d28efbcbc..77ac6f8b64 100644 --- a/crates/zed/src/settings_file.rs +++ b/crates/zed/src/settings_file.rs @@ -153,7 +153,7 @@ mod tests { watch_settings_file( default_settings.clone(), source, - ThemeRegistry::new((), font_cache), + ThemeRegistry::new((), font_cache, false), false, cx, ) diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index cadca586da..e3fd2ee8d1 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -1664,7 +1664,7 @@ mod tests { .into(), ]) .unwrap(); - let themes = ThemeRegistry::new(Assets, cx.font_cache().clone()); + let themes = ThemeRegistry::new(Assets, cx.font_cache().clone(), false); let settings = Settings::defaults(Assets, cx.font_cache(), &themes); let mut has_default_theme = false;