diff --git a/Cargo.lock b/Cargo.lock index fa8d33c425..0fc4f660e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5326,6 +5326,21 @@ dependencies = [ "toml 0.5.8", ] +[[package]] +name = "theme_selector" +version = "0.1.0" +dependencies = [ + "editor", + "fuzzy", + "gpui", + "log", + "parking_lot", + "postage", + "smol", + "theme", + "workspace", +] + [[package]] name = "thiserror" version = "1.0.29" @@ -6183,6 +6198,7 @@ dependencies = [ "surf", "tempdir", "theme", + "theme_selector", "thiserror", "time 0.3.2", "tiny_http", diff --git a/crates/theme_selector/Cargo.toml b/crates/theme_selector/Cargo.toml new file mode 100644 index 0000000000..e4ef6d768d --- /dev/null +++ b/crates/theme_selector/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "theme_selector" +version = "0.1.0" +edition = "2018" + +[dependencies] +editor = { path = "../editor" } +fuzzy = { path = "../fuzzy" } +gpui = { path = "../gpui" } +theme = { path = "../theme" } +workspace = { path = "../workspace" } +log = "0.4" +parking_lot = "0.11.1" +postage = { version = "0.4.1", features = ["futures-traits"] } +smol = "1.2.5" diff --git a/crates/zed/src/theme_selector.rs b/crates/theme_selector/src/lib.rs similarity index 92% rename from crates/zed/src/theme_selector.rs rename to crates/theme_selector/src/lib.rs index 963e35d0d2..18f29b4393 100644 --- a/crates/zed/src/theme_selector.rs +++ b/crates/theme_selector/src/lib.rs @@ -1,4 +1,3 @@ -use crate::{workspace::Workspace, AppState, Settings}; use editor::{Editor, EditorSettings}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use gpui::{ @@ -12,11 +11,19 @@ use parking_lot::Mutex; use postage::watch; use std::{cmp, sync::Arc}; use theme::ThemeRegistry; +use workspace::{Settings, Workspace}; + +#[derive(Clone)] +pub struct ThemeSelectorParams { + pub settings_tx: Arc>>, + pub settings: watch::Receiver, + pub themes: Arc, +} pub struct ThemeSelector { settings_tx: Arc>>, settings: watch::Receiver, - registry: Arc, + themes: Arc, matches: Vec, query_editor: ViewHandle, list_state: UniformListState, @@ -24,10 +31,10 @@ pub struct ThemeSelector { } action!(Confirm); -action!(Toggle, Arc); -action!(Reload, Arc); +action!(Toggle, ThemeSelectorParams); +action!(Reload, ThemeSelectorParams); -pub fn init(app_state: &Arc, cx: &mut MutableAppContext) { +pub fn init(params: ThemeSelectorParams, cx: &mut MutableAppContext) { cx.add_action(ThemeSelector::confirm); cx.add_action(ThemeSelector::select_prev); cx.add_action(ThemeSelector::select_next); @@ -35,9 +42,9 @@ pub fn init(app_state: &Arc, cx: &mut MutableAppContext) { cx.add_action(ThemeSelector::reload); cx.add_bindings(vec![ - Binding::new("cmd-k cmd-t", Toggle(app_state.clone()), None), - Binding::new("cmd-k t", Reload(app_state.clone()), None), - Binding::new("escape", Toggle(app_state.clone()), Some("ThemeSelector")), + Binding::new("cmd-k cmd-t", Toggle(params.clone()), None), + Binding::new("cmd-k t", Reload(params.clone()), None), + Binding::new("escape", Toggle(params.clone()), Some("ThemeSelector")), Binding::new("enter", Confirm, Some("ThemeSelector")), ]); } @@ -75,7 +82,7 @@ impl ThemeSelector { let mut this = Self { settings, settings_tx, - registry, + themes: registry, query_editor, matches: Vec::new(), list_state: Default::default(), @@ -117,7 +124,7 @@ impl ThemeSelector { fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext) { if let Some(mat) = self.matches.get(self.selected_index) { - match self.registry.get(&mat.string) { + match self.themes.get(&mat.string) { Ok(theme) => { self.settings_tx.lock().borrow_mut().theme = theme; cx.refresh_windows(); @@ -144,15 +151,10 @@ impl ThemeSelector { cx.notify(); } - // fn select(&mut self, selected_index: &usize, cx: &mut ViewContext) { - // self.selected_index = *selected_index; - // self.confirm(&(), cx); - // } - fn update_matches(&mut self, cx: &mut ViewContext) { let background = cx.background().clone(); let candidates = self - .registry + .themes .list() .map(|name| StringMatchCandidate { char_bag: name.as_str().into(), diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index d3f41cbb15..d6695709f0 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -39,6 +39,7 @@ project_panel = { path = "../project_panel" } rpc = { path = "../rpc" } sum_tree = { path = "../sum_tree" } theme = { path = "../theme" } +theme_selector = { path = "../theme_selector" } util = { path = "../util" } workspace = { path = "../workspace" } anyhow = "1.0.38" diff --git a/crates/zed/src/lib.rs b/crates/zed/src/lib.rs index 93ca505cdc..f8711c7175 100644 --- a/crates/zed/src/lib.rs +++ b/crates/zed/src/lib.rs @@ -3,7 +3,6 @@ pub mod language; pub mod menus; #[cfg(any(test, feature = "test-support"))] pub mod test; -pub mod theme_selector; pub use buffer; use buffer::LanguageRegistry; @@ -25,6 +24,7 @@ pub use project::{self, fs}; use project_panel::ProjectPanel; use std::{path::PathBuf, sync::Arc}; use theme::ThemeRegistry; +use theme_selector::ThemeSelectorParams; pub use workspace; use workspace::{Settings, Workspace, WorkspaceParams}; @@ -188,6 +188,16 @@ impl<'a> From<&'a AppState> for WorkspaceParams { } } +impl<'a> From<&'a AppState> for ThemeSelectorParams { + fn from(state: &'a AppState) -> Self { + Self { + settings_tx: state.settings_tx.clone(), + settings: state.settings.clone(), + themes: state.themes.clone(), + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 837fe7b645..d2357ea3c3 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -10,10 +10,7 @@ use simplelog::SimpleLogger; use std::{fs, path::PathBuf, sync::Arc}; use theme::ThemeRegistry; use workspace::{self, settings, OpenNew}; -use zed::{ - self, assets::Assets, fs::RealFs, language, menus, theme_selector, AppState, OpenParams, - OpenPaths, -}; +use zed::{self, assets::Assets, fs::RealFs, language, menus, AppState, OpenParams, OpenPaths}; fn main() { init_logger(); @@ -56,7 +53,7 @@ fn main() { people_panel::init(cx); chat_panel::init(cx); project_panel::init(cx); - theme_selector::init(&app_state, cx); + theme_selector::init(app_state.as_ref().into(), cx); cx.set_menus(menus::menus(&app_state.clone()));