Finished internal themes

Mikayla Maki created

Change summary

.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(-)

Detailed changes

.gitignore 🔗

@@ -7,3 +7,4 @@
 /crates/collab/static/styles.css
 /vendor/bin
 /assets/themes/*.json
+/assets/themes/internal/*.json

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!(),

crates/theme/src/theme_registry.rs 🔗

@@ -10,20 +10,28 @@ pub struct ThemeRegistry {
     themes: Mutex<HashMap<String, Arc<Theme>>>,
     theme_data: Mutex<HashMap<String, Arc<Value>>>,
     font_cache: Arc<FontCache>,
+    internal: bool,
 }
 
 impl ThemeRegistry {
-    pub fn new(source: impl AssetSource, font_cache: Arc<FontCache>) -> Arc<Self> {
+    pub fn new(source: impl AssetSource, font_cache: Arc<FontCache>, internal: bool) -> Arc<Self> {
         Arc::new(Self {
             assets: Box::new(source),
             themes: Default::default(),
             theme_data: Default::default(),
             font_cache,
+            internal,
         })
     }
 
     pub fn list(&self) -> impl Iterator<Item = ThemeMeta> + '_ {
-        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());

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,

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());

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,
             )

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;