Fix git colors in image tabs (#21773)

Note that the git coloring of the icons got removed in
https://github.com/zed-industries/zed/pull/21383

Closes #21772

Release Notes:

- N/A
This commit is contained in:
Nils Koch 2024-12-10 08:40:25 +00:00 committed by GitHub
parent 44164dbbb8
commit bd2087675b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

1
Cargo.lock generated
View file

@ -6171,6 +6171,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"db", "db",
"editor",
"file_icons", "file_icons",
"gpui", "gpui",
"project", "project",

View file

@ -15,6 +15,7 @@ doctest = false
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true
db.workspace = true db.workspace = true
editor.workspace = true
file_icons.workspace = true file_icons.workspace = true
gpui.workspace = true gpui.workspace = true
project.workspace = true project.workspace = true

View file

@ -1,6 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use anyhow::Context as _; use anyhow::Context as _;
use editor::items::entry_git_aware_label_color;
use gpui::{ use gpui::{
canvas, div, fill, img, opaque_grey, point, size, AnyElement, AppContext, Bounds, EventEmitter, canvas, div, fill, img, opaque_grey, point, size, AnyElement, AppContext, Bounds, EventEmitter,
FocusHandle, FocusableView, InteractiveElement, IntoElement, Model, ObjectFit, ParentElement, FocusHandle, FocusableView, InteractiveElement, IntoElement, Model, ObjectFit, ParentElement,
@ -94,15 +95,28 @@ impl Item for ImageView {
} }
fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement { fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
let path = self.image_item.read(cx).file.path(); let project_path = self.image_item.read(cx).project_path(cx);
let title = path let label_color = if ItemSettings::get_global(cx).git_status {
self.project
.read(cx)
.entry_for_path(&project_path, cx)
.map(|entry| {
entry_git_aware_label_color(entry.git_status, entry.is_ignored, params.selected)
})
.unwrap_or_else(|| params.text_color())
} else {
params.text_color()
};
let title = project_path
.path
.file_name() .file_name()
.unwrap_or_else(|| path.as_os_str()) .unwrap_or_else(|| project_path.path.as_os_str())
.to_string_lossy() .to_string_lossy()
.to_string(); .to_string();
Label::new(title) Label::new(title)
.single_line() .single_line()
.color(params.text_color()) .color(label_color)
.italic(params.preview) .italic(params.preview)
.into_any_element() .into_any_element()
} }