Removed EventHandler from workspace in favor of mouse event handler

K Simmons created

Change summary

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

Detailed changes

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,

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);
                 }
             }

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<MouseRegionEvent>, Option<MouseButton>),

crates/workspace/src/workspace.rs 🔗

@@ -2071,11 +2071,11 @@ impl Workspace {
         }
     }
 
-    fn render_disconnected_overlay(&self, cx: &AppContext) -> Option<ElementBox> {
+    fn render_disconnected_overlay(&self, cx: &mut RenderContext<Workspace>) -> Option<ElementBox> {
         if self.project.read(cx).is_read_only() {
-            let theme = &cx.global::<Settings>().theme;
             Some(
-                EventHandler::new(
+                MouseEventHandler::new::<Workspace, _, _>(0, cx, |_, cx| {
+                    let theme = &cx.global::<Settings>().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::<Self>(0)
+                    .boxed()
+                })
+                .capture_all()
                 .boxed(),
             )
         } else {