This commit is contained in:
Antonio Scandurra
2023-12-05 16:49:36 +01:00
parent 09db455db2
commit ede86d9187
16 changed files with 5405 additions and 41 deletions
+7 -16
View File
@@ -26,6 +26,7 @@ pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
fn size(&self, cx: &WindowContext) -> f32;
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>);
// todo!("We should have a icon tooltip method, rather than using persistant_name")
fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
fn toggle_action(&self) -> Box<dyn Action>;
fn icon_label(&self, _: &WindowContext) -> Option<String> {
@@ -36,7 +37,6 @@ pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
}
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
fn has_focus(&self, cx: &WindowContext) -> bool;
}
pub trait PanelHandle: Send + Sync {
@@ -53,7 +53,6 @@ pub trait PanelHandle: Send + Sync {
fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action>;
fn icon_label(&self, cx: &WindowContext) -> Option<String>;
fn has_focus(&self, cx: &WindowContext) -> bool;
fn focus_handle(&self, cx: &AppContext) -> FocusHandle;
fn to_any(&self) -> AnyView;
}
@@ -114,10 +113,6 @@ where
self.read(cx).icon_label(cx)
}
fn has_focus(&self, cx: &WindowContext) -> bool {
self.read(cx).has_focus(cx)
}
fn to_any(&self) -> AnyView {
self.clone().into()
}
@@ -319,7 +314,7 @@ impl Dock {
}
PanelEvent::ZoomIn => {
this.set_panel_zoomed(&panel.to_any(), true, cx);
if !panel.has_focus(cx) {
if !panel.focus_handle(cx).contains_focused(cx) {
cx.focus_view(&panel);
}
workspace
@@ -760,7 +755,7 @@ pub mod test {
pub position: DockPosition,
pub zoomed: bool,
pub active: bool,
pub has_focus: bool,
pub focus_handle: FocusHandle,
pub size: f32,
}
actions!(ToggleTestPanel);
@@ -768,12 +763,12 @@ pub mod test {
impl EventEmitter<PanelEvent> for TestPanel {}
impl TestPanel {
pub fn new(position: DockPosition) -> Self {
pub fn new(position: DockPosition, cx: &mut WindowContext) -> Self {
Self {
position,
zoomed: false,
active: false,
has_focus: false,
focus_handle: cx.focus_handle(),
size: 300.,
}
}
@@ -832,15 +827,11 @@ pub mod test {
fn set_active(&mut self, active: bool, _cx: &mut ViewContext<Self>) {
self.active = active;
}
fn has_focus(&self, _cx: &WindowContext) -> bool {
self.has_focus
}
}
impl FocusableView for TestPanel {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
unimplemented!()
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
self.focus_handle.clone()
}
}
}
+6 -4
View File
@@ -65,7 +65,7 @@ use std::{
time::Duration,
};
use theme::{ActiveTheme, ThemeSettings};
pub use toolbar::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
pub use toolbar::{Toolbar, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
pub use ui;
use util::ResultExt;
use uuid::Uuid;
@@ -1542,7 +1542,7 @@ impl Workspace {
if let Some(active_panel) = dock.active_panel() {
if was_visible {
if active_panel.has_focus(cx) {
if active_panel.focus_handle(cx).contains_focused(cx) {
focus_center = true;
}
} else {
@@ -1589,7 +1589,9 @@ impl Workspace {
/// Focus the panel of the given type if it isn't already focused. If it is
/// already focused, then transfer focus back to the workspace center.
pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {
self.focus_or_unfocus_panel::<T>(cx, |panel, cx| !panel.has_focus(cx));
self.focus_or_unfocus_panel::<T>(cx, |panel, cx| {
!panel.focus_handle(cx).contains_focused(cx)
});
}
/// Focus or unfocus the given panel type, depending on the given callback.
@@ -1681,7 +1683,7 @@ impl Workspace {
if Some(dock.position()) != dock_to_reveal {
if let Some(panel) = dock.active_panel() {
if panel.is_zoomed(cx) {
focus_center |= panel.has_focus(cx);
focus_center |= panel.focus_handle(cx).contains_focused(cx);
dock.set_open(false, cx);
}
}