Add icon theme selector (#23976)
This PR adds an icon theme selector for switching between icon themes: https://github.com/user-attachments/assets/2cdc7ab7-d9f4-4968-a2e9-724e8ad4ef4d Release Notes: - N/A
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
mod icon_theme_selector;
|
||||
|
||||
use fs::Fs;
|
||||
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
||||
use gpui::{
|
||||
@@ -11,22 +13,25 @@ use theme::{Appearance, Theme, ThemeMeta, ThemeRegistry, ThemeSettings};
|
||||
use ui::{prelude::*, v_flex, ListItem, ListItemSpacing};
|
||||
use util::ResultExt;
|
||||
use workspace::{ui::HighlightedLabel, ModalView, Workspace};
|
||||
use zed_actions::theme_selector::Toggle;
|
||||
|
||||
use crate::icon_theme_selector::{IconThemeSelector, IconThemeSelectorDelegate};
|
||||
|
||||
actions!(theme_selector, [Reload]);
|
||||
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.observe_new(
|
||||
|workspace: &mut Workspace, _window, _cx: &mut Context<Workspace>| {
|
||||
workspace.register_action(toggle);
|
||||
workspace
|
||||
.register_action(toggle_theme_selector)
|
||||
.register_action(toggle_icon_theme_selector);
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
}
|
||||
|
||||
pub fn toggle(
|
||||
fn toggle_theme_selector(
|
||||
workspace: &mut Workspace,
|
||||
toggle: &Toggle,
|
||||
toggle: &zed_actions::theme_selector::Toggle,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
@@ -42,9 +47,27 @@ pub fn toggle(
|
||||
});
|
||||
}
|
||||
|
||||
fn toggle_icon_theme_selector(
|
||||
workspace: &mut Workspace,
|
||||
toggle: &zed_actions::icon_theme_selector::Toggle,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
let fs = workspace.app_state().fs.clone();
|
||||
workspace.toggle_modal(window, cx, |window, cx| {
|
||||
let delegate = IconThemeSelectorDelegate::new(
|
||||
cx.entity().downgrade(),
|
||||
fs,
|
||||
toggle.themes_filter.as_ref(),
|
||||
cx,
|
||||
);
|
||||
IconThemeSelector::new(delegate, window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
impl ModalView for ThemeSelector {}
|
||||
|
||||
pub struct ThemeSelector {
|
||||
struct ThemeSelector {
|
||||
picker: Entity<Picker<ThemeSelectorDelegate>>,
|
||||
}
|
||||
|
||||
@@ -73,7 +96,7 @@ impl ThemeSelector {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ThemeSelectorDelegate {
|
||||
struct ThemeSelectorDelegate {
|
||||
fs: Arc<dyn Fs>,
|
||||
themes: Vec<ThemeMeta>,
|
||||
matches: Vec<StringMatch>,
|
||||
|
||||
Reference in New Issue
Block a user