mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-16 00:47:39 +03:00
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
@ -2023,18 +2023,8 @@ impl FocusableView for ContextEditor {
|
|||||||
impl Item for ContextEditor {
|
impl Item for ContextEditor {
|
||||||
type Event = editor::EditorEvent;
|
type Event = editor::EditorEvent;
|
||||||
|
|
||||||
fn tab_content(&self, params: item::TabContentParams, cx: &WindowContext) -> AnyElement {
|
fn tab_content_text(&self, cx: &WindowContext) -> Option<SharedString> {
|
||||||
let color = if params.selected {
|
Some(util::truncate_and_trailoff(&self.title(cx), Self::MAX_TAB_TITLE_LEN).into())
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
};
|
|
||||||
Label::new(util::truncate_and_trailoff(
|
|
||||||
&self.title(cx),
|
|
||||||
Self::MAX_TAB_TITLE_LEN,
|
|
||||||
))
|
|
||||||
.color(color)
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_item_events(event: &Self::Event, mut f: impl FnMut(item::ItemEvent)) {
|
fn to_item_events(event: &Self::Event, mut f: impl FnMut(item::ItemEvent)) {
|
||||||
@ -2531,13 +2521,8 @@ impl EventEmitter<()> for ContextHistory {}
|
|||||||
impl Item for ContextHistory {
|
impl Item for ContextHistory {
|
||||||
type Event = ();
|
type Event = ();
|
||||||
|
|
||||||
fn tab_content(&self, params: item::TabContentParams, _: &WindowContext) -> AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
let color = if params.selected {
|
Some("History".into())
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
};
|
|
||||||
Label::new("History").color(color).into_any_element()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,20 +11,20 @@ use editor::{
|
|||||||
EditorEvent,
|
EditorEvent,
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, AnyElement, AnyView, AppContext, ClipboardItem, Entity as _, EventEmitter,
|
actions, AnyView, AppContext, ClipboardItem, Entity as _, EventEmitter, FocusableView, Model,
|
||||||
FocusableView, IntoElement as _, Model, Pixels, Point, Render, Subscription, Task, View,
|
Pixels, Point, Render, Subscription, Task, View, ViewContext, VisualContext as _, WeakView,
|
||||||
ViewContext, VisualContext as _, WeakView, WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use std::{
|
use std::{
|
||||||
any::{Any, TypeId},
|
any::{Any, TypeId},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use ui::{prelude::*, Label};
|
use ui::prelude::*;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::{item::Dedup, notifications::NotificationId};
|
use workspace::{item::Dedup, notifications::NotificationId};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{FollowableItem, Item, ItemEvent, ItemHandle, TabContentParams},
|
item::{FollowableItem, Item, ItemEvent, ItemHandle},
|
||||||
searchable::SearchableItemHandle,
|
searchable::SearchableItemHandle,
|
||||||
ItemNavHistory, Pane, SaveIntent, Toast, ViewId, Workspace, WorkspaceId,
|
ItemNavHistory, Pane, SaveIntent, Toast, ViewId, Workspace, WorkspaceId,
|
||||||
};
|
};
|
||||||
@ -385,7 +385,7 @@ impl Item for ChannelView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
|
fn tab_content_text(&self, cx: &WindowContext) -> Option<SharedString> {
|
||||||
let label = if let Some(channel) = self.channel(cx) {
|
let label = if let Some(channel) = self.channel(cx) {
|
||||||
match (
|
match (
|
||||||
self.channel_buffer.read(cx).buffer().read(cx).read_only(),
|
self.channel_buffer.read(cx).buffer().read(cx).read_only(),
|
||||||
@ -398,13 +398,7 @@ impl Item for ChannelView {
|
|||||||
} else {
|
} else {
|
||||||
"channel notes (disconnected)".to_string()
|
"channel notes (disconnected)".to_string()
|
||||||
};
|
};
|
||||||
Label::new(label)
|
Some(label.into())
|
||||||
.color(if params.selected {
|
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
@ -14,7 +14,7 @@ use editor::{Editor, EditorElement, EditorStyle};
|
|||||||
use extension::{ExtensionManifest, ExtensionOperation, ExtensionStore};
|
use extension::{ExtensionManifest, ExtensionOperation, ExtensionStore};
|
||||||
use fuzzy::{match_strings, StringMatchCandidate};
|
use fuzzy::{match_strings, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, uniform_list, AnyElement, AppContext, EventEmitter, Flatten, FocusableView, FontStyle,
|
actions, uniform_list, AppContext, EventEmitter, Flatten, FocusableView, FontStyle,
|
||||||
InteractiveElement, KeyContext, ParentElement, Render, Styled, Task, TextStyle,
|
InteractiveElement, KeyContext, ParentElement, Render, Styled, Task, TextStyle,
|
||||||
UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,
|
UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,
|
||||||
};
|
};
|
||||||
@ -25,7 +25,6 @@ use settings::Settings;
|
|||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::{prelude::*, CheckboxWithLabel, ContextMenu, PopoverMenu, ToggleButton, Tooltip};
|
use ui::{prelude::*, CheckboxWithLabel, ContextMenu, PopoverMenu, ToggleButton, Tooltip};
|
||||||
use vim::VimModeSetting;
|
use vim::VimModeSetting;
|
||||||
use workspace::item::TabContentParams;
|
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{Item, ItemEvent},
|
item::{Item, ItemEvent},
|
||||||
Workspace, WorkspaceId,
|
Workspace, WorkspaceId,
|
||||||
@ -1135,14 +1134,8 @@ impl FocusableView for ExtensionsPage {
|
|||||||
impl Item for ExtensionsPage {
|
impl Item for ExtensionsPage {
|
||||||
type Event = ItemEvent;
|
type Event = ItemEvent;
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
Label::new("Extensions")
|
Some("Extensions".into())
|
||||||
.color(if params.selected {
|
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
@ -3,9 +3,9 @@ use copilot::Copilot;
|
|||||||
use editor::{actions::MoveToEnd, Editor, EditorEvent};
|
use editor::{actions::MoveToEnd, Editor, EditorEvent};
|
||||||
use futures::{channel::mpsc, StreamExt};
|
use futures::{channel::mpsc, StreamExt};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, AnchorCorner, AnyElement, AppContext, Context, EventEmitter, FocusHandle,
|
actions, div, AnchorCorner, AppContext, Context, EventEmitter, FocusHandle, FocusableView,
|
||||||
FocusableView, IntoElement, Model, ModelContext, ParentElement, Render, Styled, Subscription,
|
IntoElement, Model, ModelContext, ParentElement, Render, Styled, Subscription, View,
|
||||||
View, ViewContext, VisualContext, WeakModel, WindowContext,
|
ViewContext, VisualContext, WeakModel, WindowContext,
|
||||||
};
|
};
|
||||||
use language::{LanguageServerId, LanguageServerName};
|
use language::{LanguageServerId, LanguageServerName};
|
||||||
use lsp::{IoKind, LanguageServer};
|
use lsp::{IoKind, LanguageServer};
|
||||||
@ -13,7 +13,7 @@ use project::{search::SearchQuery, Project};
|
|||||||
use std::{borrow::Cow, sync::Arc};
|
use std::{borrow::Cow, sync::Arc};
|
||||||
use ui::{prelude::*, Button, Checkbox, ContextMenu, Label, PopoverMenu, Selection};
|
use ui::{prelude::*, Button, Checkbox, ContextMenu, Label, PopoverMenu, Selection};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{Item, ItemHandle, TabContentParams},
|
item::{Item, ItemHandle},
|
||||||
searchable::{SearchEvent, SearchableItem, SearchableItemHandle},
|
searchable::{SearchEvent, SearchableItem, SearchableItemHandle},
|
||||||
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||||
};
|
};
|
||||||
@ -697,14 +697,8 @@ impl Item for LspLogView {
|
|||||||
Editor::to_item_events(event, f)
|
Editor::to_item_events(event, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext<'_>) -> AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
Label::new("LSP Logs")
|
Some("LSP Logs".into())
|
||||||
.color(if params.selected {
|
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use editor::{scroll::Autoscroll, Anchor, Editor, ExcerptId};
|
use editor::{scroll::Autoscroll, Anchor, Editor, ExcerptId};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, rems, uniform_list, AnyElement, AppContext, Div, EventEmitter, FocusHandle,
|
actions, div, rems, uniform_list, AppContext, Div, EventEmitter, FocusHandle, FocusableView,
|
||||||
FocusableView, Hsla, InteractiveElement, IntoElement, Model, MouseButton, MouseDownEvent,
|
Hsla, InteractiveElement, IntoElement, Model, MouseButton, MouseDownEvent, MouseMoveEvent,
|
||||||
MouseMoveEvent, ParentElement, Render, Styled, UniformListScrollHandle, View, ViewContext,
|
ParentElement, Render, SharedString, Styled, UniformListScrollHandle, View, ViewContext,
|
||||||
VisualContext, WeakView, WindowContext,
|
VisualContext, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use language::{Buffer, OwnedSyntaxLayer};
|
use language::{Buffer, OwnedSyntaxLayer};
|
||||||
@ -11,7 +11,7 @@ use theme::ActiveTheme;
|
|||||||
use tree_sitter::{Node, TreeCursor};
|
use tree_sitter::{Node, TreeCursor};
|
||||||
use ui::{h_flex, ButtonLike, Color, ContextMenu, Label, LabelCommon, PopoverMenu};
|
use ui::{h_flex, ButtonLike, Color, ContextMenu, Label, LabelCommon, PopoverMenu};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{Item, ItemHandle, TabContentParams},
|
item::{Item, ItemHandle},
|
||||||
SplitDirection, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
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 to_item_events(_: &Self::Event, _: impl FnMut(workspace::item::ItemEvent)) {}
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext<'_>) -> AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
Label::new("Syntax Tree")
|
Some("Syntax Tree".into())
|
||||||
.color(if params.selected {
|
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
@ -6,13 +6,13 @@ use anyhow::Result;
|
|||||||
use editor::scroll::{Autoscroll, AutoscrollStrategy};
|
use editor::scroll::{Autoscroll, AutoscrollStrategy};
|
||||||
use editor::{Editor, EditorEvent};
|
use editor::{Editor, EditorEvent};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
list, AnyElement, AppContext, ClickEvent, EventEmitter, FocusHandle, FocusableView,
|
list, AppContext, ClickEvent, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
|
||||||
InteractiveElement, IntoElement, ListState, ParentElement, Render, Styled, Subscription, Task,
|
IntoElement, ListState, ParentElement, Render, Styled, Subscription, Task, View, ViewContext,
|
||||||
View, ViewContext, WeakView,
|
WeakView,
|
||||||
};
|
};
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
use ui::prelude::*;
|
use ui::prelude::*;
|
||||||
use workspace::item::{Item, ItemHandle, TabContentParams};
|
use workspace::item::{Item, ItemHandle};
|
||||||
use workspace::{Pane, Workspace};
|
use workspace::{Pane, Workspace};
|
||||||
|
|
||||||
use crate::markdown_elements::ParsedMarkdownElement;
|
use crate::markdown_elements::ParsedMarkdownElement;
|
||||||
@ -456,18 +456,12 @@ impl Item for MarkdownPreviewView {
|
|||||||
Some(Icon::new(IconName::FileDoc))
|
Some(Icon::new(IconName::FileDoc))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, _cx: &WindowContext) -> AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
Label::new(if let Some(description) = &self.tab_description {
|
Some(if let Some(description) = &self.tab_description {
|
||||||
description.clone().into()
|
description.clone().into()
|
||||||
} else {
|
} else {
|
||||||
self.fallback_tab_description.clone()
|
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> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
@ -35,7 +35,7 @@ use ui::{
|
|||||||
};
|
};
|
||||||
use util::paths::PathMatcher;
|
use util::paths::PathMatcher;
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{BreadcrumbText, Item, ItemEvent, ItemHandle, TabContentParams},
|
item::{BreadcrumbText, Item, ItemEvent, ItemHandle},
|
||||||
searchable::{Direction, SearchableItem, SearchableItemHandle},
|
searchable::{Direction, SearchableItem, SearchableItemHandle},
|
||||||
DeploySearch, ItemNavHistory, NewSearch, ToolbarItemEvent, ToolbarItemLocation,
|
DeploySearch, ItemNavHistory, NewSearch, ToolbarItemEvent, ToolbarItemLocation,
|
||||||
ToolbarItemView, Workspace, WorkspaceId,
|
ToolbarItemView, Workspace, WorkspaceId,
|
||||||
@ -374,7 +374,7 @@ impl Item for ProjectSearchView {
|
|||||||
Some(Icon::new(IconName::MagnifyingGlass))
|
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
|
let last_query: Option<SharedString> = self
|
||||||
.model
|
.model
|
||||||
.read(cx)
|
.read(cx)
|
||||||
@ -385,16 +385,11 @@ impl Item for ProjectSearchView {
|
|||||||
let query_text = util::truncate_and_trailoff(&query, MAX_TAB_TITLE_LEN);
|
let query_text = util::truncate_and_trailoff(&query, MAX_TAB_TITLE_LEN);
|
||||||
query_text.into()
|
query_text.into()
|
||||||
});
|
});
|
||||||
let tab_name = last_query
|
Some(
|
||||||
.filter(|query| !query.is_empty())
|
last_query
|
||||||
.unwrap_or_else(|| "Project Search".into());
|
.filter(|query| !query.is_empty())
|
||||||
Label::new(tab_name)
|
.unwrap_or_else(|| "Project Search".into()),
|
||||||
.color(if params.selected {
|
)
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
@ -9,7 +9,7 @@ use settings::Settings;
|
|||||||
use std::{path::Path, sync::Arc};
|
use std::{path::Path, sync::Arc};
|
||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::prelude::*;
|
use ui::prelude::*;
|
||||||
use workspace::item::{Item, TabContentParams};
|
use workspace::item::Item;
|
||||||
|
|
||||||
pub struct ProjectIndexDebugView {
|
pub struct ProjectIndexDebugView {
|
||||||
index: Model<ProjectIndex>,
|
index: Model<ProjectIndex>,
|
||||||
@ -271,14 +271,8 @@ impl EventEmitter<()> for ProjectIndexDebugView {}
|
|||||||
impl Item for ProjectIndexDebugView {
|
impl Item for ProjectIndexDebugView {
|
||||||
type Event = ();
|
type Event = ();
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext<'_>) -> AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
Label::new("Project Index (Debug)")
|
Some("Project Index (Debug)".into())
|
||||||
.color(if params.selected {
|
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clone_on_split(
|
fn clone_on_split(
|
||||||
|
@ -5,9 +5,9 @@ mod multibuffer_hint;
|
|||||||
use client::{telemetry::Telemetry, TelemetrySettings};
|
use client::{telemetry::Telemetry, TelemetrySettings};
|
||||||
use db::kvp::KEY_VALUE_STORE;
|
use db::kvp::KEY_VALUE_STORE;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, svg, AnyElement, AppContext, EventEmitter, FocusHandle, FocusableView,
|
actions, svg, AppContext, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
|
||||||
InteractiveElement, ParentElement, Render, Styled, Subscription, Task, View, ViewContext,
|
ParentElement, Render, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
|
||||||
VisualContext, WeakView, WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use settings::{Settings, SettingsStore};
|
use settings::{Settings, SettingsStore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -15,7 +15,7 @@ use ui::{prelude::*, CheckboxWithLabel};
|
|||||||
use vim::VimModeSetting;
|
use vim::VimModeSetting;
|
||||||
use workspace::{
|
use workspace::{
|
||||||
dock::DockPosition,
|
dock::DockPosition,
|
||||||
item::{Item, ItemEvent, TabContentParams},
|
item::{Item, ItemEvent},
|
||||||
open_new, AppState, Welcome, Workspace, WorkspaceId,
|
open_new, AppState, Welcome, Workspace, WorkspaceId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -303,14 +303,8 @@ impl FocusableView for WelcomePage {
|
|||||||
impl Item for WelcomePage {
|
impl Item for WelcomePage {
|
||||||
type Event = ItemEvent;
|
type Event = ItemEvent;
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext) -> AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
Label::new("Welcome to Zed!")
|
Some("Welcome to Zed!".into())
|
||||||
.color(if params.selected {
|
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
@ -31,7 +31,7 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use theme::Theme;
|
use theme::Theme;
|
||||||
use ui::{Element as _, Icon};
|
use ui::{Color, Element as _, Icon, IntoElement, Label, LabelCommon};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200);
|
pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200);
|
||||||
@ -144,8 +144,30 @@ pub struct TabContentParams {
|
|||||||
|
|
||||||
pub trait Item: FocusableView + EventEmitter<Self::Event> {
|
pub trait Item: FocusableView + EventEmitter<Self::Event> {
|
||||||
type Event;
|
type Event;
|
||||||
fn tab_content(&self, _params: TabContentParams, _cx: &WindowContext) -> AnyElement {
|
|
||||||
gpui::Empty.into_any()
|
/// Returns the tab contents.
|
||||||
|
///
|
||||||
|
/// By default this returns a [`Label`] that displays that text from
|
||||||
|
/// `tab_content_text`.
|
||||||
|
fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
|
||||||
|
let Some(text) = self.tab_content_text(cx) else {
|
||||||
|
return gpui::Empty.into_any();
|
||||||
|
};
|
||||||
|
|
||||||
|
let color = if params.selected {
|
||||||
|
Color::Default
|
||||||
|
} else {
|
||||||
|
Color::Muted
|
||||||
|
};
|
||||||
|
|
||||||
|
Label::new(text).color(color).into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the textual contents of the tab.
|
||||||
|
///
|
||||||
|
/// Use this if you don't need to customize the tab contents.
|
||||||
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_icon(&self, _cx: &WindowContext) -> Option<Icon> {
|
fn tab_icon(&self, _cx: &WindowContext) -> Option<Icon> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
item::{Item, ItemEvent, TabContentParams},
|
item::{Item, ItemEvent},
|
||||||
ItemNavHistory, WorkspaceId,
|
ItemNavHistory, WorkspaceId,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@ -12,7 +12,7 @@ use gpui::{
|
|||||||
WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use ui::{prelude::*, Icon, IconName, Label};
|
use ui::{prelude::*, Icon, IconName};
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Close,
|
Close,
|
||||||
@ -97,14 +97,8 @@ impl Item for SharedScreen {
|
|||||||
Some(Icon::new(IconName::Screen))
|
Some(Icon::new(IconName::Screen))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext<'_>) -> gpui::AnyElement {
|
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||||
Label::new(format!("{}'s screen", self.user.github_login))
|
Some(format!("{}'s screen", self.user.github_login).into())
|
||||||
.color(if params.selected {
|
|
||||||
Color::Default
|
|
||||||
} else {
|
|
||||||
Color::Muted
|
|
||||||
})
|
|
||||||
.into_any_element()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||||
|
Loading…
Reference in New Issue
Block a user