From 6281df900cf2e17e93675c69334365ebe7181938 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 25 Oct 2024 22:04:02 +0300 Subject: [PATCH] Update outline panel representation when a theme is changed (#19747) Release Notes: - N/A --- crates/outline_panel/src/outline_panel.rs | 28 ++++++++++++++++------- crates/theme/src/schema.rs | 16 ++++++------- crates/theme/src/settings.rs | 4 ++-- crates/theme/src/styles/accents.rs | 2 +- crates/theme/src/styles/colors.rs | 4 ++-- crates/theme/src/styles/players.rs | 4 ++-- crates/theme/src/styles/status.rs | 2 +- crates/theme/src/styles/system.rs | 2 +- crates/theme/src/theme.rs | 2 +- 9 files changed, 38 insertions(+), 26 deletions(-) diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 4944f770e73a6c8106a1630bccb25c0ecc2b24cb..25dd5cba8dcbfa091b0f5dfdddd9ed822d6e1306 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -41,7 +41,7 @@ use search::{BufferSearchBar, ProjectSearchView}; use serde::{Deserialize, Serialize}; use settings::{Settings, SettingsStore}; use smol::channel; -use theme::SyntaxTheme; +use theme::{SyntaxTheme, ThemeSettings}; use util::{debug_panic, RangeExt, ResultExt, TryFutureExt}; use workspace::{ dock::{DockPosition, Panel, PanelEvent}, @@ -653,13 +653,25 @@ impl OutlinePanel { }); let mut outline_panel_settings = *OutlinePanelSettings::get_global(cx); - let settings_subscription = cx.observe_global::(move |_, cx| { - let new_settings = *OutlinePanelSettings::get_global(cx); - if outline_panel_settings != new_settings { - outline_panel_settings = new_settings; - cx.notify(); - } - }); + let mut current_theme = ThemeSettings::get_global(cx).clone(); + let settings_subscription = + cx.observe_global::(move |outline_panel, cx| { + let new_settings = OutlinePanelSettings::get_global(cx); + let new_theme = ThemeSettings::get_global(cx); + if ¤t_theme != new_theme { + outline_panel_settings = *new_settings; + current_theme = new_theme.clone(); + for excerpts in outline_panel.excerpts.values_mut() { + for excerpt in excerpts.values_mut() { + excerpt.invalidate_outlines(); + } + } + outline_panel.update_non_fs_items(cx); + } else if &outline_panel_settings != new_settings { + outline_panel_settings = *new_settings; + cx.notify(); + } + }); let mut outline_panel = Self { mode: ItemsDisplayMode::Outline, diff --git a/crates/theme/src/schema.rs b/crates/theme/src/schema.rs index af334d8aed54b9a9b9169a038445c5924ce6d65e..e3e77ad3d0fd6066975bc5ab3b53d9e668ec39aa 100644 --- a/crates/theme/src/schema.rs +++ b/crates/theme/src/schema.rs @@ -71,7 +71,7 @@ pub struct ThemeContent { } /// The content of a serialized theme. -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)] #[serde(default)] pub struct ThemeStyleContent { #[serde(default, rename = "background.appearance")] @@ -133,7 +133,7 @@ impl ThemeStyleContent { } } -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)] #[serde(default)] pub struct ThemeColorsContent { /// Border color. Used for most borders, is usually a high contrast color. @@ -931,7 +931,7 @@ impl ThemeColorsContent { } } -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)] #[serde(default)] pub struct StatusColorsContent { /// Indicates some kind of conflict, like a file changed on disk while it was open, or @@ -1252,17 +1252,17 @@ impl StatusColorsContent { } } -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] pub struct AccentContent(pub Option); -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] pub struct PlayerColorContent { pub cursor: Option, pub background: Option, pub selection: Option, } -#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)] #[serde(rename_all = "snake_case")] pub enum FontStyleContent { Normal, @@ -1280,7 +1280,7 @@ impl From for FontStyle { } } -#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)] +#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq)] #[repr(u16)] pub enum FontWeightContent { Thin = 100, @@ -1338,7 +1338,7 @@ impl From for FontWeight { } } -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)] #[serde(default)] pub struct HighlightStyleContent { pub color: Option, diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs index 49f7ba3c83676626ae69817add0d3f3d905db636..4d8158388cf0654a151c617d524edbf25685da66 100644 --- a/crates/theme/src/settings.rs +++ b/crates/theme/src/settings.rs @@ -86,7 +86,7 @@ impl From for String { } /// Customizable settings for the UI and theme system. -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct ThemeSettings { /// The UI font size. Determines the size of text in the UI, /// as well as the size of a [gpui::Rems] unit. @@ -213,7 +213,7 @@ pub(crate) struct AdjustedUiFontSize(Pixels); impl Global for AdjustedUiFontSize {} /// Represents the selection of a theme, which can be either static or dynamic. -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] #[serde(untagged)] pub enum ThemeSelection { /// A static theme selection, represented by a single theme name. diff --git a/crates/theme/src/styles/accents.rs b/crates/theme/src/styles/accents.rs index e4d7f03cf622016d353914ffc4598c781ee13d5a..773e3319acf95c7136b2e6f71c32db3774761d6a 100644 --- a/crates/theme/src/styles/accents.rs +++ b/crates/theme/src/styles/accents.rs @@ -7,7 +7,7 @@ use crate::{ }; /// A collection of colors that are used to color indent aware lines in the editor. -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct AccentColors(pub Vec); impl Default for AccentColors { diff --git a/crates/theme/src/styles/colors.rs b/crates/theme/src/styles/colors.rs index 881a68334dcf647325a25dc844d504da31d6082c..30e8b0aa3e7c06ebcf91d0a50b0f94b4f4078491 100644 --- a/crates/theme/src/styles/colors.rs +++ b/crates/theme/src/styles/colors.rs @@ -8,7 +8,7 @@ use crate::{ AccentColors, PlayerColors, StatusColors, StatusColorsRefinement, SyntaxTheme, SystemColors, }; -#[derive(Refineable, Clone, Debug)] +#[derive(Refineable, Clone, Debug, PartialEq)] #[refineable(Debug, serde::Deserialize)] pub struct ThemeColors { /// Border color. Used for most borders, is usually a high contrast color. @@ -246,7 +246,7 @@ pub struct ThemeColors { pub link_text_hover: Hsla, } -#[derive(Refineable, Clone)] +#[derive(Refineable, Clone, PartialEq)] pub struct ThemeStyles { /// The background appearance of the window. pub window_background_appearance: WindowBackgroundAppearance, diff --git a/crates/theme/src/styles/players.rs b/crates/theme/src/styles/players.rs index 130721033239ce67bf2fa0d527cb37e529566c1c..262048f2c65100a5ae3bea8ee465fcc2011650a0 100644 --- a/crates/theme/src/styles/players.rs +++ b/crates/theme/src/styles/players.rs @@ -7,7 +7,7 @@ use crate::{ amber, blue, jade, lime, orange, pink, purple, red, try_parse_color, PlayerColorContent, }; -#[derive(Debug, Clone, Copy, Deserialize, Default)] +#[derive(Debug, Clone, Copy, Deserialize, Default, PartialEq)] pub struct PlayerColor { pub cursor: Hsla, pub background: Hsla, @@ -20,7 +20,7 @@ pub struct PlayerColor { /// /// The rest of the default colors crisscross back and forth on the /// color wheel so that the colors are as distinct as possible. -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct PlayerColors(pub Vec); impl Default for PlayerColors { diff --git a/crates/theme/src/styles/status.rs b/crates/theme/src/styles/status.rs index 84afae701d0f099beea955b65a7828c6c0df623a..0d59f7c51c210c0f707fec55821a092cf47f3ac1 100644 --- a/crates/theme/src/styles/status.rs +++ b/crates/theme/src/styles/status.rs @@ -5,7 +5,7 @@ use refineable::Refineable; use crate::{blue, grass, neutral, red, yellow}; -#[derive(Refineable, Clone, Debug)] +#[derive(Refineable, Clone, Debug, PartialEq)] #[refineable(Debug, serde::Deserialize)] pub struct StatusColors { /// Indicates some kind of conflict, like a file changed on disk while it was open, or diff --git a/crates/theme/src/styles/system.rs b/crates/theme/src/styles/system.rs index 54e892b79c49f96e66c3817e9750fed3504327da..4f33711793b5f6dbd004fcc2b066ac542c15257b 100644 --- a/crates/theme/src/styles/system.rs +++ b/crates/theme/src/styles/system.rs @@ -2,7 +2,7 @@ use gpui::{hsla, Hsla}; -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct SystemColors { pub transparent: Hsla, pub mac_os_traffic_light_red: Hsla, diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index d4436e53295278349cff6b2f522d74c2585232f8..c62359242dd9d24093abfccfcc583262c94a99e9 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -140,7 +140,7 @@ pub struct ThemeFamily { impl ThemeFamily {} /// A theme is the primary mechanism for defining the appearance of the UI. -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct Theme { /// The unique identifier for the theme. pub id: String,