From ba248244ec94724af99a41c9ec791ac437cb78e4 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 9 May 2023 17:36:49 -0600 Subject: [PATCH] Allow terminal to be docked left, bottom, or right Co-Authored-By: Joseph Lyons --- crates/project_panel/src/project_panel.rs | 2 -- crates/terminal_view/src/terminal_panel.rs | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 8ee701c3cc..c22e297a02 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -144,10 +144,8 @@ impl ProjectPanel { let project_panel = cx.add_view(|cx: &mut ViewContext| { // Update the dock position when the setting changes. let mut old_dock_position = cx.global::().project_panel_overrides.dock; - dbg!(old_dock_position); cx.observe_global::(move |_, cx| { let new_dock_position = cx.global::().project_panel_overrides.dock; - dbg!(new_dock_position); if new_dock_position != old_dock_position { old_dock_position = new_dock_position; cx.emit(Event::DockPositionChanged); diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index e2bf2c9e32..58deda9236 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -14,6 +14,7 @@ pub fn init(cx: &mut AppContext) { pub enum Event { Close, + DockPositionChanged, } pub struct TerminalPanel { @@ -25,6 +26,15 @@ pub struct TerminalPanel { impl TerminalPanel { pub fn new(workspace: &Workspace, cx: &mut ViewContext) -> Self { + let mut old_dock_position = cx.global::().terminal_overrides.dock; + cx.observe_global::(move |_, cx| { + let new_dock_position = cx.global::().terminal_overrides.dock; + if new_dock_position != old_dock_position { + old_dock_position = new_dock_position; + cx.emit(Event::DockPositionChanged); + } + }).detach(); + let this = cx.weak_handle(); let pane = cx.add_view(|cx| { let window_id = cx.window_id(); @@ -160,12 +170,12 @@ impl Panel for TerminalPanel { } } - fn should_change_position_on_event(_: &Self::Event) -> bool { - todo!() + fn should_change_position_on_event(event: &Self::Event) -> bool { + matches!(event, Event::DockPositionChanged) } fn should_activate_on_event(&self, _: &Self::Event, _: &AppContext) -> bool { - todo!() + false } fn should_close_on_event(&self, event: &Event, _: &AppContext) -> bool {