This commit is contained in:
Nathan Sobo 2023-04-12 12:38:26 -06:00
parent 4cb13fb39c
commit 25ad635577
6 changed files with 47 additions and 53 deletions

View File

@ -54,10 +54,22 @@ impl View for Breadcrumbs {
let breadcrumbs = match active_item.breadcrumbs(&theme, cx) {
Some(breadcrumbs) => breadcrumbs,
None => return Empty::new().boxed(),
};
}
.into_iter()
.map(|breadcrumb| {
let text = Text::new(
breadcrumb.text,
theme.workspace.breadcrumbs.default.text.clone(),
);
if let Some(highlights) = breadcrumb.highlights {
text.with_highlights(highlights).boxed()
} else {
text.boxed()
}
});
let crumbs = Flex::row()
.with_children(Itertools::intersperse_with(breadcrumbs.into_iter(), || {
.with_children(Itertools::intersperse_with(breadcrumbs, || {
Label::new("", style.default.text.clone()).boxed()
}))
.constrained()

View File

@ -6,8 +6,7 @@ use gpui::{
elements::*,
impl_internal_actions,
platform::{CursorStyle, MouseButton},
AppContext, Drawable, Element, Entity, MouseState, Subscription, View, ViewContext,
ViewHandle,
AppContext, Drawable, Element, Entity, MouseState, Subscription, View, ViewContext, ViewHandle,
};
use settings::{settings_file::SettingsFile, Settings};
use workspace::{

View File

@ -28,7 +28,7 @@ use std::{
};
use text::Selection;
use util::{ResultExt, TryFutureExt};
use workspace::item::FollowableItemHandle;
use workspace::item::{BreadcrumbText, FollowableItemHandle};
use workspace::{
item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem},
searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle},
@ -727,11 +727,7 @@ impl Item for Editor {
ToolbarItemLocation::PrimaryLeft { flex: None }
}
fn breadcrumbs(
&self,
theme: &theme::Theme,
cx: &AppContext,
) -> Option<Vec<Box<dyn AnyRootElement>>> {
fn breadcrumbs(&self, theme: &theme::Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {
let cursor = self.selections.newest_anchor().head();
let multibuffer = &self.buffer().read(cx);
let (buffer_id, symbols) =
@ -751,18 +747,13 @@ impl Item for Editor {
.map(|path| path.to_string_lossy().to_string())
.unwrap_or_else(|| "untitled".to_string());
let filename_label = Label::new(filename, theme.workspace.breadcrumbs.default.text.clone());
let mut breadcrumbs =
vec![Box::new(filename_label.into_root(cx)) as Box<dyn AnyRootElement>];
breadcrumbs.extend(symbols.into_iter().map(|symbol| {
Box::new(
Text::new(
symbol.text,
theme.workspace.breadcrumbs.default.text.clone(),
)
.with_highlights(symbol.highlight_ranges)
.into_root(cx) as Element<Editor>,
) as Box<dyn AnyRootElement>
let mut breadcrumbs = vec![BreadcrumbText {
text: filename,
highlights: None,
}];
breadcrumbs.extend(symbols.into_iter().map(|symbol| BreadcrumbText {
text: symbol.text,
highlights: Some(symbol.highlight_ranges),
}));
Some(breadcrumbs)
}

View File

@ -12,8 +12,8 @@ use gpui::{
actions,
elements::*,
platform::{CursorStyle, MouseButton},
Action, AnyViewHandle, AppContext, Element, Entity, ModelContext, ModelHandle, RenderedView,
Subscription, Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
Action, AnyViewHandle, AppContext, Element, Entity, ModelContext, ModelHandle, Subscription,
Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
};
use menu::Confirm;
use project::{search::SearchQuery, Project};
@ -28,7 +28,7 @@ use std::{
};
use util::ResultExt as _;
use workspace::{
item::{Item, ItemEvent, ItemHandle},
item::{BreadcrumbText, Item, ItemEvent, ItemHandle},
searchable::{Direction, SearchableItem, SearchableItemHandle},
ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView, Workspace, WorkspaceId,
};
@ -364,11 +364,7 @@ impl Item for ProjectSearchView {
}
}
fn breadcrumbs(
&self,
theme: &theme::Theme,
cx: &AppContext,
) -> Option<Vec<Box<dyn RenderedView>>> {
fn breadcrumbs(&self, theme: &theme::Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {
self.results_editor.breadcrumbs(theme, cx)
}

View File

@ -17,8 +17,8 @@ use gpui::{
impl_actions, impl_internal_actions,
keymap_matcher::{KeymapContext, Keystroke},
platform::KeyDownEvent,
AnyViewHandle, AppContext, Drawable, Element, Entity, ModelHandle, RenderedView, Task, View,
ViewContext, ViewHandle, WeakViewHandle,
AnyViewHandle, AppContext, Drawable, Element, Entity, ModelHandle, Task, View, ViewContext,
ViewHandle, WeakViewHandle,
};
use project::{LocalWorktree, Project};
use serde::Deserialize;
@ -34,7 +34,7 @@ use terminal::{
};
use util::ResultExt;
use workspace::{
item::{Item, ItemEvent},
item::{BreadcrumbText, Item, ItemEvent},
notifications::NotifyResultExt,
pane, register_deserializable_item,
searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle},
@ -606,18 +606,11 @@ impl Item for TerminalView {
ToolbarItemLocation::PrimaryLeft { flex: None }
}
fn breadcrumbs(
&self,
theme: &theme::Theme,
cx: &AppContext,
) -> Option<Vec<Box<dyn RenderedView>>> {
Some(vec![Box::new(
Text::new(
self.terminal().read(cx).breadcrumb_text.clone(),
theme.workspace.breadcrumbs.default.text.clone(),
)
.boxed() as Element<TerminalView>,
)])
fn breadcrumbs(&self, _: &theme::Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {
Some(vec![BreadcrumbText {
text: self.terminal().read(cx).breadcrumb_text.clone(),
highlights: None,
}])
}
fn serialized_item_kind() -> Option<&'static str> {

View File

@ -3,6 +3,7 @@ use std::{
borrow::Cow,
cell::RefCell,
fmt,
ops::Range,
path::PathBuf,
rc::Rc,
sync::{
@ -15,7 +16,7 @@ use std::{
use anyhow::Result;
use client::{proto, Client};
use gpui::{
elements::AnyRootElement, AnyViewHandle, AppContext, Element, ModelHandle, Task, View,
fonts::HighlightStyle, AnyViewHandle, AppContext, Element, ModelHandle, Task, View,
ViewContext, ViewHandle, WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath};
@ -38,6 +39,12 @@ pub enum ItemEvent {
Edit,
}
// TODO: Combine this with existing HighlightedText struct?
pub struct BreadcrumbText {
pub text: String,
pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
}
pub trait Item: View {
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
@ -134,11 +141,7 @@ pub trait Item: View {
ToolbarItemLocation::Hidden
}
fn breadcrumbs(
&self,
_theme: &Theme,
_cx: &ViewContext<Self>,
) -> Option<Vec<Box<dyn AnyRootElement>>> {
fn breadcrumbs(&self, _theme: &Theme, _cx: &AppContext) -> Option<Vec<BreadcrumbText>> {
None
}
@ -225,7 +228,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
) -> gpui::Subscription;
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<Box<dyn AnyRootElement>>>;
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>>;
fn serialized_item_kind(&self) -> Option<&'static str>;
fn show_toolbar(&self, cx: &AppContext) -> bool;
}
@ -595,7 +598,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
self.read(cx).breadcrumb_location()
}
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<Box<dyn AnyRootElement>>> {
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {
self.read(cx).breadcrumbs(theme, cx)
}