From c03e470fe6e0ef750f784d757ea31ddf689c3d05 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 15 May 2023 17:10:30 +0200 Subject: [PATCH] Introduce `Panel::can_zoom` --- crates/project_panel/src/project_panel.rs | 4 ++++ crates/terminal_view/src/terminal_panel.rs | 10 +++++++--- crates/workspace/src/dock.rs | 18 +++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index e271c9970b..b1f0740df0 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1373,6 +1373,10 @@ impl workspace::dock::Panel for ProjectPanel { cx.global::().project_panel.default_width } + fn can_zoom(&self, _cx: &gpui::WindowContext) -> bool { + false + } + fn icon_path(&self) -> &'static str { "icons/folder_tree_16.svg" } diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 995c8be50b..f3bfbdd730 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -1,7 +1,7 @@ use crate::TerminalView; use gpui::{ elements::*, AppContext, Entity, ModelHandle, Subscription, View, ViewContext, ViewHandle, - WeakViewHandle, + WeakViewHandle, WindowContext, }; use project::Project; use settings::{settings_file::SettingsFile, Settings, TerminalDockPosition, WorkingDirectory}; @@ -149,7 +149,7 @@ impl View for TerminalPanel { } impl Panel for TerminalPanel { - fn position(&self, cx: &gpui::WindowContext) -> DockPosition { + fn position(&self, cx: &WindowContext) -> DockPosition { let settings = cx.global::(); let dock = settings .terminal_overrides @@ -179,7 +179,7 @@ impl Panel for TerminalPanel { }); } - fn default_size(&self, cx: &gpui::WindowContext) -> f32 { + fn default_size(&self, cx: &WindowContext) -> f32 { let settings = &cx.global::().terminal_overrides; match self.position(cx) { DockPosition::Left | DockPosition::Right => settings.default_width.unwrap_or(640.), @@ -187,6 +187,10 @@ impl Panel for TerminalPanel { } } + fn can_zoom(&self, _: &WindowContext) -> bool { + true + } + fn icon_path(&self) -> &'static str { "icons/terminal_12.svg" } diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 86c2cc3929..6d0b34dc27 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -9,11 +9,16 @@ use serde::Deserialize; use settings::Settings; use std::rc::Rc; +pub fn init(cx: &mut AppContext) { + cx.capture_action(Dock::toggle_zoom); +} + pub trait Panel: View { fn position(&self, cx: &WindowContext) -> DockPosition; fn position_is_valid(&self, position: DockPosition) -> bool; fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext); fn default_size(&self, cx: &WindowContext) -> f32; + fn can_zoom(&self, cx: &WindowContext) -> bool; fn icon_path(&self) -> &'static str; fn icon_tooltip(&self) -> String; fn icon_label(&self, _: &AppContext) -> Option { @@ -30,6 +35,7 @@ pub trait PanelHandle { fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool; fn set_position(&self, position: DockPosition, cx: &mut WindowContext); fn default_size(&self, cx: &WindowContext) -> f32; + fn can_zoom(&self, cx: &WindowContext) -> bool; fn icon_path(&self, cx: &WindowContext) -> &'static str; fn icon_tooltip(&self, cx: &WindowContext) -> String; fn icon_label(&self, cx: &WindowContext) -> Option; @@ -61,6 +67,10 @@ where self.read(cx).default_size(cx) } + fn can_zoom(&self, cx: &WindowContext) -> bool { + self.read(cx).can_zoom(cx) + } + fn icon_path(&self, cx: &WindowContext) -> &'static str { self.read(cx).icon_path() } @@ -313,9 +323,7 @@ impl View for Dock { .resizable( self.position.to_resize_handle_side(), size, - |dock: &mut Self, size, cx| { - dock.resize_active_panel(size, cx); - }, + |dock: &mut Self, size, cx| dock.resize_active_panel(size, cx), ) .into_any() } else { @@ -526,6 +534,10 @@ pub(crate) mod test { } } + fn can_zoom(&self, _cx: &WindowContext) -> bool { + unimplemented!() + } + fn icon_path(&self) -> &'static str { "icons/test_panel.svg" }