Render other tab icons in the start slot (#14683)

This PR reworks the rendering for tab icons to allow us to render all of
the tab icons—not just file icons—in the tab's start slot.

The `Item` trait now has a separate `tab_icon` method that can be used
to indicate what icon should be shown for the tab.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2024-07-17 16:59:41 -04:00
committed by GitHub
parent 2edf224599
commit 00c3c02f7d
10 changed files with 80 additions and 80 deletions
+15
View File
@@ -5,6 +5,7 @@ use crate::{
};
use anyhow::{anyhow, Context as _, Result};
use collections::HashSet;
use file_icons::FileIcons;
use futures::future::try_join_all;
use git::repository::GitFileStatus;
use gpui::{
@@ -590,6 +591,20 @@ impl Item for Editor {
Some(path.to_string_lossy().to_string().into())
}
fn tab_icon(&self, cx: &WindowContext) -> Option<Icon> {
ItemSettings::get_global(cx)
.file_icons
.then(|| {
self.buffer
.read(cx)
.as_singleton()
.and_then(|buffer| buffer.read(cx).project_path(cx))
.and_then(|path| FileIcons::get_icon(path.path.as_ref(), cx))
})
.flatten()
.map(|icon| Icon::from_path(icon))
}
fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
let label_color = if ItemSettings::get_global(cx).git_status {
self.buffer()