Don't show navigation controls for terminal panel

This commit is contained in:
Antonio Scandurra 2023-05-25 15:15:20 +02:00
parent 414b97adce
commit aa8c0475b1
3 changed files with 98 additions and 66 deletions

View file

@ -55,6 +55,7 @@ impl TerminalPanel {
cx, cx,
); );
pane.set_can_split(false, cx); pane.set_can_split(false, cx);
pane.set_can_navigate(false, cx);
pane.on_can_drop(move |drag_and_drop, cx| { pane.on_can_drop(move |drag_and_drop, cx| {
drag_and_drop drag_and_drop
.currently_dragged::<DraggedItem>(window_id) .currently_dragged::<DraggedItem>(window_id)

View file

@ -164,6 +164,7 @@ pub struct Pane {
has_focus: bool, has_focus: bool,
can_drop: Rc<dyn Fn(&DragAndDrop<Workspace>, &WindowContext) -> bool>, can_drop: Rc<dyn Fn(&DragAndDrop<Workspace>, &WindowContext) -> bool>,
can_split: bool, can_split: bool,
can_navigate: bool,
render_tab_bar_buttons: Rc<dyn Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>>, render_tab_bar_buttons: Rc<dyn Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>>,
} }
@ -279,6 +280,7 @@ impl Pane {
has_focus: false, has_focus: false,
can_drop: Rc::new(|_, _| true), can_drop: Rc::new(|_, _| true),
can_split: true, can_split: true,
can_navigate: true,
render_tab_bar_buttons: Rc::new(|pane, cx| { render_tab_bar_buttons: Rc::new(|pane, cx| {
Flex::row() Flex::row()
// New menu // New menu
@ -346,6 +348,14 @@ impl Pane {
cx.notify(); cx.notify();
} }
pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {
self.can_navigate = can_navigate;
self.toolbar.update(cx, |toolbar, cx| {
toolbar.set_can_navigate(can_navigate, cx);
});
cx.notify();
}
pub fn set_render_tab_bar_buttons<F>(&mut self, cx: &mut ViewContext<Self>, render: F) pub fn set_render_tab_bar_buttons<F>(&mut self, cx: &mut ViewContext<Self>, render: F)
where where
F: 'static + Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>, F: 'static + Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>,
@ -430,6 +440,10 @@ impl Pane {
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
let to_load = if let Some(pane) = pane.upgrade(cx) { let to_load = if let Some(pane) = pane.upgrade(cx) {
if !pane.read(cx).can_navigate {
return Task::ready(Ok(()));
}
cx.focus(&pane); cx.focus(&pane);
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {

View file

@ -53,6 +53,7 @@ pub enum ToolbarItemLocation {
pub struct Toolbar { pub struct Toolbar {
active_pane_item: Option<Box<dyn ItemHandle>>, active_pane_item: Option<Box<dyn ItemHandle>>,
hidden: bool, hidden: bool,
can_navigate: bool,
pane: WeakViewHandle<Pane>, pane: WeakViewHandle<Pane>,
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>, items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
} }
@ -132,10 +133,9 @@ impl View for Toolbar {
let button_style = theme.nav_button; let button_style = theme.nav_button;
let tooltip_style = theme::current(cx).tooltip.clone(); let tooltip_style = theme::current(cx).tooltip.clone();
Flex::column() let mut primary_items = Flex::row();
.with_child( if self.can_navigate {
Flex::row() primary_items.add_child(nav_button(
.with_child(nav_button(
"icons/arrow_left_16.svg", "icons/arrow_left_16.svg",
button_style, button_style,
nav_button_height, nav_button_height,
@ -163,8 +163,8 @@ impl View for Toolbar {
super::GoBack { pane: None }, super::GoBack { pane: None },
"Go Back", "Go Back",
cx, cx,
)) ));
.with_child(nav_button( primary_items.add_child(nav_button(
"icons/arrow_right_16.svg", "icons/arrow_right_16.svg",
button_style, button_style,
nav_button_height, nav_button_height,
@ -192,18 +192,29 @@ impl View for Toolbar {
super::GoForward { pane: None }, super::GoForward { pane: None },
"Go Forward", "Go Forward",
cx, cx,
)) ));
.with_children(primary_left_items) }
.with_children(primary_right_items) primary_items.extend(primary_left_items);
.constrained() primary_items.extend(primary_right_items);
.with_height(height),
) let mut toolbar = Flex::column();
.with_children(secondary_item) if !primary_items.is_empty() {
toolbar.add_child(primary_items.constrained().with_height(height));
}
if let Some(secondary_item) = secondary_item {
toolbar.add_child(secondary_item);
}
if toolbar.is_empty() {
toolbar.into_any_named("toolbar")
} else {
toolbar
.contained() .contained()
.with_style(container_style) .with_style(container_style)
.into_any_named("toolbar") .into_any_named("toolbar")
} }
} }
}
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>( fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
@ -264,9 +275,15 @@ impl Toolbar {
pane, pane,
items: Default::default(), items: Default::default(),
hidden: false, hidden: false,
can_navigate: true,
} }
} }
pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {
self.can_navigate = can_navigate;
cx.notify();
}
pub fn add_item<T>(&mut self, item: ViewHandle<T>, cx: &mut ViewContext<Self>) pub fn add_item<T>(&mut self, item: ViewHandle<T>, cx: &mut ViewContext<Self>)
where where
T: 'static + ToolbarItemView, T: 'static + ToolbarItemView,