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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 80 additions and 80 deletions

View file

@ -10,7 +10,6 @@ use crate::{
};
use anyhow::Result;
use collections::{BTreeSet, HashMap, HashSet, VecDeque};
use file_icons::FileIcons;
use futures::{stream::FuturesUnordered, StreamExt};
use gpui::{
actions, anchored, deferred, impl_actions, prelude::*, Action, AnchorCorner, AnyElement,
@ -1590,6 +1589,7 @@ impl Pane {
},
cx,
);
let icon = item.tab_icon(cx);
let close_side = &ItemSettings::get_global(cx).close_position;
let indicator = render_item_indicator(item.boxed_clone(), cx);
let item_id = item.item_id();
@ -1597,14 +1597,6 @@ impl Pane {
let is_last_item = ix == self.items.len() - 1;
let position_relative_to_active_item = ix.cmp(&self.active_item_index);
let file_icon = ItemSettings::get_global(cx)
.file_icons
.then(|| {
item.project_path(cx)
.and_then(|path| FileIcons::get_icon(path.path.as_ref(), cx))
})
.flatten();
let tab = Tab::new(ix)
.position(if is_first_item {
TabPosition::First
@ -1675,14 +1667,12 @@ impl Pane {
})
.map(|tab| match indicator {
Some(indicator) => tab.start_slot(indicator),
None => tab.start_slot::<Icon>(file_icon.map(|icon| {
Icon::from_path(icon.to_string())
.size(IconSize::XSmall)
.color(if is_active {
Color::Default
} else {
Color::Muted
})
None => tab.start_slot::<Icon>(icon.map(|icon| {
icon.size(IconSize::XSmall).color(if is_active {
Color::Default
} else {
Color::Muted
})
})),
})
.end_slot(