Update outline panel representation when a theme is changed (#19747)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-10-25 22:04:02 +03:00 committed by GitHub
parent c9db1b9a7b
commit 6de5ace116
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 38 additions and 26 deletions

View file

@ -41,7 +41,7 @@ use search::{BufferSearchBar, ProjectSearchView};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsStore}; use settings::{Settings, SettingsStore};
use smol::channel; use smol::channel;
use theme::SyntaxTheme; use theme::{SyntaxTheme, ThemeSettings};
use util::{debug_panic, RangeExt, ResultExt, TryFutureExt}; use util::{debug_panic, RangeExt, ResultExt, TryFutureExt};
use workspace::{ use workspace::{
dock::{DockPosition, Panel, PanelEvent}, dock::{DockPosition, Panel, PanelEvent},
@ -653,10 +653,22 @@ impl OutlinePanel {
}); });
let mut outline_panel_settings = *OutlinePanelSettings::get_global(cx); let mut outline_panel_settings = *OutlinePanelSettings::get_global(cx);
let settings_subscription = cx.observe_global::<SettingsStore>(move |_, cx| { let mut current_theme = ThemeSettings::get_global(cx).clone();
let new_settings = *OutlinePanelSettings::get_global(cx); let settings_subscription =
if outline_panel_settings != new_settings { cx.observe_global::<SettingsStore>(move |outline_panel, cx| {
outline_panel_settings = new_settings; let new_settings = OutlinePanelSettings::get_global(cx);
let new_theme = ThemeSettings::get_global(cx);
if &current_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(); cx.notify();
} }
}); });

View file

