Remove internal actions from menu crate

This commit is contained in:
Antonio Scandurra 2023-04-27 14:26:09 +02:00
parent 816eb06a7b
commit 15d83d40b0
2 changed files with 4 additions and 11 deletions

View File

@ -1,6 +1,3 @@
#[derive(Clone, PartialEq)]
pub struct SelectIndex(pub usize);
gpui::actions!( gpui::actions!(
menu, menu,
[ [
@ -12,5 +9,3 @@ gpui::actions!(
SelectLast SelectLast
] ]
); );
gpui::impl_internal_actions!(menu, [SelectIndex]);

View File

@ -7,7 +7,7 @@ use gpui::{
AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext, AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext,
ViewHandle, ViewHandle,
}; };
use menu::{Cancel, Confirm, SelectFirst, SelectIndex, SelectLast, SelectNext, SelectPrev}; use menu::{Cancel, Confirm, SelectFirst, SelectLast, SelectNext, SelectPrev};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{cmp, sync::Arc}; use std::{cmp, sync::Arc};
use util::ResultExt; use util::ResultExt;
@ -104,8 +104,8 @@ impl<D: PickerDelegate> View for Picker<D> {
// Capture mouse events // Capture mouse events
.on_down(MouseButton::Left, |_, _, _| {}) .on_down(MouseButton::Left, |_, _, _| {})
.on_up(MouseButton::Left, |_, _, _| {}) .on_up(MouseButton::Left, |_, _, _| {})
.on_click(MouseButton::Left, move |_, _, cx| { .on_click(MouseButton::Left, move |_, picker, cx| {
cx.dispatch_action(SelectIndex(ix)) picker.select_index(ix, cx);
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.into_any() .into_any()
@ -151,7 +151,6 @@ impl<D: PickerDelegate> Picker<D> {
cx.add_action(Self::select_last); cx.add_action(Self::select_last);
cx.add_action(Self::select_next); cx.add_action(Self::select_next);
cx.add_action(Self::select_prev); cx.add_action(Self::select_prev);
cx.add_action(Self::select_index);
cx.add_action(Self::confirm); cx.add_action(Self::confirm);
cx.add_action(Self::cancel); cx.add_action(Self::cancel);
} }
@ -265,8 +264,7 @@ impl<D: PickerDelegate> Picker<D> {
cx.notify(); cx.notify();
} }
pub fn select_index(&mut self, action: &SelectIndex, cx: &mut ViewContext<Self>) { pub fn select_index(&mut self, index: usize, cx: &mut ViewContext<Self>) {
let index = action.0;
if self.delegate.match_count() > 0 { if self.delegate.match_count() > 0 {
self.confirmed = true; self.confirmed = true;
self.delegate.set_selected_index(index, cx); self.delegate.set_selected_index(index, cx);