From a102b3ba4b1acb3d38f48611401e1fd77fc07670 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 13 Sep 2022 14:51:00 +0200 Subject: [PATCH] Start on a real status bar item implementation --- Cargo.lock | 25 +++++++++++++ assets/icons/zed_32.svg | 22 ++++++++++++ crates/contacts_status_item/Cargo.toml | 32 +++++++++++++++++ .../src/contacts_status_item.rs | 36 +++++++++++++++++++ crates/zed/Cargo.toml | 1 + crates/zed/src/main.rs | 4 ++- 6 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 assets/icons/zed_32.svg create mode 100644 crates/contacts_status_item/Cargo.toml create mode 100644 crates/contacts_status_item/src/contacts_status_item.rs diff --git a/Cargo.lock b/Cargo.lock index 7486a62082..05701b7c56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1126,6 +1126,30 @@ dependencies = [ "workspace", ] +[[package]] +name = "contacts_status_item" +version = "0.1.0" +dependencies = [ + "anyhow", + "client", + "collections", + "editor", + "futures", + "fuzzy", + "gpui", + "language", + "log", + "menu", + "picker", + "postage", + "project", + "serde", + "settings", + "theme", + "util", + "workspace", +] + [[package]] name = "context_menu" version = "0.1.0" @@ -7122,6 +7146,7 @@ dependencies = [ "collections", "command_palette", "contacts_panel", + "contacts_status_item", "context_menu", "ctor", "diagnostics", diff --git a/assets/icons/zed_32.svg b/assets/icons/zed_32.svg new file mode 100644 index 0000000000..f8c0c537c3 --- /dev/null +++ b/assets/icons/zed_32.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/crates/contacts_status_item/Cargo.toml b/crates/contacts_status_item/Cargo.toml new file mode 100644 index 0000000000..df115a3842 --- /dev/null +++ b/crates/contacts_status_item/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "contacts_status_item" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/contacts_status_item.rs" +doctest = false + +[dependencies] +client = { path = "../client" } +collections = { path = "../collections" } +editor = { path = "../editor" } +fuzzy = { path = "../fuzzy" } +gpui = { path = "../gpui" } +menu = { path = "../menu" } +picker = { path = "../picker" } +project = { path = "../project" } +settings = { path = "../settings" } +theme = { path = "../theme" } +util = { path = "../util" } +workspace = { path = "../workspace" } +anyhow = "1.0" +futures = "0.3" +log = "0.4" +postage = { version = "0.4.1", features = ["futures-traits"] } +serde = { version = "1.0", features = ["derive", "rc"] } + +[dev-dependencies] +language = { path = "../language", features = ["test-support"] } +project = { path = "../project", features = ["test-support"] } +workspace = { path = "../workspace", features = ["test-support"] } diff --git a/crates/contacts_status_item/src/contacts_status_item.rs b/crates/contacts_status_item/src/contacts_status_item.rs new file mode 100644 index 0000000000..928eecb8fe --- /dev/null +++ b/crates/contacts_status_item/src/contacts_status_item.rs @@ -0,0 +1,36 @@ +use gpui::{color::Color, elements::*, Entity, RenderContext, View}; + +pub struct ContactsStatusItem; + +impl Entity for ContactsStatusItem { + type Event = (); +} + +impl View for ContactsStatusItem { + fn ui_name() -> &'static str { + "ContactsStatusItem" + } + + fn render(&mut self, cx: &mut RenderContext) -> ElementBox { + MouseEventHandler::new::(0, cx, |state, cx| { + Svg::new("icons/zed_32.svg") + .with_color(if state.clicked.is_some() { + Color::red() + } else { + Color::blue() + }) + .boxed() + }) + .on_down(gpui::MouseButton::Left, |_, cx| {}) + .on_up(gpui::MouseButton::Left, |_, cx| {}) + .contained() + .with_background_color(Color::green()) + .boxed() + } +} + +impl ContactsStatusItem { + pub fn new() -> Self { + Self + } +} diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 6d2a617d4c..446139eaaf 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -27,6 +27,7 @@ context_menu = { path = "../context_menu" } client = { path = "../client" } clock = { path = "../clock" } contacts_panel = { path = "../contacts_panel" } +contacts_status_item = { path = "../contacts_status_item" } diagnostics = { path = "../diagnostics" } editor = { path = "../editor" } file_finder = { path = "../file_finder" } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 43a403ab7f..287ac721fd 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -14,6 +14,7 @@ use client::{ http::{self, HttpClient}, UserStore, ZED_SECRET_CLIENT_TOKEN, }; +use contacts_status_item::ContactsStatusItem; use fs::OpenOptions; use futures::{ channel::{mpsc, oneshot}, @@ -87,7 +88,8 @@ fn main() { }); app.run(move |cx| { - std::mem::forget(cx.platform().add_status_item()); + cx.add_status_bar_item(|_| ContactsStatusItem::new()); + let client = client::Client::new(http.clone()); let mut languages = LanguageRegistry::new(login_shell_env_loaded); languages.set_language_server_download_dir(zed::paths::LANGUAGES_DIR.clone());