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) { let breadcrumbs = match active_item.breadcrumbs(&theme, cx) {
Some(breadcrumbs) => breadcrumbs, Some(breadcrumbs) => breadcrumbs,
None => return Empty::new().boxed(), 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() 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() Label::new("", style.default.text.clone()).boxed()
})) }))
.constrained() .constrained()

View File

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

View File

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

View File

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

View File

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

View File

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