theme: Add support for setting light/dark icon themes (#24702)

This PR adds support for configuring both a light and dark icon theme in
`settings.json`.

In addition to accepting just an icon theme name, the `icon_theme` field
now also accepts an object in the following form:

```jsonc
{
  "icon_theme": {
    "mode": "system",
    "light": "Zed (Default)",
    "dark": "Zed (Default)"
  }
}
```

Both `light` and `dark` are required, and indicate which icon theme
should be used when the system is in light mode and dark mode,
respectively.

The `mode` field is optional and indicates which icon theme should be
used:
- `"system"` - Use the icon theme that corresponds to the system's
appearance.
- `"light"` - Use the icon theme indicated by the `light` field.
- `"dark"` - Use the icon theme indicated by the `dark` field.

Closes https://github.com/zed-industries/zed/issues/24695.

Release Notes:

- Added support for configuring both a light and dark icon theme and
switching between them based on system preference.
This commit is contained in:
Marshall Bowers 2025-02-11 18:45:37 -05:00 committed by GitHub
parent 148547ecd1
commit cc931a8fcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 142 additions and 22 deletions

View file

@ -7,7 +7,7 @@ use gpui::{
use picker::{Picker, PickerDelegate};
use settings::{update_settings_file, Settings as _, SettingsStore};
use std::sync::Arc;
use theme::{IconTheme, ThemeMeta, ThemeRegistry, ThemeSettings};
use theme::{Appearance, IconTheme, ThemeMeta, ThemeRegistry, ThemeSettings};
use ui::{prelude::*, v_flex, ListItem, ListItemSpacing};
use util::ResultExt;
use workspace::{ui::HighlightedLabel, ModalView};
@ -151,7 +151,7 @@ impl PickerDelegate for IconThemeSelectorDelegate {
fn confirm(
&mut self,
_: bool,
_window: &mut Window,
window: &mut Window,
cx: &mut Context<Picker<IconThemeSelectorDelegate>>,
) {
self.selection_completed = true;
@ -165,8 +165,10 @@ impl PickerDelegate for IconThemeSelectorDelegate {
value = theme_name
);
let appearance = Appearance::from(window.appearance());
update_settings_file::<ThemeSettings>(self.fs.clone(), cx, move |settings, _| {
settings.icon_theme = Some(theme_name.to_string());
settings.set_icon_theme(theme_name.to_string(), appearance);
});
self.selector