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
|
@ -35,7 +35,7 @@ use ui::{
|
|||
};
|
||||
use util::paths::PathMatcher;
|
||||
use workspace::{
|
||||
item::{BreadcrumbText, Item, ItemEvent, ItemHandle, TabContentParams},
|
||||
item::{BreadcrumbText, Item, ItemEvent, ItemHandle},
|
||||
searchable::{Direction, SearchableItem, SearchableItemHandle},
|
||||
DeploySearch, ItemNavHistory, NewSearch, ToolbarItemEvent, ToolbarItemLocation,
|
||||
ToolbarItemView, Workspace, WorkspaceId,
|
||||
|
@ -374,7 +374,7 @@ impl Item for ProjectSearchView {
|
|||
Some(Icon::new(IconName::MagnifyingGlass))
|
||||
}
|
||||
|
||||
fn tab_content(&self, params: TabContentParams, cx: &WindowContext<'_>) -> AnyElement {
|
||||
fn tab_content_text(&self, cx: &WindowContext) -> Option<SharedString> {
|
||||
let last_query: Option<SharedString> = self
|
||||
.model
|
||||
.read(cx)
|
||||
|
@ -385,16 +385,11 @@ impl Item for ProjectSearchView {
|
|||
let query_text = util::truncate_and_trailoff(&query, MAX_TAB_TITLE_LEN);
|
||||
query_text.into()
|
||||
});
|
||||
let tab_name = last_query
|
||||
.filter(|query| !query.is_empty())
|
||||
.unwrap_or_else(|| "Project Search".into());
|
||||
Label::new(tab_name)
|
||||
.color(if params.selected {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
})
|
||||
.into_any_element()
|
||||
Some(
|
||||
last_query
|
||||
.filter(|query| !query.is_empty())
|
||||
.unwrap_or_else(|| "Project Search".into()),
|
||||
)
|
||||
}
|
||||
|
||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue