Start on a real status bar item implementation

Antonio Scandurra created

Change summary

Cargo.lock                                              | 25 +++++++
assets/icons/zed_32.svg                                 | 22 ++++++
crates/contacts_status_item/Cargo.toml                  | 32 +++++++++
crates/contacts_status_item/src/contacts_status_item.rs | 36 +++++++++++
crates/zed/Cargo.toml                                   |  1 
crates/zed/src/main.rs                                  |  4 
6 files changed, 119 insertions(+), 1 deletion(-)

Detailed changes

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",

assets/icons/zed_32.svg 🔗

@@ -0,0 +1,22 @@
+<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g clip-path="url(#clip0_203_783)">
+<g filter="url(#filter0_d_203_783)">
+<rect x="3.33984" y="3.33984" width="25.3203" height="25.3203" rx="12.6602" fill="#FEFEFE" stroke="#0E1016" stroke-width="3.61719"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M10.5742 10.5742L22.7822 10.5742L14.9827 18.7129H18.7129L21.4258 21.4258H9.21777L17.0173 13.2871H13.2871L10.5742 10.5742Z" fill="#0E1016"/>
+</g>
+</g>
+<defs>
+<filter id="filter0_d_203_783" x="1.18007" y="1.53125" width="29.6399" height="29.6399" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
+<feFlood flood-opacity="0" result="BackgroundImageFix"/>
+<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
+<feOffset dy="0.351183"/>
+<feGaussianBlur stdDeviation="0.175592"/>
+<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0"/>
+<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_203_783"/>
+<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_203_783" result="shape"/>
+</filter>
+<clipPath id="clip0_203_783">
+<rect width="32" height="32" fill="white"/>
+</clipPath>
+</defs>
+</svg>

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"] }

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<Self>) -> ElementBox {
+        MouseEventHandler::new::<Self, _, _>(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
+    }
+}

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" }

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());