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
|
@ -3,9 +3,9 @@ use copilot::Copilot;
|
|||
use editor::{actions::MoveToEnd, Editor, EditorEvent};
|
||||
use futures::{channel::mpsc, StreamExt};
|
||||
use gpui::{
|
||||
actions, div, AnchorCorner, AnyElement, AppContext, Context, EventEmitter, FocusHandle,
|
||||
FocusableView, IntoElement, Model, ModelContext, ParentElement, Render, Styled, Subscription,
|
||||
View, ViewContext, VisualContext, WeakModel, WindowContext,
|
||||
actions, div, AnchorCorner, AppContext, Context, EventEmitter, FocusHandle, FocusableView,
|
||||
IntoElement, Model, ModelContext, ParentElement, Render, Styled, Subscription, View,
|
||||
ViewContext, VisualContext, WeakModel, WindowContext,
|
||||
};
|
||||
use language::{LanguageServerId, LanguageServerName};
|
||||
use lsp::{IoKind, LanguageServer};
|
||||
|
@ -13,7 +13,7 @@ use project::{search::SearchQuery, Project};
|
|||
use std::{borrow::Cow, sync::Arc};
|
||||
use ui::{prelude::*, Button, Checkbox, ContextMenu, Label, PopoverMenu, Selection};
|
||||
use workspace::{
|
||||
item::{Item, ItemHandle, TabContentParams},
|
||||
item::{Item, ItemHandle},
|
||||
searchable::{SearchEvent, SearchableItem, SearchableItemHandle},
|
||||
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||
};
|
||||
|
@ -697,14 +697,8 @@ impl Item for LspLogView {
|
|||
Editor::to_item_events(event, f)
|
||||
}
|
||||
|
||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext<'_>) -> AnyElement {
|
||||
Label::new("LSP Logs")
|
||||
.color(if params.selected {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
})
|
||||
.into_any_element()
|
||||
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||
Some("LSP Logs".into())
|
||||
}
|
||||
|
||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use editor::{scroll::Autoscroll, Anchor, Editor, ExcerptId};
|
||||
use gpui::{
|
||||
actions, div, rems, uniform_list, AnyElement, AppContext, Div, EventEmitter, FocusHandle,
|
||||
FocusableView, Hsla, InteractiveElement, IntoElement, Model, MouseButton, MouseDownEvent,
|
||||
MouseMoveEvent, ParentElement, Render, Styled, UniformListScrollHandle, View, ViewContext,
|
||||
actions, div, rems, uniform_list, AppContext, Div, EventEmitter, FocusHandle, FocusableView,
|
||||
Hsla, InteractiveElement, IntoElement, Model, MouseButton, MouseDownEvent, MouseMoveEvent,
|
||||
ParentElement, Render, SharedString, Styled, UniformListScrollHandle, View, ViewContext,
|
||||
VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use language::{Buffer, OwnedSyntaxLayer};
|
||||
|
@ -11,7 +11,7 @@ use theme::ActiveTheme;
|
|||
use tree_sitter::{Node, TreeCursor};
|
||||
use ui::{h_flex, ButtonLike, Color, ContextMenu, Label, LabelCommon, PopoverMenu};
|
||||
use workspace::{
|
||||
item::{Item, ItemHandle, TabContentParams},
|
||||
item::{Item, ItemHandle},
|
||||
SplitDirection, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||
};
|
||||
|
||||
|
@ -380,14 +380,8 @@ impl Item for SyntaxTreeView {
|
|||
|
||||
fn to_item_events(_: &Self::Event, _: impl FnMut(workspace::item::ItemEvent)) {}
|
||||
|
||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext<'_>) -> AnyElement {
|
||||
Label::new("Syntax Tree")
|
||||
.color(if params.selected {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
})
|
||||
.into_any_element()
|
||||
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||
Some("Syntax Tree".into())
|
||||
}
|
||||
|
||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue