From e1535735b852b29e3deb81008552135a64d71696 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 28 Apr 2023 16:51:01 +0200 Subject: [PATCH] Remove `DeployContextMenu` internal action --- crates/terminal_view/src/terminal_element.rs | 29 ++++++++++---------- crates/terminal_view/src/terminal_view.rs | 14 ++-------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 55e10a3195..392b050f43 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -33,7 +33,7 @@ use util::ResultExt; use std::{fmt::Debug, ops::RangeInclusive}; use std::{mem, ops::Range}; -use crate::{DeployContextMenu, TerminalView}; +use crate::TerminalView; ///The information generated during layout that is nescessary for painting pub struct LayoutState { @@ -429,19 +429,20 @@ impl TerminalElement { ), ) // Context menu - .on_click(MouseButton::Right, move |e, _: &mut TerminalView, cx| { - let mouse_mode = if let Some(conn_handle) = connection.upgrade(cx) { - conn_handle.update(cx, |terminal, _cx| terminal.mouse_mode(e.shift)) - } else { - // If we can't get the model handle, probably can't deploy the context menu - true - }; - if !mouse_mode { - cx.dispatch_action(DeployContextMenu { - position: e.position, - }); - } - }) + .on_click( + MouseButton::Right, + move |event, view: &mut TerminalView, cx| { + let mouse_mode = if let Some(conn_handle) = connection.upgrade(cx) { + conn_handle.update(cx, |terminal, _cx| terminal.mouse_mode(event.shift)) + } else { + // If we can't get the model handle, probably can't deploy the context menu + true + }; + if !mouse_mode { + view.deploy_context_menu(event.position, cx); + } + }, + ) .on_move(move |event, _: &mut TerminalView, cx| { if cx.is_parent_view_focused() { if let Some(conn_handle) = connection.upgrade(cx) { diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index b6916ee8e6..5e04fc9825 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -9,7 +9,7 @@ use gpui::{ actions, elements::{AnchorCorner, ChildView, Flex, Label, ParentElement, Stack}, geometry::vector::Vector2F, - impl_actions, impl_internal_actions, + impl_actions, keymap_matcher::{KeymapContext, Keystroke}, platform::KeyDownEvent, AnyElement, AnyViewHandle, AppContext, Element, Entity, ModelHandle, Task, View, ViewContext, @@ -50,11 +50,6 @@ const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500); #[derive(Clone, Debug, PartialEq)] pub struct ScrollTerminal(pub i32); -#[derive(Clone, PartialEq)] -pub struct DeployContextMenu { - pub position: Vector2F, -} - #[derive(Clone, Default, Deserialize, PartialEq)] pub struct SendText(String); @@ -68,8 +63,6 @@ actions!( impl_actions!(terminal, [SendText, SendKeystroke]); -impl_internal_actions!(project_panel, [DeployContextMenu]); - pub fn init(cx: &mut AppContext) { cx.add_action(TerminalView::deploy); @@ -78,7 +71,6 @@ pub fn init(cx: &mut AppContext) { //Useful terminal views cx.add_action(TerminalView::send_text); cx.add_action(TerminalView::send_keystroke); - cx.add_action(TerminalView::deploy_context_menu); cx.add_action(TerminalView::copy); cx.add_action(TerminalView::paste); cx.add_action(TerminalView::clear); @@ -197,14 +189,14 @@ impl TerminalView { cx.emit(Event::Wakeup); } - pub fn deploy_context_menu(&mut self, action: &DeployContextMenu, cx: &mut ViewContext) { + pub fn deploy_context_menu(&mut self, position: Vector2F, cx: &mut ViewContext) { let menu_entries = vec![ ContextMenuItem::action("Clear", Clear), ContextMenuItem::action("Close", pane::CloseActiveItem), ]; self.context_menu.update(cx, |menu, cx| { - menu.show(action.position, AnchorCorner::TopLeft, menu_entries, cx) + menu.show(position, AnchorCorner::TopLeft, menu_entries, cx) }); cx.notify();