theme: Add theme_name to get current active theme name. (#1190)

And fix theme menu selected item in example when theme mode changed.
This commit is contained in:
Jason Lee 2025-09-01 11:39:01 +08:00 committed by GitHub
parent e4a367f157
commit 34d2a75894
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -6,7 +6,7 @@ use gpui::{
use gpui_component::{ use gpui_component::{
button::{Button, ButtonVariants}, button::{Button, ButtonVariants},
popup_menu::PopupMenuExt, popup_menu::PopupMenuExt,
IconName, Sizable, Theme, ThemeRegistry, ActiveTheme, IconName, Sizable, Theme, ThemeRegistry,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -38,6 +38,11 @@ pub fn init(cx: &mut App) {
}) { }) {
tracing::error!("Failed to watch themes directory: {}", err); tracing::error!("Failed to watch themes directory: {}", err);
} }
cx.observe_global::<Theme>(|cx| {
AppState::global_mut(cx).theme_name = Some(cx.theme().theme_name().into());
})
.detach();
} }
#[derive(Action, Clone, PartialEq)] #[derive(Action, Clone, PartialEq)]

View file

@ -101,6 +101,15 @@ impl Theme {
self.mode.is_dark() self.mode.is_dark()
} }
/// Returns the current theme name.
pub fn theme_name(&self) -> &SharedString {
if self.is_dark() {
&self.dark_theme.name
} else {
&self.light_theme.name
}
}
// /// Sets the theme to default light. // /// Sets the theme to default light.
// pub fn set_default_light(&mut self) { // pub fn set_default_light(&mut self) {
// self.light_theme = ThemeColor::light(); // self.light_theme = ThemeColor::light();