Introduce Panel::can_zoom

This commit is contained in:
Antonio Scandurra 2023-05-15 17:10:30 +02:00
parent ba50b35de6
commit c03e470fe6
3 changed files with 26 additions and 6 deletions

View file

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

View file

@ -1,7 +1,7 @@
use crate::TerminalView; use crate::TerminalView;
use gpui::{ use gpui::{
elements::*, AppContext, Entity, ModelHandle, Subscription, View, ViewContext, ViewHandle, elements::*, AppContext, Entity, ModelHandle, Subscription, View, ViewContext, ViewHandle,
WeakViewHandle, WeakViewHandle, WindowContext,
}; };
use project::Project; use project::Project;
use settings::{settings_file::SettingsFile, Settings, TerminalDockPosition, WorkingDirectory}; use settings::{settings_file::SettingsFile, Settings, TerminalDockPosition, WorkingDirectory};
@ -149,7 +149,7 @@ impl View for TerminalPanel {
} }
impl Panel 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 settings = cx.global::<Settings>();
let dock = settings let dock = settings
.terminal_overrides .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; let settings = &cx.global::<Settings>().terminal_overrides;
match self.position(cx) { match self.position(cx) {
DockPosition::Left | DockPosition::Right => settings.default_width.unwrap_or(640.), 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 { fn icon_path(&self) -> &'static str {
"icons/terminal_12.svg" "icons/terminal_12.svg"
} }

View file

@ -9,11 +9,16 @@ use serde::Deserialize;
use settings::Settings; use settings::Settings;
use std::rc::Rc; use std::rc::Rc;
pub fn init(cx: &mut AppContext) {
cx.capture_action(Dock::toggle_zoom);
}
pub trait Panel: View { pub trait Panel: View {
fn position(&self, cx: &WindowContext) -> DockPosition; fn position(&self, cx: &WindowContext) -> DockPosition;
fn position_is_valid(&self, position: DockPosition) -> bool; fn position_is_valid(&self, position: DockPosition) -> bool;
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>); fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
fn default_size(&self, cx: &WindowContext) -> f32; fn default_size(&self, cx: &WindowContext) -> f32;
fn can_zoom(&self, cx: &WindowContext) -> bool;
fn icon_path(&self) -> &'static str; fn icon_path(&self) -> &'static str;
fn icon_tooltip(&self) -> String; fn icon_tooltip(&self) -> String;
fn icon_label(&self, _: &AppContext) -> Option<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 position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool;
fn set_position(&self, position: DockPosition, cx: &mut WindowContext); fn set_position(&self, position: DockPosition, cx: &mut WindowContext);
fn default_size(&self, cx: &WindowContext) -> f32; fn default_size(&self, cx: &WindowContext) -> f32;
fn can_zoom(&self, cx: &WindowContext) -> bool;
fn icon_path(&self, cx: &WindowContext) -> &'static str; fn icon_path(&self, cx: &WindowContext) -> &'static str;
fn icon_tooltip(&self, cx: &WindowContext) -> String; fn icon_tooltip(&self, cx: &WindowContext) -> String;
fn icon_label(&self, cx: &WindowContext) -> Option<String>; fn icon_label(&self, cx: &WindowContext) -> Option<String>;
@ -61,6 +67,10 @@ where
self.read(cx).default_size(cx) 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 { fn icon_path(&self, cx: &WindowContext) -> &'static str {
self.read(cx).icon_path() self.read(cx).icon_path()
} }
@ -313,9 +323,7 @@ impl View for Dock {
.resizable( .resizable(
self.position.to_resize_handle_side(), self.position.to_resize_handle_side(),
size, size,
|dock: &mut Self, size, cx| { |dock: &mut Self, size, cx| dock.resize_active_panel(size, cx),
dock.resize_active_panel(size, cx);
},
) )
.into_any() .into_any()
} else { } else {
@ -526,6 +534,10 @@ pub(crate) mod test {
} }
} }
fn can_zoom(&self, _cx: &WindowContext) -> bool {
unimplemented!()
}
fn icon_path(&self) -> &'static str { fn icon_path(&self) -> &'static str {
"icons/test_panel.svg" "icons/test_panel.svg"
} }