Remove DeployContextMenu internal action

This commit is contained in:
Antonio Scandurra 2023-04-28 16:51:01 +02:00
parent f65e64829e
commit e1535735b8
2 changed files with 18 additions and 25 deletions

View file

@ -33,7 +33,7 @@ use util::ResultExt;
use std::{fmt::Debug, ops::RangeInclusive}; use std::{fmt::Debug, ops::RangeInclusive};
use std::{mem, ops::Range}; use std::{mem, ops::Range};
use crate::{DeployContextMenu, TerminalView}; use crate::TerminalView;
///The information generated during layout that is nescessary for painting ///The information generated during layout that is nescessary for painting
pub struct LayoutState { pub struct LayoutState {
@ -429,19 +429,20 @@ impl TerminalElement {
), ),
) )
// Context menu // Context menu
.on_click(MouseButton::Right, move |e, _: &mut TerminalView, cx| { .on_click(
MouseButton::Right,
move |event, view: &mut TerminalView, cx| {
let mouse_mode = if let Some(conn_handle) = connection.upgrade(cx) { let mouse_mode = if let Some(conn_handle) = connection.upgrade(cx) {
conn_handle.update(cx, |terminal, _cx| terminal.mouse_mode(e.shift)) conn_handle.update(cx, |terminal, _cx| terminal.mouse_mode(event.shift))
} else { } else {
// If we can't get the model handle, probably can't deploy the context menu // If we can't get the model handle, probably can't deploy the context menu
true true
}; };
if !mouse_mode { if !mouse_mode {
cx.dispatch_action(DeployContextMenu { view.deploy_context_menu(event.position, cx);
position: e.position,
});
} }
}) },
)
.on_move(move |event, _: &mut TerminalView, cx| { .on_move(move |event, _: &mut TerminalView, cx| {
if cx.is_parent_view_focused() { if cx.is_parent_view_focused() {
if let Some(conn_handle) = connection.upgrade(cx) { if let Some(conn_handle) = connection.upgrade(cx) {

View file

@ -9,7 +9,7 @@ use gpui::{
actions, actions,
elements::{AnchorCorner, ChildView, Flex, Label, ParentElement, Stack}, elements::{AnchorCorner, ChildView, Flex, Label, ParentElement, Stack},
geometry::vector::Vector2F, geometry::vector::Vector2F,
impl_actions, impl_internal_actions, impl_actions,
keymap_matcher::{KeymapContext, Keystroke}, keymap_matcher::{KeymapContext, Keystroke},
platform::KeyDownEvent, platform::KeyDownEvent,
AnyElement, AnyViewHandle, AppContext, Element, Entity, ModelHandle, Task, View, ViewContext, 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)] #[derive(Clone, Debug, PartialEq)]
pub struct ScrollTerminal(pub i32); pub struct ScrollTerminal(pub i32);
#[derive(Clone, PartialEq)]
pub struct DeployContextMenu {
pub position: Vector2F,
}
#[derive(Clone, Default, Deserialize, PartialEq)] #[derive(Clone, Default, Deserialize, PartialEq)]
pub struct SendText(String); pub struct SendText(String);
@ -68,8 +63,6 @@ actions!(
impl_actions!(terminal, [SendText, SendKeystroke]); impl_actions!(terminal, [SendText, SendKeystroke]);
impl_internal_actions!(project_panel, [DeployContextMenu]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.add_action(TerminalView::deploy); cx.add_action(TerminalView::deploy);
@ -78,7 +71,6 @@ pub fn init(cx: &mut AppContext) {
//Useful terminal views //Useful terminal views
cx.add_action(TerminalView::send_text); cx.add_action(TerminalView::send_text);
cx.add_action(TerminalView::send_keystroke); cx.add_action(TerminalView::send_keystroke);
cx.add_action(TerminalView::deploy_context_menu);
cx.add_action(TerminalView::copy); cx.add_action(TerminalView::copy);
cx.add_action(TerminalView::paste); cx.add_action(TerminalView::paste);
cx.add_action(TerminalView::clear); cx.add_action(TerminalView::clear);
@ -197,14 +189,14 @@ impl TerminalView {
cx.emit(Event::Wakeup); cx.emit(Event::Wakeup);
} }
pub fn deploy_context_menu(&mut self, action: &DeployContextMenu, cx: &mut ViewContext<Self>) { pub fn deploy_context_menu(&mut self, position: Vector2F, cx: &mut ViewContext<Self>) {
let menu_entries = vec![ let menu_entries = vec![
ContextMenuItem::action("Clear", Clear), ContextMenuItem::action("Clear", Clear),
ContextMenuItem::action("Close", pane::CloseActiveItem), ContextMenuItem::action("Close", pane::CloseActiveItem),
]; ];
self.context_menu.update(cx, |menu, cx| { 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(); cx.notify();