Update breadcrumb rendering (#3505)
This PR updates the rendering of the breadcrumb. Release Notes: - N/A Co-authored-by: Nate Butler <iamnbutler@gmail.com>
This commit is contained in:
parent
fc9b662042
commit
02e507b973
1 changed files with 39 additions and 42 deletions
|
@ -1,10 +1,10 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Component, Element, EventEmitter, IntoElement, ParentElement, Render, StyledText, Subscription,
|
Div, Element, EventEmitter, IntoElement, ParentElement, Render, StyledText, Subscription,
|
||||||
ViewContext, WeakView,
|
ViewContext, WeakView,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::{ButtonCommon, ButtonLike, ButtonStyle, Clickable, Disableable, Label};
|
use ui::{prelude::*, ButtonLike, ButtonStyle, Label};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{ItemEvent, ItemHandle},
|
item::{ItemEvent, ItemHandle},
|
||||||
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||||
|
@ -36,54 +36,51 @@ impl EventEmitter<Event> for Breadcrumbs {}
|
||||||
impl EventEmitter<ToolbarItemEvent> for Breadcrumbs {}
|
impl EventEmitter<ToolbarItemEvent> for Breadcrumbs {}
|
||||||
|
|
||||||
impl Render for Breadcrumbs {
|
impl Render for Breadcrumbs {
|
||||||
type Element = Component<ButtonLike>;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
let button = ButtonLike::new("breadcrumbs")
|
let element = h_stack().text_ui();
|
||||||
.style(ButtonStyle::Transparent)
|
|
||||||
.disabled(true);
|
|
||||||
|
|
||||||
let active_item = match &self.active_item {
|
let Some(active_item) = &self
|
||||||
Some(active_item) => active_item,
|
.active_item
|
||||||
None => return button.into_element(),
|
.as_ref()
|
||||||
|
.filter(|item| item.downcast::<editor::Editor>().is_some())
|
||||||
|
else {
|
||||||
|
return element;
|
||||||
};
|
};
|
||||||
let not_editor = active_item.downcast::<editor::Editor>().is_none();
|
|
||||||
|
|
||||||
let breadcrumbs = match active_item.breadcrumbs(cx.theme(), cx) {
|
let Some(segments) = active_item.breadcrumbs(cx.theme(), cx) else {
|
||||||
Some(breadcrumbs) => breadcrumbs,
|
return element;
|
||||||
None => return button.into_element(),
|
};
|
||||||
}
|
|
||||||
.into_iter()
|
let highlighted_segments = segments.into_iter().map(|segment| {
|
||||||
.map(|breadcrumb| {
|
StyledText::new(segment.text)
|
||||||
StyledText::new(breadcrumb.text)
|
.with_highlights(&cx.text_style(), segment.highlights.unwrap_or_default())
|
||||||
.with_highlights(&cx.text_style(), breadcrumb.highlights.unwrap_or_default())
|
|
||||||
.into_any()
|
.into_any()
|
||||||
});
|
});
|
||||||
|
let breadcrumbs = Itertools::intersperse_with(highlighted_segments, || {
|
||||||
|
Label::new("›").into_any_element()
|
||||||
|
});
|
||||||
|
|
||||||
let button = button.children(Itertools::intersperse_with(breadcrumbs, || {
|
element.child(
|
||||||
Label::new(" › ").into_any_element()
|
ButtonLike::new("toggle outline view")
|
||||||
}));
|
.style(ButtonStyle::Subtle)
|
||||||
|
.child(h_stack().gap_1().children(breadcrumbs))
|
||||||
if not_editor || !self.pane_focused {
|
// We disable the button when it is not focused
|
||||||
return button.into_element();
|
// due to ... @julia what was the reason again?
|
||||||
}
|
.disabled(!self.pane_focused)
|
||||||
|
.on_click(move |_, _cx| {
|
||||||
// let this = cx.view().downgrade();
|
todo!("outline::toggle");
|
||||||
button
|
// this.update(cx, |this, cx| {
|
||||||
.style(ButtonStyle::Filled)
|
// if let Some(workspace) = this.workspace.upgrade() {
|
||||||
.disabled(false)
|
// workspace.update(cx, |_workspace, _cx| {
|
||||||
.on_click(move |_, _cx| {
|
// outline::toggle(workspace, &Default::default(), cx)
|
||||||
todo!("outline::toggle");
|
// })
|
||||||
// this.update(cx, |this, cx| {
|
// }
|
||||||
// if let Some(workspace) = this.workspace.upgrade() {
|
// })
|
||||||
// workspace.update(cx, |_workspace, _cx| {
|
// .ok();
|
||||||
// outline::toggle(workspace, &Default::default(), cx)
|
}),
|
||||||
// })
|
)
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .ok();
|
|
||||||
})
|
|
||||||
.into_element()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue