From 103f757c114c2712df5f98f05bb64ff1ff9ef2d0 Mon Sep 17 00:00:00 2001 From: Daste Date: Tue, 17 Sep 2024 14:48:05 +0200 Subject: [PATCH] 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) --- crates/diagnostics/src/diagnostics.rs | 59 ++++++++++++----------- crates/tab_switcher/src/tab_switcher.rs | 3 ++ crates/terminal_view/src/terminal_view.rs | 2 +- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index ddf39e0bfa..eec4f735ec 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -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> { diff --git a/crates/tab_switcher/src/tab_switcher.rs b/crates/tab_switcher/src/tab_switcher.rs index e8966ac5b9..0b3eaf9e8a 100644 --- a/crates/tab_switcher/src/tab_switcher.rs +++ b/crates/tab_switcher/src/tab_switcher.rs @@ -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::(close_button) diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 1869e33383..f19bfa7010 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -1008,7 +1008,7 @@ impl Item for TerminalView { }; h_flex() - .gap_2() + .gap_1() .group("term-tab-icon") .child( h_flex()