From 61346f734d1fc2fc1b45e3a9609f8620cdee8bc1 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 5 May 2022 15:15:58 +0200 Subject: [PATCH] WIP --- crates/auto_update/src/auto_update.rs | 2 +- crates/chat_panel/src/chat_panel.rs | 2 +- crates/contacts_panel/src/contacts_panel.rs | 2 +- crates/diagnostics/src/items.rs | 4 ++-- crates/editor/src/element.rs | 2 +- crates/gpui/src/elements/mouse_event_handler.rs | 12 ++++++++---- crates/gpui/src/platform/event.rs | 3 ++- crates/gpui/src/platform/mac/event.rs | 1 + crates/gpui/src/views/select.rs | 4 ++-- crates/project_panel/src/project_panel.rs | 14 ++++++++++---- crates/search/src/buffer_search.rs | 4 ++-- crates/search/src/project_search.rs | 4 ++-- crates/workspace/src/lsp_status.rs | 2 +- crates/workspace/src/pane.rs | 2 +- crates/workspace/src/sidebar.rs | 2 +- crates/workspace/src/workspace.rs | 6 +++--- 16 files changed, 39 insertions(+), 27 deletions(-) diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index f722167b6f..499b3ed99d 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -270,7 +270,7 @@ impl View for AutoUpdateIndicator { ) .boxed() }) - .on_click(|cx| cx.dispatch_action(DismissErrorMessage)) + .on_click(|_, cx| cx.dispatch_action(DismissErrorMessage)) .boxed() } AutoUpdateStatus::Idle => Empty::new().boxed(), diff --git a/crates/chat_panel/src/chat_panel.rs b/crates/chat_panel/src/chat_panel.rs index 415ff6187e..bb835c6640 100644 --- a/crates/chat_panel/src/chat_panel.rs +++ b/crates/chat_panel/src/chat_panel.rs @@ -320,7 +320,7 @@ impl ChatPanel { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(move |cx| { + .on_click(move |_, cx| { let rpc = rpc.clone(); let this = this.clone(); cx.spawn(|mut cx| async move { diff --git a/crates/contacts_panel/src/contacts_panel.rs b/crates/contacts_panel/src/contacts_panel.rs index 45b5f69b5e..171b419496 100644 --- a/crates/contacts_panel/src/contacts_panel.rs +++ b/crates/contacts_panel/src/contacts_panel.rs @@ -204,7 +204,7 @@ impl ContactsPanel { } else { CursorStyle::Arrow }) - .on_click(move |cx| { + .on_click(move |_, cx| { if !is_host && !is_guest { cx.dispatch_global_action(JoinProject { project_id, diff --git a/crates/diagnostics/src/items.rs b/crates/diagnostics/src/items.rs index 39b5437a6a..ef99cbf5a8 100644 --- a/crates/diagnostics/src/items.rs +++ b/crates/diagnostics/src/items.rs @@ -161,7 +161,7 @@ impl View for DiagnosticIndicator { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(|cx| cx.dispatch_action(crate::Deploy)) + .on_click(|_, cx| cx.dispatch_action(crate::Deploy)) .aligned() .boxed(), ); @@ -194,7 +194,7 @@ impl View for DiagnosticIndicator { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(|cx| cx.dispatch_action(GoToNextDiagnostic)) + .on_click(|_, cx| cx.dispatch_action(GoToNextDiagnostic)) .boxed(), ); } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index f4453774f7..a04d27a8bb 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1189,7 +1189,7 @@ impl Element for EditorElement { click_count, .. } => self.mouse_down(*position, *alt, *shift, *click_count, layout, paint, cx), - Event::LeftMouseUp { position } => self.mouse_up(*position, cx), + Event::LeftMouseUp { position, .. } => self.mouse_up(*position, cx), Event::LeftMouseDragged { position } => { self.mouse_dragged(*position, layout, paint, cx) } diff --git a/crates/gpui/src/elements/mouse_event_handler.rs b/crates/gpui/src/elements/mouse_event_handler.rs index 12166d45b5..1ee7c6cbb5 100644 --- a/crates/gpui/src/elements/mouse_event_handler.rs +++ b/crates/gpui/src/elements/mouse_event_handler.rs @@ -15,7 +15,7 @@ pub struct MouseEventHandler { child: ElementBox, cursor_style: Option, mouse_down_handler: Option>, - click_handler: Option>, + click_handler: Option>, drag_handler: Option>, padding: Padding, } @@ -57,7 +57,7 @@ impl MouseEventHandler { self } - pub fn on_click(mut self, handler: impl FnMut(&mut EventContext) + 'static) -> Self { + pub fn on_click(mut self, handler: impl FnMut(usize, &mut EventContext) + 'static) -> Self { self.click_handler = Some(Box::new(handler)); self } @@ -151,14 +151,18 @@ impl Element for MouseEventHandler { handled_in_child } } - Event::LeftMouseUp { position, .. } => { + Event::LeftMouseUp { + position, + click_count, + .. + } => { state.prev_drag_position = None; if !handled_in_child && state.clicked { state.clicked = false; cx.notify(); if let Some(handler) = click_handler { if hit_bounds.contains_point(*position) { - handler(cx); + handler(*click_count, cx); } } true diff --git a/crates/gpui/src/platform/event.rs b/crates/gpui/src/platform/event.rs index fe353fed4c..b32ab952c7 100644 --- a/crates/gpui/src/platform/event.rs +++ b/crates/gpui/src/platform/event.rs @@ -28,6 +28,7 @@ pub enum Event { }, LeftMouseUp { position: Vector2F, + click_count: usize, }, LeftMouseDragged { position: Vector2F, @@ -68,7 +69,7 @@ impl Event { Event::KeyDown { .. } => None, Event::ScrollWheel { position, .. } | Event::LeftMouseDown { position, .. } - | Event::LeftMouseUp { position } + | Event::LeftMouseUp { position, .. } | Event::LeftMouseDragged { position } | Event::RightMouseDown { position, .. } | Event::RightMouseUp { position } diff --git a/crates/gpui/src/platform/mac/event.rs b/crates/gpui/src/platform/mac/event.rs index 7170bd2fd5..651805370c 100644 --- a/crates/gpui/src/platform/mac/event.rs +++ b/crates/gpui/src/platform/mac/event.rs @@ -129,6 +129,7 @@ impl Event { native_event.locationInWindow().x as f32, window_height - native_event.locationInWindow().y as f32, ), + click_count: native_event.clickCount() as usize, }), NSEventType::NSRightMouseDown => { let modifiers = native_event.modifierFlags(); diff --git a/crates/gpui/src/views/select.rs b/crates/gpui/src/views/select.rs index 10cd0cd5a2..d5d2105c3f 100644 --- a/crates/gpui/src/views/select.rs +++ b/crates/gpui/src/views/select.rs @@ -119,7 +119,7 @@ impl View for Select { .with_style(style.header) .boxed() }) - .on_click(move |cx| cx.dispatch_action(ToggleSelect)) + .on_click(move |_, cx| cx.dispatch_action(ToggleSelect)) .boxed(), ); if self.is_open { @@ -153,7 +153,7 @@ impl View for Select { ) }, ) - .on_click(move |cx| cx.dispatch_action(SelectItem(ix))) + .on_click(move |_, cx| cx.dispatch_action(SelectItem(ix))) .boxed() })) }, diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 6bb4f640ee..220278fd1d 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -69,7 +69,10 @@ struct EntryDetails { pub struct ToggleExpanded(pub ProjectEntryId); #[derive(Clone)] -pub struct Open(pub ProjectEntryId); +pub struct Open { + pub entry_id: ProjectEntryId, + pub change_focus: bool, +} actions!( project_panel, @@ -339,7 +342,7 @@ impl ProjectPanel { } fn open_entry(&mut self, action: &Open, cx: &mut ViewContext) { - cx.emit(Event::OpenedEntry(action.0)); + cx.emit(Event::OpenedEntry(action.entry_id)); } fn add_file(&mut self, _: &AddFile, cx: &mut ViewContext) { @@ -799,11 +802,14 @@ impl ProjectPanel { .with_padding_left(padding) .boxed() }) - .on_click(move |cx| { + .on_click(move |click_count, cx| { if kind == EntryKind::Dir { cx.dispatch_action(ToggleExpanded(entry_id)) } else { - cx.dispatch_action(Open(entry_id)) + cx.dispatch_action(Open { + entry_id, + change_focus: click_count > 1, + }) } }) .with_cursor_style(CursorStyle::PointingHand) diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index d1f17608f2..549edf89e7 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -292,7 +292,7 @@ impl BufferSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |cx| cx.dispatch_action(ToggleSearchOption(search_option))) + .on_click(move |_, cx| cx.dispatch_action(ToggleSearchOption(search_option))) .with_cursor_style(CursorStyle::PointingHand) .boxed() } @@ -316,7 +316,7 @@ impl BufferSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |cx| match direction { + .on_click(move |_, cx| match direction { Direction::Prev => cx.dispatch_action(SelectPrevMatch), Direction::Next => cx.dispatch_action(SelectNextMatch), }) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index d3b3520a53..cbd373c468 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -666,7 +666,7 @@ impl ProjectSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |cx| match direction { + .on_click(move |_, cx| match direction { Direction::Prev => cx.dispatch_action(SelectPrevMatch), Direction::Next => cx.dispatch_action(SelectNextMatch), }) @@ -693,7 +693,7 @@ impl ProjectSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |cx| cx.dispatch_action(ToggleSearchOption(option))) + .on_click(move |_, cx| cx.dispatch_action(ToggleSearchOption(option))) .with_cursor_style(CursorStyle::PointingHand) .boxed() } diff --git a/crates/workspace/src/lsp_status.rs b/crates/workspace/src/lsp_status.rs index ddc6d89308..f58e0b973e 100644 --- a/crates/workspace/src/lsp_status.rs +++ b/crates/workspace/src/lsp_status.rs @@ -168,7 +168,7 @@ impl View for LspStatus { self.failed.join(", "), if self.failed.len() > 1 { "s" } else { "" } ); - handler = Some(|cx: &mut EventContext| cx.dispatch_action(DismissErrorMessage)); + handler = Some(|_, cx: &mut EventContext| cx.dispatch_action(DismissErrorMessage)); } else { return Empty::new().boxed(); } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index a992897c11..94fe7c3a42 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -737,7 +737,7 @@ impl Pane { .with_cursor_style(CursorStyle::PointingHand) .on_click({ let pane = pane.clone(); - move |cx| { + move |_, cx| { cx.dispatch_action(CloseItem { item_id, pane: pane.clone(), diff --git a/crates/workspace/src/sidebar.rs b/crates/workspace/src/sidebar.rs index 2f13469cec..bc7314e732 100644 --- a/crates/workspace/src/sidebar.rs +++ b/crates/workspace/src/sidebar.rs @@ -203,7 +203,7 @@ impl View for SidebarButtons { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(move |cx| { + .on_click(move |_, cx| { cx.dispatch_action(ToggleSidebarItem { side, item_index: ix, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index d072c51550..fe18fcb95a 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1584,7 +1584,7 @@ impl Workspace { .with_style(style.container) .boxed() }) - .on_click(|cx| cx.dispatch_action(Authenticate)) + .on_click(|_, cx| cx.dispatch_action(Authenticate)) .with_cursor_style(CursorStyle::PointingHand) .aligned() .boxed(), @@ -1635,7 +1635,7 @@ impl Workspace { if let Some(peer_id) = peer_id { MouseEventHandler::new::(replica_id.into(), cx, move |_, _| content) .with_cursor_style(CursorStyle::PointingHand) - .on_click(move |cx| cx.dispatch_action(ToggleFollow(peer_id))) + .on_click(move |_, cx| cx.dispatch_action(ToggleFollow(peer_id))) .boxed() } else { content @@ -1667,7 +1667,7 @@ impl Workspace { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(|cx| cx.dispatch_action(ToggleShare)) + .on_click(|_, cx| cx.dispatch_action(ToggleShare)) .boxed(), ) } else {