mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 21:32:40 +00:00
Finished internal themes
This commit is contained in:
parent
3171a0c312
commit
d881320345
8 changed files with 17 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@
|
||||||
/crates/collab/static/styles.css
|
/crates/collab/static/styles.css
|
||||||
/vendor/bin
|
/vendor/bin
|
||||||
/assets/themes/*.json
|
/assets/themes/*.json
|
||||||
|
/assets/themes/internal/*.json
|
|
@ -5220,7 +5220,7 @@ impl TestServer {
|
||||||
user_store: user_store.clone(),
|
user_store: user_store.clone(),
|
||||||
project_store: project_store.clone(),
|
project_store: project_store.clone(),
|
||||||
languages: Arc::new(LanguageRegistry::new(Task::ready(()))),
|
languages: Arc::new(LanguageRegistry::new(Task::ready(()))),
|
||||||
themes: ThemeRegistry::new((), cx.font_cache()),
|
themes: ThemeRegistry::new((), cx.font_cache(), false),
|
||||||
fs: fs.clone(),
|
fs: fs.clone(),
|
||||||
build_window_options: Default::default,
|
build_window_options: Default::default,
|
||||||
initialize_workspace: |_, _, _| unimplemented!(),
|
initialize_workspace: |_, _, _| unimplemented!(),
|
||||||
|
|
|
@ -10,20 +10,28 @@ pub struct ThemeRegistry {
|
||||||
themes: Mutex<HashMap<String, Arc<Theme>>>,
|
themes: Mutex<HashMap<String, Arc<Theme>>>,
|
||||||
theme_data: Mutex<HashMap<String, Arc<Value>>>,
|
theme_data: Mutex<HashMap<String, Arc<Value>>>,
|
||||||
font_cache: Arc<FontCache>,
|
font_cache: Arc<FontCache>,
|
||||||
|
internal: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThemeRegistry {
|
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 {
|
Arc::new(Self {
|
||||||
assets: Box::new(source),
|
assets: Box::new(source),
|
||||||
themes: Default::default(),
|
themes: Default::default(),
|
||||||
theme_data: Default::default(),
|
theme_data: Default::default(),
|
||||||
font_cache,
|
font_cache,
|
||||||
|
internal,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list(&self) -> impl Iterator<Item = ThemeMeta> + '_ {
|
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 filename = path.strip_prefix("themes/")?;
|
||||||
let theme_name = filename.strip_suffix(".json")?;
|
let theme_name = filename.strip_suffix(".json")?;
|
||||||
self.get(theme_name).ok().map(|theme| theme.meta.clone())
|
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))
|
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();
|
theme.meta.name = name.into();
|
||||||
let theme = Arc::new(theme);
|
let theme = Arc::new(theme);
|
||||||
self.themes.lock().insert(name.to_string(), theme.clone());
|
self.themes.lock().insert(name.to_string(), theme.clone());
|
||||||
|
|
|
@ -860,7 +860,7 @@ impl AppState {
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client.clone());
|
||||||
let project_store = cx.add_model(|_| ProjectStore::new(project::Db::open_fake()));
|
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 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 {
|
Arc::new(Self {
|
||||||
client,
|
client,
|
||||||
themes,
|
themes,
|
||||||
|
|
|
@ -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 default_settings = Settings::defaults(Assets, &app.font_cache(), &themes);
|
||||||
|
|
||||||
let config_files = load_config_files(&app, fs.clone());
|
let config_files = load_config_files(&app, fs.clone());
|
||||||
|
|
|
@ -153,7 +153,7 @@ mod tests {
|
||||||
watch_settings_file(
|
watch_settings_file(
|
||||||
default_settings.clone(),
|
default_settings.clone(),
|
||||||
source,
|
source,
|
||||||
ThemeRegistry::new((), font_cache),
|
ThemeRegistry::new((), font_cache, false),
|
||||||
false,
|
false,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1664,7 +1664,7 @@ mod tests {
|
||||||
.into(),
|
.into(),
|
||||||
])
|
])
|
||||||
.unwrap();
|
.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 settings = Settings::defaults(Assets, cx.font_cache(), &themes);
|
||||||
|
|
||||||
let mut has_default_theme = false;
|
let mut has_default_theme = false;
|
||||||
|
|
Loading…
Reference in a new issue