@ -71,7 +71,7 @@ pub struct ThemeContent {
} }
/// The content of a serialized theme. /// The content of a serialized theme.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(default)] #[serde(default)]
pub struct ThemeStyleContent { pub struct ThemeStyleContent {
#[serde(default, rename = "background.appearance")] #[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)] #[serde(default)]
pub struct ThemeColorsContent { pub struct ThemeColorsContent {
/// Border color. Used for most borders, is usually a high contrast color. /// Border color. Used for most borders, is usually a high contrast color.
@ -952,7 +952,7 @@ impl ThemeColorsContent {
} }
} }
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(default)] #[serde(default)]
pub struct StatusColorsContent { pub struct StatusColorsContent {
/// Indicates some kind of conflict, like a file changed on disk while it was open, or /// Indicates some kind of conflict, like a file changed on disk while it was open, or
@ -1273,17 +1273,17 @@ impl StatusColorsContent {
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct AccentContent(pub Option<String>); pub struct AccentContent(pub Option<String>);
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct PlayerColorContent { pub struct PlayerColorContent {
pub cursor: Option<String>, pub cursor: Option<String>,
pub background: Option<String>, pub background: Option<String>,
pub selection: Option<String>, pub selection: Option<String>,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum FontStyleContent { pub enum FontStyleContent {
Normal, Normal,
@ -1301,7 +1301,7 @@ impl From<FontStyleContent> for FontStyle {
} }
} }
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)] #[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq)]
#[repr(u16)] #[repr(u16)]
pub enum FontWeightContent { pub enum FontWeightContent {
Thin = 100, Thin = 100,
@ -1359,7 +1359,7 @@ impl From<FontWeightContent> for FontWeight {
} }
} }
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(default)] #[serde(default)]
pub struct HighlightStyleContent { pub struct HighlightStyleContent {
pub color: Option<String>, pub color: Option<String>,

View file

@ -86,7 +86,7 @@ impl From<UiDensity> for String {
} }
/// Customizable settings for the UI and theme system. /// Customizable settings for the UI and theme system.
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct ThemeSettings { pub struct ThemeSettings {
/// The UI font size. Determines the size of text in the UI, /// The UI font size. Determines the size of text in the UI,
/// as well as the size of a [gpui::Rems] unit. /// as well as the size of a [gpui::Rems] unit.
@ -213,7 +213,7 @@ pub(crate) struct AdjustedUiFontSize(Pixels);
impl Global for AdjustedUiFontSize {} impl Global for AdjustedUiFontSize {}
/// Represents the selection of a theme, which can be either static or dynamic. /// 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)] #[serde(untagged)]
pub enum ThemeSelection { pub enum ThemeSelection {
/// A static theme selection, represented by a single theme name. /// A static theme selection, represented by a single theme name.

View file

@ -7,7 +7,7 @@ use crate::{
}; };
/// A collection of colors that are used to color indent aware lines in the editor. /// 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<Hsla>); pub struct AccentColors(pub Vec<Hsla>);
impl Default for AccentColors { impl Default for AccentColors {

View file

@ -8,7 +8,7 @@ use crate::{
AccentColors, PlayerColors, StatusColors, StatusColorsRefinement, SyntaxTheme, SystemColors, AccentColors, PlayerColors, StatusColors, StatusColorsRefinement, SyntaxTheme, SystemColors,
}; };
#[derive(Refineable, Clone, Debug)] #[derive(Refineable, Clone, Debug, PartialEq)]
#[refineable(Debug, serde::Deserialize)] #[refineable(Debug, serde::Deserialize)]
pub struct ThemeColors { pub struct ThemeColors {
/// Border color. Used for most borders, is usually a high contrast color. /// Border color. Used for most borders, is usually a high contrast color.
@ -249,7 +249,7 @@ pub struct ThemeColors {
pub link_text_hover: Hsla, pub link_text_hover: Hsla,
} }
#[derive(Refineable, Clone)] #[derive(Refineable, Clone, PartialEq)]
pub struct ThemeStyles { pub struct ThemeStyles {
/// The background appearance of the window. /// The background appearance of the window.
pub window_background_appearance: WindowBackgroundAppearance, pub window_background_appearance: WindowBackgroundAppearance,

View file

@ -7,7 +7,7 @@ use crate::{
amber, blue, jade, lime, orange, pink, purple, red, try_parse_color, PlayerColorContent, 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 struct PlayerColor {
pub cursor: Hsla, pub cursor: Hsla,
pub background: Hsla, pub background: Hsla,
@ -20,7 +20,7 @@ pub struct PlayerColor {
/// ///
/// The rest of the default colors crisscross back and forth on the /// The rest of the default colors crisscross back and forth on the
/// color wheel so that the colors are as distinct as possible. /// color wheel so that the colors are as distinct as possible.
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct PlayerColors(pub Vec<PlayerColor>); pub struct PlayerColors(pub Vec<PlayerColor>);
impl Default for PlayerColors { impl Default for PlayerColors {

View file

@ -5,7 +5,7 @@ use refineable::Refineable;
use crate::{blue, grass, neutral, red, yellow}; use crate::{blue, grass, neutral, red, yellow};
#[derive(Refineable, Clone, Debug)] #[derive(Refineable, Clone, Debug, PartialEq)]
#[refineable(Debug, serde::Deserialize)] #[refineable(Debug, serde::Deserialize)]
pub struct StatusColors { pub struct StatusColors {
/// Indicates some kind of conflict, like a file changed on disk while it was open, or /// Indicates some kind of conflict, like a file changed on disk while it was open, or

View file

@ -2,7 +2,7 @@
use gpui::{hsla, Hsla}; use gpui::{hsla, Hsla};
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct SystemColors { pub struct SystemColors {
pub transparent: Hsla, pub transparent: Hsla,
pub mac_os_traffic_light_red: Hsla, pub mac_os_traffic_light_red: Hsla,

View file

@ -140,7 +140,7 @@ pub struct ThemeFamily {
impl ThemeFamily {} impl ThemeFamily {}
/// A theme is the primary mechanism for defining the appearance of the UI. /// A theme is the primary mechanism for defining the appearance of the UI.
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct Theme { pub struct Theme {
/// The unique identifier for the theme. /// The unique identifier for the theme.
pub id: String, pub id: String,