From e44536344ad4bde224e4745e42964b4326d8ba94 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Mon, 22 Aug 2022 16:49:14 -0700 Subject: [PATCH] Removed EventHandler from workspace in favor of mouse event handler --- crates/gpui/src/elements/mouse_event_handler.rs | 5 +++++ crates/gpui/src/presenter.rs | 2 -- crates/gpui/src/scene/mouse_region.rs | 4 ++-- crates/workspace/src/workspace.rs | 12 ++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/gpui/src/elements/mouse_event_handler.rs b/crates/gpui/src/elements/mouse_event_handler.rs index 52e701b051..78dbfd65b7 100644 --- a/crates/gpui/src/elements/mouse_event_handler.rs +++ b/crates/gpui/src/elements/mouse_event_handler.rs @@ -44,6 +44,11 @@ impl MouseEventHandler { self } + pub fn capture_all(mut self) -> Self { + self.handlers = HandlerSet::capture_all(); + self + } + pub fn on_move( mut self, handler: impl Fn(MoveRegionEvent, &mut EventContext) + 'static, diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 42dac6d207..d3acaf72e5 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -79,7 +79,6 @@ impl Presenter { self.rendered_views.remove(view_id); } for view_id in &invalidation.updated { - dbg!(view_id); self.rendered_views.insert( *view_id, cx.render_view(RenderParams { @@ -152,7 +151,6 @@ impl Presenter { if cx.window_is_active(self.window_id) { if let Some(event) = self.last_mouse_moved_event.clone() { - println!("Redispatching mouse moved"); self.dispatch_event(event, true, cx); } } diff --git a/crates/gpui/src/scene/mouse_region.rs b/crates/gpui/src/scene/mouse_region.rs index 5919d09180..9a73c499f6 100644 --- a/crates/gpui/src/scene/mouse_region.rs +++ b/crates/gpui/src/scene/mouse_region.rs @@ -46,7 +46,7 @@ impl MouseRegion { view_id, discriminant, bounds, - handlers: HandlerSet::handle_all(), + handlers: HandlerSet::capture_all(), } } @@ -129,7 +129,7 @@ pub struct HandlerSet { } impl HandlerSet { - pub fn handle_all() -> Self { + pub fn capture_all() -> Self { #[allow(clippy::type_complexity)] let mut set: HashMap< (Discriminant, Option), diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index fa81cd9f11..c71f21ccdc 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2071,11 +2071,11 @@ impl Workspace { } } - fn render_disconnected_overlay(&self, cx: &AppContext) -> Option { + fn render_disconnected_overlay(&self, cx: &mut RenderContext) -> Option { if self.project.read(cx).is_read_only() { - let theme = &cx.global::().theme; Some( - EventHandler::new( + MouseEventHandler::new::(0, cx, |_, cx| { + let theme = &cx.global::().theme; Label::new( "Your connection to the remote project has been lost.".to_string(), theme.workspace.disconnected_overlay.text.clone(), @@ -2083,9 +2083,9 @@ impl Workspace { .aligned() .contained() .with_style(theme.workspace.disconnected_overlay.container) - .boxed(), - ) - .capture_all::(0) + .boxed() + }) + .capture_all() .boxed(), ) } else {