Simplify constructing tab content that is purely textual (#14695)
This PR adds a streamlined way to consistently construct tab content for items that only have textual content in the tabs. The `Item` trait now has a new `tab_content_text` method that can be used to return the textual content for the tab. The `tab_content` method now has a default implementation that—unless overridden—will construct a `Label` out of the text. This default implementation also takes care of setting the label color based on the active state of the tab, something that previously had to be repeated in each `tab_content` implementation. The majority of our tabs are now using `tab_content_text`. Release Notes: - N/A
This commit is contained in:
parent
ca2976559e
commit
2c8ead4423
11 changed files with 77 additions and 124 deletions
|
@ -6,13 +6,13 @@ use anyhow::Result;
|
|||
use editor::scroll::{Autoscroll, AutoscrollStrategy};
|
||||
use editor::{Editor, EditorEvent};
|
||||
use gpui::{
|
||||
list, AnyElement, AppContext, ClickEvent, EventEmitter, FocusHandle, FocusableView,
|
||||
InteractiveElement, IntoElement, ListState, ParentElement, Render, Styled, Subscription, Task,
|
||||
View, ViewContext, WeakView,
|
||||
list, AppContext, ClickEvent, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
|
||||
IntoElement, ListState, ParentElement, Render, Styled, Subscription, Task, View, ViewContext,
|
||||
WeakView,
|
||||
};
|
||||
use language::LanguageRegistry;
|
||||
use ui::prelude::*;
|
||||
use workspace::item::{Item, ItemHandle, TabContentParams};
|
||||
use workspace::item::{Item, ItemHandle};
|
||||
use workspace::{Pane, Workspace};
|
||||
|
||||
use crate::markdown_elements::ParsedMarkdownElement;
|
||||
|
@ -456,18 +456,12 @@ impl Item for MarkdownPreviewView {
|
|||
Some(Icon::new(IconName::FileDoc))
|
||||
}
|
||||
|
||||
fn tab_content(&self, params: TabContentParams, _cx: &WindowContext) -> AnyElement {
|
||||
Label::new(if let Some(description) = &self.tab_description {
|
||||
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||
Some(if let Some(description) = &self.tab_description {
|
||||
description.clone().into()
|
||||
} else {
|
||||
self.fallback_tab_description.clone()
|
||||
})
|
||||
.color(if params.selected {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
})
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue