diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 63263b23c7..a89d544074 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1395,6 +1395,10 @@ impl workspace::dock::Panel for ProjectPanel { false } + fn is_zoomed(&self, _: &WindowContext) -> bool { + false + } + fn set_zoomed(&mut self, _: bool, _: &mut ViewContext) {} fn icon_path(&self) -> &'static str { diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 4e90121d59..4926a8775e 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -207,6 +207,10 @@ impl Panel for TerminalPanel { matches!(event, Event::ZoomOut) } + fn is_zoomed(&self, cx: &WindowContext) -> bool { + self.pane.read(cx).is_zoomed() + } + fn set_zoomed(&mut self, zoomed: bool, cx: &mut ViewContext) { self.pane.update(cx, |pane, cx| pane.set_zoomed(zoomed, cx)); } diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index a387f05e65..5c501f64ad 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -21,6 +21,7 @@ pub trait Panel: View { fn should_change_position_on_event(_: &Self::Event) -> bool; fn should_zoom_in_on_event(_: &Self::Event) -> bool; fn should_zoom_out_on_event(_: &Self::Event) -> bool; + fn is_zoomed(&self, cx: &WindowContext) -> bool; fn set_zoomed(&mut self, zoomed: bool, cx: &mut ViewContext); fn should_activate_on_event(_: &Self::Event) -> bool; fn should_close_on_event(_: &Self::Event) -> bool; @@ -33,6 +34,7 @@ pub trait PanelHandle { fn position(&self, cx: &WindowContext) -> DockPosition; fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool; fn set_position(&self, position: DockPosition, cx: &mut WindowContext); + fn is_zoomed(&self, cx: &WindowContext) -> bool; fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext); fn default_size(&self, cx: &WindowContext) -> f32; fn icon_path(&self, cx: &WindowContext) -> &'static str; @@ -66,6 +68,10 @@ where self.read(cx).default_size(cx) } + fn is_zoomed(&self, cx: &WindowContext) -> bool { + self.read(cx).is_zoomed(cx) + } + fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext) { self.update(cx, |this, cx| this.set_zoomed(zoomed, cx)) } @@ -140,7 +146,6 @@ struct PanelEntry { panel: Rc, size: f32, context_menu: ViewHandle, - zoomed: bool, _subscriptions: [Subscription; 2], } @@ -206,12 +211,10 @@ impl Dock { ) { for entry in &mut self.panel_entries { if entry.panel.as_any() == panel { - if zoomed != entry.zoomed { - entry.zoomed = zoomed; + if zoomed != entry.panel.is_zoomed(cx) { entry.panel.set_zoomed(zoomed, cx); } - } else if entry.zoomed { - entry.zoomed = false; + } else if entry.panel.is_zoomed(cx) { entry.panel.set_zoomed(false, cx); } } @@ -221,8 +224,7 @@ impl Dock { pub fn zoom_out(&mut self, cx: &mut ViewContext) { for entry in &mut self.panel_entries { - if entry.zoomed { - entry.zoomed = false; + if entry.panel.is_zoomed(cx) { entry.panel.set_zoomed(false, cx); } } @@ -255,7 +257,6 @@ impl Dock { self.panel_entries.push(PanelEntry { panel: Rc::new(panel), size, - zoomed: false, context_menu: cx.add_view(|cx| { let mut menu = ContextMenu::new(dock_view_id, cx); menu.set_position_mode(OverlayPositionMode::Local); @@ -314,9 +315,9 @@ impl Dock { } } - pub fn zoomed_panel(&self) -> Option> { + pub fn zoomed_panel(&self, cx: &WindowContext) -> Option> { let entry = self.active_entry()?; - if entry.zoomed { + if entry.panel.is_zoomed(cx) { Some(entry.panel.clone()) } else { None @@ -598,6 +599,10 @@ pub(crate) mod test { cx.emit(TestPanelEvent::PositionChanged); } + fn is_zoomed(&self, _: &WindowContext) -> bool { + unimplemented!() + } + fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext) { unimplemented!() } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 278ea9d879..e9fc2866aa 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1330,7 +1330,7 @@ impl Workspace { DockPosition::Right => (&self.right_dock, [&self.left_dock, &self.bottom_dock]), }; - let zoomed_panel = dock.read(&cx).zoomed_panel()?; + let zoomed_panel = dock.read(&cx).zoomed_panel(cx)?; if other_docks.iter().all(|dock| !dock.read(cx).has_focus(cx)) && !self.active_pane.read(cx).has_focus() {