theme: Turn ThemeRegistry
into a trait (#20076)
This PR converts the `ThemeRegistry` type into a trait instead of a concrete implementation. This allows for the extension store to depend on an abstraction rather than the concrete theme registry implementation. We currently have two `ThemeRegistry` implementations: - `RealThemeRegistry` — this was previously the `ThemeRegistry` and contains the real implementation of the registry. - `VoidThemeRegistry` — a null object that doesn't have any behavior. Release Notes: - N/A
This commit is contained in:
parent
c04c439d23
commit
af9e7f1f96
13 changed files with 184 additions and 118 deletions
|
@ -150,7 +150,7 @@ impl ThemeSettings {
|
|||
|
||||
// If the selected theme doesn't exist, fall back to a default theme
|
||||
// based on the system appearance.
|
||||
let theme_registry = ThemeRegistry::global(cx);
|
||||
let theme_registry = <dyn ThemeRegistry>::global(cx);
|
||||
if theme_registry.get(theme_name).ok().is_none() {
|
||||
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 `None` otherwise.
|
||||
pub fn switch_theme(&mut self, theme: &str, cx: &mut AppContext) -> Option<Arc<Theme>> {
|
||||
let themes = ThemeRegistry::default_global(cx);
|
||||
let themes = <dyn ThemeRegistry>::default_global(cx);
|
||||
|
||||
let mut new_theme = None;
|
||||
|
||||
|
@ -598,7 +598,7 @@ impl settings::Settings for ThemeSettings {
|
|||
type FileContent = ThemeSettingsContent;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, cx: &mut AppContext) -> Result<Self> {
|
||||
let themes = ThemeRegistry::default_global(cx);
|
||||
let themes = <dyn ThemeRegistry>::default_global(cx);
|
||||
let system_appearance = SystemAppearance::default_global(cx);
|
||||
|
||||
let defaults = sources.default;
|
||||
|
@ -710,7 +710,7 @@ impl settings::Settings for ThemeSettings {
|
|||
cx: &AppContext,
|
||||
) -> schemars::schema::RootSchema {
|
||||
let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>();
|
||||
let theme_names = ThemeRegistry::global(cx)
|
||||
let theme_names = <dyn ThemeRegistry>::global(cx)
|
||||
.list_names(params.staff_mode)
|
||||
.into_iter()
|
||||
.map(|theme_name| Value::String(theme_name.to_string()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue