This commit is contained in:
Antonio Scandurra 2022-05-05 15:15:58 +02:00
parent 6b22c47d47
commit 61346f734d
16 changed files with 39 additions and 27 deletions

View file

@ -270,7 +270,7 @@ impl View for AutoUpdateIndicator {
) )
.boxed() .boxed()
}) })
.on_click(|cx| cx.dispatch_action(DismissErrorMessage)) .on_click(|_, cx| cx.dispatch_action(DismissErrorMessage))
.boxed() .boxed()
} }
AutoUpdateStatus::Idle => Empty::new().boxed(), AutoUpdateStatus::Idle => Empty::new().boxed(),

View file

@ -320,7 +320,7 @@ impl ChatPanel {
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(move |cx| { .on_click(move |_, cx| {
let rpc = rpc.clone(); let rpc = rpc.clone();
let this = this.clone(); let this = this.clone();
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {

View file

@ -204,7 +204,7 @@ impl ContactsPanel {
} else { } else {
CursorStyle::Arrow CursorStyle::Arrow
}) })
.on_click(move |cx| { .on_click(move |_, cx| {
if !is_host && !is_guest { if !is_host && !is_guest {
cx.dispatch_global_action(JoinProject { cx.dispatch_global_action(JoinProject {
project_id, project_id,

View file

@ -161,7 +161,7 @@ impl View for DiagnosticIndicator {
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(|cx| cx.dispatch_action(crate::Deploy)) .on_click(|_, cx| cx.dispatch_action(crate::Deploy))
.aligned() .aligned()
.boxed(), .boxed(),
); );
@ -194,7 +194,7 @@ impl View for DiagnosticIndicator {
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(|cx| cx.dispatch_action(GoToNextDiagnostic)) .on_click(|_, cx| cx.dispatch_action(GoToNextDiagnostic))
.boxed(), .boxed(),
); );
} }

View file

@ -1189,7 +1189,7 @@ impl Element for EditorElement {
click_count, click_count,
.. ..
} => self.mouse_down(*position, *alt, *shift, *click_count, layout, paint, cx), } => 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 } => { Event::LeftMouseDragged { position } => {
self.mouse_dragged(*position, layout, paint, cx) self.mouse_dragged(*position, layout, paint, cx)
} }

View file

@ -15,7 +15,7 @@ pub struct MouseEventHandler {
child: ElementBox, child: ElementBox,
cursor_style: Option<CursorStyle>, cursor_style: Option<CursorStyle>,
mouse_down_handler: Option<Box<dyn FnMut(&mut EventContext)>>, mouse_down_handler: Option<Box<dyn FnMut(&mut EventContext)>>,
click_handler: Option<Box<dyn FnMut(&mut EventContext)>>, click_handler: Option<Box<dyn FnMut(usize, &mut EventContext)>>,
drag_handler: Option<Box<dyn FnMut(Vector2F, &mut EventContext)>>, drag_handler: Option<Box<dyn FnMut(Vector2F, &mut EventContext)>>,
padding: Padding, padding: Padding,
} }
@ -57,7 +57,7 @@ impl MouseEventHandler {
self 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.click_handler = Some(Box::new(handler));
self self
} }
@ -151,14 +151,18 @@ impl Element for MouseEventHandler {
handled_in_child handled_in_child
} }
} }
Event::LeftMouseUp { position, .. } => { Event::LeftMouseUp {
position,
click_count,
..
} => {
state.prev_drag_position = None; state.prev_drag_position = None;
if !handled_in_child && state.clicked { if !handled_in_child && state.clicked {
state.clicked = false; state.clicked = false;
cx.notify(); cx.notify();
if let Some(handler) = click_handler { if let Some(handler) = click_handler {
if hit_bounds.contains_point(*position) { if hit_bounds.contains_point(*position) {
handler(cx); handler(*click_count, cx);
} }
} }
true true

View file

@ -28,6 +28,7 @@ pub enum Event {
}, },
LeftMouseUp { LeftMouseUp {
position: Vector2F, position: Vector2F,
click_count: usize,
}, },
LeftMouseDragged { LeftMouseDragged {
position: Vector2F, position: Vector2F,
@ -68,7 +69,7 @@ impl Event {
Event::KeyDown { .. } => None, Event::KeyDown { .. } => None,
Event::ScrollWheel { position, .. } Event::ScrollWheel { position, .. }
| Event::LeftMouseDown { position, .. } | Event::LeftMouseDown { position, .. }
| Event::LeftMouseUp { position } | Event::LeftMouseUp { position, .. }
| Event::LeftMouseDragged { position } | Event::LeftMouseDragged { position }
| Event::RightMouseDown { position, .. } | Event::RightMouseDown { position, .. }
| Event::RightMouseUp { position } | Event::RightMouseUp { position }

View file

@ -129,6 +129,7 @@ impl Event {
native_event.locationInWindow().x as f32, native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32, window_height - native_event.locationInWindow().y as f32,
), ),
click_count: native_event.clickCount() as usize,
}), }),
NSEventType::NSRightMouseDown => { NSEventType::NSRightMouseDown => {
let modifiers = native_event.modifierFlags(); let modifiers = native_event.modifierFlags();

View file

@ -119,7 +119,7 @@ impl View for Select {
.with_style(style.header) .with_style(style.header)
.boxed() .boxed()
}) })
.on_click(move |cx| cx.dispatch_action(ToggleSelect)) .on_click(move |_, cx| cx.dispatch_action(ToggleSelect))
.boxed(), .boxed(),
); );
if self.is_open { 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() .boxed()
})) }))
}, },

