diff --git a/Cargo.lock b/Cargo.lock index 7fa4d3b9ba..95fcf2224d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6809,6 +6809,7 @@ dependencies = [ "procinfo", "project", "rand 0.8.5", + "search", "serde", "serde_derive", "settings", diff --git a/crates/terminal_view/Cargo.toml b/crates/terminal_view/Cargo.toml index a42d6c550e..6fa920d739 100644 --- a/crates/terminal_view/Cargo.toml +++ b/crates/terminal_view/Cargo.toml @@ -14,6 +14,7 @@ editor = { path = "../editor" } language = { path = "../language" } gpui = { path = "../gpui" } project = { path = "../project" } +search = { path = "../search" } settings = { path = "../settings" } theme = { path = "../theme" } util = { path = "../util" } diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 791a8b21c5..68382f8d4f 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/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::(window_id) @@ -99,6 +100,9 @@ impl TerminalPanel { )) .into_any() }); + let buffer_search_bar = cx.add_view(search::BufferSearchBar::new); + pane.toolbar() + .update(cx, |toolbar, cx| toolbar.add_item(buffer_search_bar, cx)); pane }); let subscriptions = vec![ diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 26f3d17453..4bb3bf61c4 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -164,6 +164,7 @@ pub struct Pane { has_focus: bool, can_drop: Rc, &WindowContext) -> bool>, can_split: bool, + can_navigate: bool, render_tab_bar_buttons: Rc) -> AnyElement>, } @@ -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.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(&mut self, cx: &mut ViewContext, render: F) where F: 'static + Fn(&mut Pane, &mut ViewContext) -> AnyElement, @@ -430,6 +440,10 @@ impl Pane { cx: &mut ViewContext, ) -> Task> { 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| { diff --git a/crates/workspace/src/toolbar.rs b/crates/workspace/src/toolbar.rs index 30890ed5d2..be327c45f2 100644 --- a/crates/workspace/src/toolbar.rs +++ b/crates/workspace/src/toolbar.rs @@ -53,6 +53,7 @@ pub enum ToolbarItemLocation { pub struct Toolbar { active_pane_item: Option>, hidden: bool, + can_navigate: bool, pane: WeakViewHandle, items: Vec<(Box, 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.can_navigate = can_navigate; + cx.notify(); + } + pub fn add_item(&mut self, item: ViewHandle, cx: &mut ViewContext) where T: 'static + ToolbarItemView,