tab_switcher: Add file and project search icons (#17115)

I found tab switcher file icons to be missing. They were mentioned in
the [initial tab switcher
issue](https://github.com/zed-industries/zed/issues/7653), but left to
be added later (mentioned in
https://github.com/zed-industries/zed/pull/7987).

I also noticed that the project search icon went missing, but I'm not
sure if that's intentional. These changes re-introduce it, as it's
provided by the generic `tab_icon()` function.

There's a small difference between the terminal item and everything
else, because terminal's `tab_content` returns a slightly different
layout, which adds a little more space between the icon and text. I'll
look into resolving this withouth changing too much stuff around in the
terminal crate. If you have any ideas on how to do this well, please
comment.

The new `tab_switcher` config section only has a single boolean option -
`show_icons`. It toggles between icons and not icons, but doesn't
disable the terminal icon. Implementing this would probably also require
some refactoring in terminal's `tab_content` function.

Release Notes:

- Added file icons to the tab switcher

Screenshot:

![image](https://github.com/user-attachments/assets/17f3f4a3-1f95-4830-aef1-cda280726385)
This commit is contained in:
Daste 2024-09-17 14:48:05 +02:00 committed by GitHub
parent 2165d52d3e
commit 103f757c11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 28 deletions

View File

@ -645,37 +645,42 @@ impl Item for ProjectDiagnosticsEditor {
}
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
if self.summary.error_count == 0 && self.summary.warning_count == 0 {
Label::new("No problems")
.color(params.text_color())
.into_any_element()
} else {
h_flex()
.gap_1()
.when(self.summary.error_count > 0, |then| {
h_flex()
.gap_1()
.when(
self.summary.error_count == 0 && self.summary.warning_count == 0,
|then| {
then.child(
h_flex()
.gap_1()
.child(Icon::new(IconName::XCircle).color(Color::Error))
.child(
Label::new(self.summary.error_count.to_string())
.color(params.text_color()),
),
.child(Icon::new(IconName::Check).color(Color::Success))
.child(Label::new("No problems").color(params.text_color())),
)
})
.when(self.summary.warning_count > 0, |then| {
then.child(
h_flex()
.gap_1()
.child(Icon::new(IconName::Warning).color(Color::Warning))
.child(
Label::new(self.summary.warning_count.to_string())
.color(params.text_color()),
),
)
})
.into_any_element()
}
},
)
.when(self.summary.error_count > 0, |then| {
then.child(
h_flex()
.gap_1()
.child(Icon::new(IconName::XCircle).color(Color::Error))
.child(
Label::new(self.summary.error_count.to_string())
.color(params.text_color()),
),
)
})
.when(self.summary.warning_count > 0, |then| {
then.child(
h_flex()
.gap_1()
.child(Icon::new(IconName::Warning).color(Color::Warning))
.child(
Label::new(self.summary.warning_count.to_string())
.color(params.text_color()),
),
)
})
.into_any_element()
}
fn telemetry_event_text(&self) -> Option<&'static str> {

View File

@ -378,6 +378,9 @@ impl PickerDelegate for TabSwitcherDelegate {
.inset(true)
.selected(selected)
.child(h_flex().w_full().child(label))
.when_some(tab_match.item.tab_icon(cx), |el, icon| {
el.start_slot(div().child(icon))
})
.map(|el| {
if self.selected_index == ix {
el.end_slot::<AnyElement>(close_button)

View File

@ -1008,7 +1008,7 @@ impl Item for TerminalView {
};
h_flex()
.gap_2()
.gap_1()
.group("term-tab-icon")
.child(
h_flex()