This PR reverts #20076 to turn the `ThemeRegistry` back into a regular struct again. It doesn't actually help us by having it behind a trait. Release Notes: - N/A
This commit is contained in:
parent
4084ba36f9
commit
273173ec8a
12 changed files with 89 additions and 151 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -12098,7 +12098,6 @@ name = "theme"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
|
||||||
"collections",
|
"collections",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"fs",
|
"fs",
|
||||||
|
|
|
@ -112,7 +112,7 @@ pub struct ExtensionStore {
|
||||||
outstanding_operations: BTreeMap<Arc<str>, ExtensionOperation>,
|
outstanding_operations: BTreeMap<Arc<str>, ExtensionOperation>,
|
||||||
index_path: PathBuf,
|
index_path: PathBuf,
|
||||||
language_registry: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
theme_registry: Arc<dyn ThemeRegistry>,
|
theme_registry: Arc<ThemeRegistry>,
|
||||||
slash_command_registry: Arc<SlashCommandRegistry>,
|
slash_command_registry: Arc<SlashCommandRegistry>,
|
||||||
indexed_docs_registry: Arc<IndexedDocsRegistry>,
|
indexed_docs_registry: Arc<IndexedDocsRegistry>,
|
||||||
snippet_registry: Arc<SnippetRegistry>,
|
snippet_registry: Arc<SnippetRegistry>,
|
||||||
|
@ -177,7 +177,7 @@ pub fn init(
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
node_runtime: NodeRuntime,
|
node_runtime: NodeRuntime,
|
||||||
language_registry: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
theme_registry: Arc<dyn ThemeRegistry>,
|
theme_registry: Arc<ThemeRegistry>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) {
|
) {
|
||||||
ExtensionSettings::register(cx);
|
ExtensionSettings::register(cx);
|
||||||
|
@ -228,7 +228,7 @@ impl ExtensionStore {
|
||||||
telemetry: Option<Arc<Telemetry>>,
|
telemetry: Option<Arc<Telemetry>>,
|
||||||
node_runtime: NodeRuntime,
|
node_runtime: NodeRuntime,
|
||||||
language_registry: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
theme_registry: Arc<dyn ThemeRegistry>,
|
theme_registry: Arc<ThemeRegistry>,
|
||||||
slash_command_registry: Arc<SlashCommandRegistry>,
|
slash_command_registry: Arc<SlashCommandRegistry>,
|
||||||
indexed_docs_registry: Arc<IndexedDocsRegistry>,
|
indexed_docs_registry: Arc<IndexedDocsRegistry>,
|
||||||
snippet_registry: Arc<SnippetRegistry>,
|
snippet_registry: Arc<SnippetRegistry>,
|
||||||
|
|
|
@ -27,7 +27,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use theme::{RealThemeRegistry, ThemeRegistry};
|
use theme::ThemeRegistry;
|
||||||
use util::test::temp_tree;
|
use util::test::temp_tree;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -260,7 +260,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let language_registry = Arc::new(LanguageRegistry::test(cx.executor()));
|
let language_registry = Arc::new(LanguageRegistry::test(cx.executor()));
|
||||||
let theme_registry = Arc::new(RealThemeRegistry::new(Box::new(())));
|
let theme_registry = Arc::new(ThemeRegistry::new(Box::new(())));
|
||||||
let slash_command_registry = SlashCommandRegistry::new();
|
let slash_command_registry = SlashCommandRegistry::new();
|
||||||
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
||||||
let snippet_registry = Arc::new(SnippetRegistry::new());
|
let snippet_registry = Arc::new(SnippetRegistry::new());
|
||||||
|
@ -486,7 +486,7 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
|
||||||
let project = Project::test(fs.clone(), [project_dir.as_path()], cx).await;
|
let project = Project::test(fs.clone(), [project_dir.as_path()], cx).await;
|
||||||
|
|
||||||
let language_registry = project.read_with(cx, |project, _cx| project.languages().clone());
|
let language_registry = project.read_with(cx, |project, _cx| project.languages().clone());
|
||||||
let theme_registry = Arc::new(RealThemeRegistry::new(Box::new(())));
|
let theme_registry = Arc::new(ThemeRegistry::new(Box::new(())));
|
||||||
let slash_command_registry = SlashCommandRegistry::new();
|
let slash_command_registry = SlashCommandRegistry::new();
|
||||||
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
||||||
let snippet_registry = Arc::new(SnippetRegistry::new());
|
let snippet_registry = Arc::new(SnippetRegistry::new());
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl RenderOnce for ThemeControl {
|
||||||
"theme",
|
"theme",
|
||||||
value.clone(),
|
value.clone(),
|
||||||
ContextMenu::build(cx, |mut menu, cx| {
|
ContextMenu::build(cx, |mut menu, cx| {
|
||||||
let theme_registry = <dyn ThemeRegistry>::global(cx);
|
let theme_registry = ThemeRegistry::global(cx);
|
||||||
|
|
||||||
for theme in theme_registry.list_names() {
|
for theme in theme_registry.list_names() {
|
||||||
menu = menu.custom_entry(
|
menu = menu.custom_entry(
|
||||||
|
|
|
@ -76,7 +76,7 @@ fn main() {
|
||||||
|
|
||||||
let selector = story_selector;
|
let selector = story_selector;
|
||||||
|
|
||||||
let theme_registry = <dyn ThemeRegistry>::global(cx);
|
let theme_registry = ThemeRegistry::global(cx);
|
||||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
||||||
theme_settings.active_theme = theme_registry.get(&theme_name).unwrap();
|
theme_settings.active_theme = theme_registry.get(&theme_name).unwrap();
|
||||||
ThemeSettings::override_global(theme_settings, cx);
|
ThemeSettings::override_global(theme_settings, cx);
|
||||||
|
|
|
@ -18,7 +18,6 @@ doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
async-trait.workspace = true
|
|
||||||
collections.workspace = true
|
collections.workspace = true
|
||||||
derive_more.workspace = true
|
derive_more.workspace = true
|
||||||
fs.workspace = true
|
fs.workspace = true
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{fmt::Debug, path::Path};
|
use std::{fmt::Debug, path::Path};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use async_trait::async_trait;
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
|
@ -30,34 +29,22 @@ pub struct ThemeMeta {
|
||||||
/// inserting the [`ThemeRegistry`] into the context as a global.
|
/// inserting the [`ThemeRegistry`] into the context as a global.
|
||||||
///
|
///
|
||||||
/// This should not be exposed outside of this module.
|
/// This should not be exposed outside of this module.
|
||||||
#[derive(Deref, DerefMut)]
|
#[derive(Default, Deref, DerefMut)]
|
||||||
struct GlobalThemeRegistry(Arc<dyn ThemeRegistry>);
|
struct GlobalThemeRegistry(Arc<ThemeRegistry>);
|
||||||
|
|
||||||
impl Global for GlobalThemeRegistry {}
|
impl Global for GlobalThemeRegistry {}
|
||||||
|
|
||||||
/// A registry for themes.
|
struct ThemeRegistryState {
|
||||||
#[async_trait]
|
themes: HashMap<SharedString, Arc<Theme>>,
|
||||||
pub trait ThemeRegistry: Send + Sync + 'static {
|
|
||||||
/// Returns the names of all themes in the registry.
|
|
||||||
fn list_names(&self) -> Vec<SharedString>;
|
|
||||||
|
|
||||||
/// Returns the metadata of all themes in the registry.
|
|
||||||
fn list(&self) -> Vec<ThemeMeta>;
|
|
||||||
|
|
||||||
/// Returns the theme with the given name.
|
|
||||||
fn get(&self, name: &str) -> Result<Arc<Theme>>;
|
|
||||||
|
|
||||||
/// Loads the user theme from the specified path and adds it to the registry.
|
|
||||||
async fn load_user_theme(&self, theme_path: &Path, fs: Arc<dyn Fs>) -> Result<()>;
|
|
||||||
|
|
||||||
/// Loads the user themes from the specified directory and adds them to the registry.
|
|
||||||
async fn load_user_themes(&self, themes_path: &Path, fs: Arc<dyn Fs>) -> Result<()>;
|
|
||||||
|
|
||||||
/// Removes the themes with the given names from the registry.
|
|
||||||
fn remove_user_themes(&self, themes_to_remove: &[SharedString]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl dyn ThemeRegistry {
|
/// The registry for themes.
|
||||||
|
pub struct ThemeRegistry {
|
||||||
|
state: RwLock<ThemeRegistryState>,
|
||||||
|
assets: Box<dyn AssetSource>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThemeRegistry {
|
||||||
/// Returns the global [`ThemeRegistry`].
|
/// Returns the global [`ThemeRegistry`].
|
||||||
pub fn global(cx: &AppContext) -> Arc<Self> {
|
pub fn global(cx: &AppContext) -> Arc<Self> {
|
||||||
cx.global::<GlobalThemeRegistry>().0.clone()
|
cx.global::<GlobalThemeRegistry>().0.clone()
|
||||||
|
@ -67,37 +54,18 @@ impl dyn ThemeRegistry {
|
||||||
///
|
///
|
||||||
/// Inserts a default [`ThemeRegistry`] if one does not yet exist.
|
/// Inserts a default [`ThemeRegistry`] if one does not yet exist.
|
||||||
pub fn default_global(cx: &mut AppContext) -> Arc<Self> {
|
pub fn default_global(cx: &mut AppContext) -> Arc<Self> {
|
||||||
if let Some(registry) = cx.try_global::<GlobalThemeRegistry>() {
|
cx.default_global::<GlobalThemeRegistry>().0.clone()
|
||||||
return registry.0.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
let registry = Arc::new(RealThemeRegistry::default());
|
|
||||||
cx.set_global(GlobalThemeRegistry(registry.clone()));
|
|
||||||
|
|
||||||
registry
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
struct RealThemeRegistryState {
|
|
||||||
themes: HashMap<SharedString, Arc<Theme>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The registry for themes.
|
|
||||||
pub struct RealThemeRegistry {
|
|
||||||
state: RwLock<RealThemeRegistryState>,
|
|
||||||
assets: Box<dyn AssetSource>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RealThemeRegistry {
|
|
||||||
/// Sets the global [`ThemeRegistry`].
|
/// Sets the global [`ThemeRegistry`].
|
||||||
pub(crate) fn set_global(self: Arc<Self>, cx: &mut AppContext) {
|
pub(crate) fn set_global(assets: Box<dyn AssetSource>, cx: &mut AppContext) {
|
||||||
cx.set_global(GlobalThemeRegistry(self));
|
cx.set_global(GlobalThemeRegistry(Arc::new(ThemeRegistry::new(assets))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`ThemeRegistry`] with the given [`AssetSource`].
|
/// Creates a new [`ThemeRegistry`] with the given [`AssetSource`].
|
||||||
pub fn new(assets: Box<dyn AssetSource>) -> Self {
|
pub fn new(assets: Box<dyn AssetSource>) -> Self {
|
||||||
let registry = Self {
|
let registry = Self {
|
||||||
state: RwLock::new(RealThemeRegistryState {
|
state: RwLock::new(ThemeRegistryState {
|
||||||
themes: HashMap::default(),
|
themes: HashMap::default(),
|
||||||
}),
|
}),
|
||||||
assets,
|
assets,
|
||||||
|
@ -132,11 +100,49 @@ impl RealThemeRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes the themes with the given names from the registry.
|
||||||
|
pub fn remove_user_themes(&self, themes_to_remove: &[SharedString]) {
|
||||||
|
self.state
|
||||||
|
.write()
|
||||||
|
.themes
|
||||||
|
.retain(|name, _| !themes_to_remove.contains(name))
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes all themes from the registry.
|
/// Removes all themes from the registry.
|
||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
self.state.write().themes.clear();
|
self.state.write().themes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the names of all themes in the registry.
|
||||||
|
pub fn list_names(&self) -> Vec<SharedString> {
|
||||||
|
let mut names = self.state.read().themes.keys().cloned().collect::<Vec<_>>();
|
||||||
|
names.sort();
|
||||||
|
names
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the metadata of all themes in the registry.
|
||||||
|
pub fn list(&self) -> Vec<ThemeMeta> {
|
||||||
|
self.state
|
||||||
|
.read()
|
||||||
|
.themes
|
||||||
|
.values()
|
||||||
|
.map(|theme| ThemeMeta {
|
||||||
|
name: theme.name.clone(),
|
||||||
|
appearance: theme.appearance(),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the theme with the given name.
|
||||||
|
pub fn get(&self, name: &str) -> Result<Arc<Theme>> {
|
||||||
|
self.state
|
||||||
|
.read()
|
||||||
|
.themes
|
||||||
|
.get(name)
|
||||||
|
.ok_or_else(|| anyhow!("theme not found: {}", name))
|
||||||
|
.cloned()
|
||||||
|
}
|
||||||
|
|
||||||
/// Loads the themes bundled with the Zed binary and adds them to the registry.
|
/// Loads the themes bundled with the Zed binary and adds them to the registry.
|
||||||
pub fn load_bundled_themes(&self) {
|
pub fn load_bundled_themes(&self) {
|
||||||
let theme_paths = self
|
let theme_paths = self
|
||||||
|
@ -161,52 +167,9 @@ impl RealThemeRegistry {
|
||||||
self.insert_user_theme_families([theme_family]);
|
self.insert_user_theme_families([theme_family]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RealThemeRegistry {
|
/// Loads the user themes from the specified directory and adds them to the registry.
|
||||||
fn default() -> Self {
|
pub async fn load_user_themes(&self, themes_path: &Path, fs: Arc<dyn Fs>) -> Result<()> {
|
||||||
Self::new(Box::new(()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ThemeRegistry for RealThemeRegistry {
|
|
||||||
fn list_names(&self) -> Vec<SharedString> {
|
|
||||||
let mut names = self.state.read().themes.keys().cloned().collect::<Vec<_>>();
|
|
||||||
names.sort();
|
|
||||||
names
|
|
||||||
}
|
|
||||||
|
|
||||||
fn list(&self) -> Vec<ThemeMeta> {
|
|
||||||
self.state
|
|
||||||
.read()
|
|
||||||
.themes
|
|
||||||
.values()
|
|
||||||
.map(|theme| ThemeMeta {
|
|
||||||
name: theme.name.clone(),
|
|
||||||
appearance: theme.appearance(),
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, name: &str) -> Result<Arc<Theme>> {
|
|
||||||
self.state
|
|
||||||
.read()
|
|
||||||
.themes
|
|
||||||
.get(name)
|
|
||||||
.ok_or_else(|| anyhow!("theme not found: {}", name))
|
|
||||||
.cloned()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn load_user_theme(&self, theme_path: &Path, fs: Arc<dyn Fs>) -> Result<()> {
|
|
||||||
let theme = read_user_theme(theme_path, fs).await?;
|
|
||||||
|
|
||||||
self.insert_user_theme_families([theme]);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn load_user_themes(&self, themes_path: &Path, fs: Arc<dyn Fs>) -> Result<()> {
|
|
||||||
let mut theme_paths = fs
|
let mut theme_paths = fs
|
||||||
.read_dir(themes_path)
|
.read_dir(themes_path)
|
||||||
.await
|
.await
|
||||||
|
@ -225,38 +188,18 @@ impl ThemeRegistry for RealThemeRegistry {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_user_themes(&self, themes_to_remove: &[SharedString]) {
|
/// Loads the user theme from the specified path and adds it to the registry.
|
||||||
self.state
|
pub async fn load_user_theme(&self, theme_path: &Path, fs: Arc<dyn Fs>) -> Result<()> {
|
||||||
.write()
|
let theme = read_user_theme(theme_path, fs).await?;
|
||||||
.themes
|
|
||||||
.retain(|name, _| !themes_to_remove.contains(name))
|
self.insert_user_theme_families([theme]);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A theme registry that doesn't have any behavior.
|
impl Default for ThemeRegistry {
|
||||||
pub struct VoidThemeRegistry;
|
fn default() -> Self {
|
||||||
|
Self::new(Box::new(()))
|
||||||
#[async_trait]
|
|
||||||
impl ThemeRegistry for VoidThemeRegistry {
|
|
||||||
fn list_names(&self) -> Vec<SharedString> {
|
|
||||||
Vec::new()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(&self) -> Vec<ThemeMeta> {
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, name: &str) -> Result<Arc<Theme>> {
|
|
||||||
bail!("cannot retrieve theme {name:?} from a void theme registry")
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn load_user_theme(&self, _theme_path: &Path, _fs: Arc<dyn Fs>) -> Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn load_user_themes(&self, _themes_path: &Path, _fs: Arc<dyn Fs>) -> Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_user_themes(&self, _themes_to_remove: &[SharedString]) {}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ impl ThemeSettings {
|
||||||
|
|
||||||
// If the selected theme doesn't exist, fall back to a default theme
|
// If the selected theme doesn't exist, fall back to a default theme
|
||||||
// based on the system appearance.
|
// based on the system appearance.
|
||||||
let theme_registry = <dyn ThemeRegistry>::global(cx);
|
let theme_registry = ThemeRegistry::global(cx);
|
||||||
if theme_registry.get(theme_name).ok().is_none() {
|
if theme_registry.get(theme_name).ok().is_none() {
|
||||||
theme_name = Self::default_theme(*system_appearance);
|
theme_name = Self::default_theme(*system_appearance);
|
||||||
};
|
};
|
||||||
|
@ -446,7 +446,7 @@ impl ThemeSettings {
|
||||||
/// Returns a `Some` containing the new theme if it was successful.
|
/// Returns a `Some` containing the new theme if it was successful.
|
||||||
/// Returns `None` otherwise.
|
/// Returns `None` otherwise.
|
||||||
pub fn switch_theme(&mut self, theme: &str, cx: &mut AppContext) -> Option<Arc<Theme>> {
|
pub fn switch_theme(&mut self, theme: &str, cx: &mut AppContext) -> Option<Arc<Theme>> {
|
||||||
let themes = <dyn ThemeRegistry>::default_global(cx);
|
let themes = ThemeRegistry::default_global(cx);
|
||||||
|
|
||||||
let mut new_theme = None;
|
let mut new_theme = None;
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ impl settings::Settings for ThemeSettings {
|
||||||
type FileContent = ThemeSettingsContent;
|
type FileContent = ThemeSettingsContent;
|
||||||
|
|
||||||
fn load(sources: SettingsSources<Self::FileContent>, cx: &mut AppContext) -> Result<Self> {
|
fn load(sources: SettingsSources<Self::FileContent>, cx: &mut AppContext) -> Result<Self> {
|
||||||
let themes = <dyn ThemeRegistry>::default_global(cx);
|
let themes = ThemeRegistry::default_global(cx);
|
||||||
let system_appearance = SystemAppearance::default_global(cx);
|
let system_appearance = SystemAppearance::default_global(cx);
|
||||||
|
|
||||||
let defaults = sources.default;
|
let defaults = sources.default;
|
||||||
|
@ -710,7 +710,7 @@ impl settings::Settings for ThemeSettings {
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> schemars::schema::RootSchema {
|
) -> schemars::schema::RootSchema {
|
||||||
let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>();
|
let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>();
|
||||||
let theme_names = <dyn ThemeRegistry>::global(cx)
|
let theme_names = ThemeRegistry::global(cx)
|
||||||
.list_names()
|
.list_names()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|theme_name| Value::String(theme_name.to_string()))
|
.map(|theme_name| Value::String(theme_name.to_string()))
|
||||||
|
|
|
@ -88,11 +88,10 @@ pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
|
||||||
LoadThemes::JustBase => (Box::new(()) as Box<dyn AssetSource>, false),
|
LoadThemes::JustBase => (Box::new(()) as Box<dyn AssetSource>, false),
|
||||||
LoadThemes::All(assets) => (assets, true),
|
LoadThemes::All(assets) => (assets, true),
|
||||||
};
|
};
|
||||||
let registry = Arc::new(RealThemeRegistry::new(assets));
|
ThemeRegistry::set_global(assets, cx);
|
||||||
registry.clone().set_global(cx);
|
|
||||||
|
|
||||||
if load_user_themes {
|
if load_user_themes {
|
||||||
registry.load_bundled_themes();
|
ThemeRegistry::global(cx).load_bundled_themes();
|
||||||
}
|
}
|
||||||
|
|
||||||
ThemeSettings::register(cx);
|
ThemeSettings::register(cx);
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl ThemeSelectorDelegate {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let original_theme = cx.theme().clone();
|
let original_theme = cx.theme().clone();
|
||||||
|
|
||||||
let registry = <dyn ThemeRegistry>::global(cx);
|
let registry = ThemeRegistry::global(cx);
|
||||||
let mut themes = registry
|
let mut themes = registry
|
||||||
.list()
|
.list()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -140,7 +140,7 @@ impl ThemeSelectorDelegate {
|
||||||
|
|
||||||
fn show_selected_theme(&mut self, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
|
fn show_selected_theme(&mut self, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
|
||||||
if let Some(mat) = self.matches.get(self.selected_index) {
|
if let Some(mat) = self.matches.get(self.selected_index) {
|
||||||
let registry = <dyn ThemeRegistry>::global(cx);
|
let registry = ThemeRegistry::global(cx);
|
||||||
match registry.get(&mat.string) {
|
match registry.get(&mat.string) {
|
||||||
Ok(theme) => {
|
Ok(theme) => {
|
||||||
Self::set_theme(theme, cx);
|
Self::set_theme(theme, cx);
|
||||||
|
|
|
@ -407,7 +407,7 @@ fn main() {
|
||||||
app_state.client.clone(),
|
app_state.client.clone(),
|
||||||
app_state.node_runtime.clone(),
|
app_state.node_runtime.clone(),
|
||||||
app_state.languages.clone(),
|
app_state.languages.clone(),
|
||||||
<dyn ThemeRegistry>::global(cx),
|
ThemeRegistry::global(cx),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
recent_projects::init(cx);
|
recent_projects::init(cx);
|
||||||
|
@ -1160,9 +1160,8 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||||
cx.spawn({
|
cx.spawn({
|
||||||
let fs = fs.clone();
|
let fs = fs.clone();
|
||||||
|cx| async move {
|
|cx| async move {
|
||||||
if let Some(theme_registry) = cx
|
if let Some(theme_registry) =
|
||||||
.update(|cx| <dyn ThemeRegistry>::global(cx).clone())
|
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
|
||||||
.log_err()
|
|
||||||
{
|
{
|
||||||
let themes_dir = paths::themes_dir().as_ref();
|
let themes_dir = paths::themes_dir().as_ref();
|
||||||
match fs
|
match fs
|
||||||
|
@ -1201,9 +1200,8 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||||
while let Some(paths) = events.next().await {
|
while let Some(paths) = events.next().await {
|
||||||
for event in paths {
|
for event in paths {
|
||||||
if fs.metadata(&event.path).await.ok().flatten().is_some() {
|
if fs.metadata(&event.path).await.ok().flatten().is_some() {
|
||||||
if let Some(theme_registry) = cx
|
if let Some(theme_registry) =
|
||||||
.update(|cx| <dyn ThemeRegistry>::global(cx).clone())
|
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
|
||||||
.log_err()
|
|
||||||
{
|
{
|
||||||
if let Some(()) = theme_registry
|
if let Some(()) = theme_registry
|
||||||
.load_user_theme(&event.path, fs.clone())
|
.load_user_theme(&event.path, fs.clone())
|
||||||
|
|
|
@ -1139,7 +1139,7 @@ mod tests {
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use theme::{RealThemeRegistry, ThemeRegistry, ThemeSettings};
|
use theme::{ThemeRegistry, ThemeSettings};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{Item, ItemHandle},
|
item::{Item, ItemHandle},
|
||||||
open_new, open_paths, pane, NewFile, OpenVisible, SaveIntent, SplitDirection,
|
open_new, open_paths, pane, NewFile, OpenVisible, SaveIntent, SplitDirection,
|
||||||
|
@ -3419,7 +3419,7 @@ mod tests {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
])
|
])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let themes = RealThemeRegistry::default();
|
let themes = ThemeRegistry::default();
|
||||||
settings::init(cx);
|
settings::init(cx);
|
||||||
theme::init(theme::LoadThemes::JustBase, cx);
|
theme::init(theme::LoadThemes::JustBase, cx);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue