From 3070a6ef2674a912cc6320f48275a2f47581e7c2 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 5 Jan 2024 12:38:42 +0200 Subject: [PATCH] Return back git status colors for tab labels --- crates/editor/src/items.rs | 33 ++++++++++++++++++++++++------- crates/gpui/src/app/entity_map.rs | 7 ++++--- crates/workspace/src/pane.rs | 7 ++++++- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 31c4e24659..9e198fa2fd 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -15,9 +15,11 @@ use language::{ proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, CharKind, OffsetRangeExt, Point, SelectionGoal, }; +use project::repository::GitFileStatus; use project::{search::SearchQuery, FormatTrigger, Item as _, Project, ProjectPath}; use rpc::proto::{self, update_view, PeerId}; use settings::Settings; +use workspace::item::ItemSettings; use std::fmt::Write; use std::{ @@ -29,7 +31,7 @@ use std::{ sync::Arc, }; use text::Selection; -use theme::{ActiveTheme, Theme}; +use theme::Theme; use ui::{h_stack, prelude::*, Label}; use util::{paths::PathExt, paths::FILE_ROW_COLUMN_DELIMITER, ResultExt, TryFutureExt}; use workspace::{ @@ -579,7 +581,28 @@ impl Item for Editor { } fn tab_content(&self, detail: Option, selected: bool, cx: &WindowContext) -> AnyElement { - let _theme = cx.theme(); + let git_status = if ItemSettings::get_global(cx).git_status { + self.buffer() + .read(cx) + .as_singleton() + .and_then(|buffer| buffer.read(cx).project_path(cx)) + .and_then(|path| self.project.as_ref()?.read(cx).entry_for_path(&path, cx)) + .and_then(|entry| entry.git_status()) + } else { + None + }; + let label_color = match git_status { + Some(GitFileStatus::Added) => Color::Created, + Some(GitFileStatus::Modified) => Color::Modified, + Some(GitFileStatus::Conflict) => Color::Conflict, + None => { + if selected { + Color::Default + } else { + Color::Muted + } + } + }; let description = detail.and_then(|detail| { let path = path_for_buffer(&self.buffer, detail, false, cx)?; @@ -595,11 +618,7 @@ impl Item for Editor { h_stack() .gap_2() - .child(Label::new(self.title(cx).to_string()).color(if selected { - Color::Default - } else { - Color::Muted - })) + .child(Label::new(self.title(cx).to_string()).color(label_color)) .when_some(description, |this, description| { this.child( Label::new(description) diff --git a/crates/gpui/src/app/entity_map.rs b/crates/gpui/src/app/entity_map.rs index 3bab9d00f9..97f680560a 100644 --- a/crates/gpui/src/app/entity_map.rs +++ b/crates/gpui/src/app/entity_map.rs @@ -1,8 +1,6 @@ use crate::{private::Sealed, AppContext, Context, Entity, ModelContext}; use anyhow::{anyhow, Result}; -use collections::HashMap; use derive_more::{Deref, DerefMut}; -use lazy_static::lazy_static; use parking_lot::{RwLock, RwLockUpgradableReadGuard}; use slotmap::{SecondaryMap, SlotMap}; use std::{ @@ -18,6 +16,9 @@ use std::{ thread::panicking, }; +#[cfg(any(test, feature = "test-support"))] +use collections::HashMap; + slotmap::new_key_type! { pub struct EntityId; } impl EntityId { @@ -600,7 +601,7 @@ impl PartialEq> for WeakModel { } #[cfg(any(test, feature = "test-support"))] -lazy_static! { +lazy_static::lazy_static! { static ref LEAK_BACKTRACE: bool = std::env::var("LEAK_BACKTRACE").map_or(false, |b| !b.is_empty()); } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 21c5962beb..91e2890adb 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1128,7 +1128,12 @@ impl Pane { if self.items.len() == 1 && should_activate { self.focus_handle.focus(cx); } else { - self.activate_item(index_to_activate, should_activate, should_activate, cx); + self.activate_item( + dbg!(index_to_activate), + dbg!(should_activate), + should_activate, + cx, + ); } }