Introduce `Panel::can_zoom`

Antonio Scandurra created

Change summary

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(-)

Detailed changes

crates/project_panel/src/project_panel.rs 🔗

@@ -1373,6 +1373,10 @@ impl workspace::dock::Panel for ProjectPanel {
         cx.global::<Settings>().project_panel.default_width
     }
 
+    fn can_zoom(&self, _cx: &gpui::WindowContext) -> bool {
+        false
+    }
+
     fn icon_path(&self) -> &'static str {
         "icons/folder_tree_16.svg"
     }

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::<Settings>();
         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::<Settings>().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"
     }

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<Self>);
     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<String> {
@@ -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<String>;
@@ -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"
         }