From 15d83d40b0076b6c713da00db975ed1bf1c1fdd2 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 Apr 2023 14:26:09 +0200 Subject: [PATCH] Remove internal actions from `menu` crate --- crates/menu/src/menu.rs | 5 ----- crates/picker/src/picker.rs | 10 ++++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/crates/menu/src/menu.rs b/crates/menu/src/menu.rs index 227e6c6c28..81716028b9 100644 --- a/crates/menu/src/menu.rs +++ b/crates/menu/src/menu.rs @@ -1,6 +1,3 @@ -#[derive(Clone, PartialEq)] -pub struct SelectIndex(pub usize); - gpui::actions!( menu, [ @@ -12,5 +9,3 @@ gpui::actions!( SelectLast ] ); - -gpui::impl_internal_actions!(menu, [SelectIndex]); diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 83717af0fd..62ffd417fe 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -7,7 +7,7 @@ use gpui::{ AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext, ViewHandle, }; -use menu::{Cancel, Confirm, SelectFirst, SelectIndex, SelectLast, SelectNext, SelectPrev}; +use menu::{Cancel, Confirm, SelectFirst, SelectLast, SelectNext, SelectPrev}; use parking_lot::Mutex; use std::{cmp, sync::Arc}; use util::ResultExt; @@ -104,8 +104,8 @@ impl View for Picker { // Capture mouse events .on_down(MouseButton::Left, |_, _, _| {}) .on_up(MouseButton::Left, |_, _, _| {}) - .on_click(MouseButton::Left, move |_, _, cx| { - cx.dispatch_action(SelectIndex(ix)) + .on_click(MouseButton::Left, move |_, picker, cx| { + picker.select_index(ix, cx); }) .with_cursor_style(CursorStyle::PointingHand) .into_any() @@ -151,7 +151,6 @@ impl Picker { cx.add_action(Self::select_last); cx.add_action(Self::select_next); cx.add_action(Self::select_prev); - cx.add_action(Self::select_index); cx.add_action(Self::confirm); cx.add_action(Self::cancel); } @@ -265,8 +264,7 @@ impl Picker { cx.notify(); } - pub fn select_index(&mut self, action: &SelectIndex, cx: &mut ViewContext) { - let index = action.0; + pub fn select_index(&mut self, index: usize, cx: &mut ViewContext) { if self.delegate.match_count() > 0 { self.confirmed = true; self.delegate.set_selected_index(index, cx);