Don't show navigation controls for terminal panel

Antonio Scandurra created

Change summary

crates/terminal_view/src/terminal_panel.rs |   1 
crates/workspace/src/pane.rs               |  14 ++
crates/workspace/src/toolbar.rs            | 149 +++++++++++++----------
3 files changed, 98 insertions(+), 66 deletions(-)

Detailed changes

crates/terminal_view/src/terminal_panel.rs 🔗

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

crates/workspace/src/pane.rs 🔗

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

crates/workspace/src/toolbar.rs 🔗

@@ -53,6 +53,7 @@ pub enum ToolbarItemLocation {
 pub struct Toolbar {
     active_pane_item: Option<Box<dyn ItemHandle>>,
     hidden: bool,
+    can_navigate: bool,
     pane: WeakViewHandle<Pane>,
     items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
 }
@@ -132,76 +133,86 @@ impl View for Toolbar {
         let button_style = theme.nav_button;
         let tooltip_style = theme::current(cx).tooltip.clone();
 
-        Flex::column()
-            .with_child(
-                Flex::row()
-                    .with_child(nav_button(
-                        "icons/arrow_left_16.svg",
-                        button_style,
-                        nav_button_height,
-                        tooltip_style.clone(),
-                        enable_go_backward,
-                        spacing,
+        let mut primary_items = Flex::row();
+        if self.can_navigate {
+            primary_items.add_child(nav_button(
+                "icons/arrow_left_16.svg",
+                button_style,
+                nav_button_height,
+                tooltip_style.clone(),
+                enable_go_backward,
+                spacing,
+                {
+                    let pane = pane.clone();
+                    move |toolbar, cx| {
+                        if let Some(workspace) = toolbar
+                            .pane
+                            .upgrade(cx)
+                            .and_then(|pane| pane.read(cx).workspace().upgrade(cx))
                         {
                             let pane = pane.clone();
-                            move |toolbar, cx| {
-                                if let Some(workspace) = toolbar
-                                    .pane
-                                    .upgrade(cx)
-                                    .and_then(|pane| pane.read(cx).workspace().upgrade(cx))
-                                {
-                                    let pane = pane.clone();
-                                    cx.window_context().defer(move |cx| {
-                                        workspace.update(cx, |workspace, cx| {
-                                            Pane::go_back(workspace, Some(pane.clone()), cx)
-                                                .detach_and_log_err(cx);
-                                        });
-                                    })
-                                }
-                            }
-                        },
-                        super::GoBack { pane: None },
-                        "Go Back",
-                        cx,
-                    ))
-                    .with_child(nav_button(
-                        "icons/arrow_right_16.svg",
-                        button_style,
-                        nav_button_height,
-                        tooltip_style,
-                        enable_go_forward,
-                        spacing,
+                            cx.window_context().defer(move |cx| {
+                                workspace.update(cx, |workspace, cx| {
+                                    Pane::go_back(workspace, Some(pane.clone()), cx)
+                                        .detach_and_log_err(cx);
+                                });
+                            })
+                        }
+                    }
+                },
+                super::GoBack { pane: None },
+                "Go Back",
+                cx,
+            ));
+            primary_items.add_child(nav_button(
+                "icons/arrow_right_16.svg",
+                button_style,
+                nav_button_height,
+                tooltip_style,
+                enable_go_forward,
+                spacing,
+                {
+                    let pane = pane.clone();
+                    move |toolbar, cx| {
+                        if let Some(workspace) = toolbar
+                            .pane
+                            .upgrade(cx)
+                            .and_then(|pane| pane.read(cx).workspace().upgrade(cx))
                         {
                             let pane = pane.clone();
-                            move |toolbar, cx| {
-                                if let Some(workspace) = toolbar
-                                    .pane
-                                    .upgrade(cx)
-                                    .and_then(|pane| pane.read(cx).workspace().upgrade(cx))
-                                {
-                                    let pane = pane.clone();
-                                    cx.window_context().defer(move |cx| {
-                                        workspace.update(cx, |workspace, cx| {
-                                            Pane::go_forward(workspace, Some(pane.clone()), cx)
-                                                .detach_and_log_err(cx);
-                                        });
-                                    });
-                                }
-                            }
-                        },
-                        super::GoForward { pane: None },
-                        "Go Forward",
-                        cx,
-                    ))
-                    .with_children(primary_left_items)
-                    .with_children(primary_right_items)
-                    .constrained()
-                    .with_height(height),
-            )
-            .with_children(secondary_item)
-            .contained()
-            .with_style(container_style)
-            .into_any_named("toolbar")
+                            cx.window_context().defer(move |cx| {
+                                workspace.update(cx, |workspace, cx| {
+                                    Pane::go_forward(workspace, Some(pane.clone()), cx)
+                                        .detach_and_log_err(cx);
+                                });
+                            });
+                        }
+                    }
+                },
+                super::GoForward { pane: None },
+                "Go Forward",
+                cx,
+            ));
+        }
+        primary_items.extend(primary_left_items);
+        primary_items.extend(primary_right_items);
+
+        let mut toolbar = Flex::column();
+        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()
+                .with_style(container_style)
+                .into_any_named("toolbar")
+        }
     }
 }
 
@@ -264,9 +275,15 @@ impl Toolbar {
             pane,
             items: Default::default(),
             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>)
     where
         T: 'static + ToolbarItemView,