View file

@ -69,7 +69,10 @@ struct EntryDetails {
pub struct ToggleExpanded(pub ProjectEntryId); pub struct ToggleExpanded(pub ProjectEntryId);
#[derive(Clone)] #[derive(Clone)]
pub struct Open(pub ProjectEntryId); pub struct Open {
pub entry_id: ProjectEntryId,
pub change_focus: bool,
}
actions!( actions!(
project_panel, project_panel,
@ -339,7 +342,7 @@ impl ProjectPanel {
} }
fn open_entry(&mut self, action: &Open, cx: &mut ViewContext<Self>) { fn open_entry(&mut self, action: &Open, cx: &mut ViewContext<Self>) {
cx.emit(Event::OpenedEntry(action.0)); cx.emit(Event::OpenedEntry(action.entry_id));
} }
fn add_file(&mut self, _: &AddFile, cx: &mut ViewContext<Self>) { fn add_file(&mut self, _: &AddFile, cx: &mut ViewContext<Self>) {
@ -799,11 +802,14 @@ impl ProjectPanel {
.with_padding_left(padding) .with_padding_left(padding)
.boxed() .boxed()
}) })
.on_click(move |cx| { .on_click(move |click_count, cx| {
if kind == EntryKind::Dir { if kind == EntryKind::Dir {
cx.dispatch_action(ToggleExpanded(entry_id)) cx.dispatch_action(ToggleExpanded(entry_id))
} else { } else {
cx.dispatch_action(Open(entry_id)) cx.dispatch_action(Open {
entry_id,
change_focus: click_count > 1,
})
} }
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)

View file

@ -292,7 +292,7 @@ impl BufferSearchBar {
.with_style(style.container) .with_style(style.container)
.boxed() .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) .with_cursor_style(CursorStyle::PointingHand)
.boxed() .boxed()
} }
@ -316,7 +316,7 @@ impl BufferSearchBar {
.with_style(style.container) .with_style(style.container)
.boxed() .boxed()
}) })
.on_click(move |cx| match direction { .on_click(move |_, cx| match direction {
Direction::Prev => cx.dispatch_action(SelectPrevMatch), Direction::Prev => cx.dispatch_action(SelectPrevMatch),
Direction::Next => cx.dispatch_action(SelectNextMatch), Direction::Next => cx.dispatch_action(SelectNextMatch),
}) })

View file

@ -666,7 +666,7 @@ impl ProjectSearchBar {
.with_style(style.container) .with_style(style.container)
.boxed() .boxed()
}) })
.on_click(move |cx| match direction { .on_click(move |_, cx| match direction {
Direction::Prev => cx.dispatch_action(SelectPrevMatch), Direction::Prev => cx.dispatch_action(SelectPrevMatch),
Direction::Next => cx.dispatch_action(SelectNextMatch), Direction::Next => cx.dispatch_action(SelectNextMatch),
}) })
@ -693,7 +693,7 @@ impl ProjectSearchBar {
.with_style(style.container) .with_style(style.container)
.boxed() .boxed()
}) })
.on_click(move |cx| cx.dispatch_action(ToggleSearchOption(option))) .on_click(move |_, cx| cx.dispatch_action(ToggleSearchOption(option)))
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.boxed() .boxed()
} }

View file

@ -168,7 +168,7 @@ impl View for LspStatus {
self.failed.join(", "), self.failed.join(", "),
if self.failed.len() > 1 { "s" } else { "" } 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 { } else {
return Empty::new().boxed(); return Empty::new().boxed();
} }

View file

@ -737,7 +737,7 @@ impl Pane {
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click({ .on_click({
let pane = pane.clone(); let pane = pane.clone();
move |cx| { move |_, cx| {
cx.dispatch_action(CloseItem { cx.dispatch_action(CloseItem {
item_id, item_id,
pane: pane.clone(), pane: pane.clone(),

View file

@ -203,7 +203,7 @@ impl View for SidebarButtons {
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(move |cx| { .on_click(move |_, cx| {
cx.dispatch_action(ToggleSidebarItem { cx.dispatch_action(ToggleSidebarItem {
side, side,
item_index: ix, item_index: ix,

View file

@ -1584,7 +1584,7 @@ impl Workspace {
.with_style(style.container) .with_style(style.container)
.boxed() .boxed()
}) })
.on_click(|cx| cx.dispatch_action(Authenticate)) .on_click(|_, cx| cx.dispatch_action(Authenticate))
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.aligned() .aligned()
.boxed(), .boxed(),
@ -1635,7 +1635,7 @@ impl Workspace {
if let Some(peer_id) = peer_id { if let Some(peer_id) = peer_id {
MouseEventHandler::new::<ToggleFollow, _, _>(replica_id.into(), cx, move |_, _| content) MouseEventHandler::new::<ToggleFollow, _, _>(replica_id.into(), cx, move |_, _| content)
.with_cursor_style(CursorStyle::PointingHand) .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() .boxed()
} else { } else {
content content
@ -1667,7 +1667,7 @@ impl Workspace {
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(|cx| cx.dispatch_action(ToggleShare)) .on_click(|_, cx| cx.dispatch_action(ToggleShare))
.boxed(), .boxed(),
) )
} else { } else {