mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-05 18:25:57 +00:00
Merge pull request #2271 from zed-industries/petros/z-278-lock-pop-up-to-the-terminal-button
A new approach for positioning pop-up menus tied to an icon/button
This commit is contained in:
commit
c6f27903cc
1 changed files with 24 additions and 16 deletions
|
@ -1,8 +1,8 @@
|
||||||
use context_menu::{ContextMenu, ContextMenuItem};
|
use context_menu::{ContextMenu, ContextMenuItem};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::*, geometry::vector::Vector2F, impl_internal_actions, CursorStyle, Element,
|
elements::*, impl_internal_actions, CursorStyle, Element, ElementBox, Entity, MouseButton,
|
||||||
ElementBox, Entity, MouseButton, MutableAppContext, RenderContext, View, ViewContext,
|
MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakModelHandle,
|
||||||
ViewHandle, WeakModelHandle, WeakViewHandle,
|
WeakViewHandle,
|
||||||
};
|
};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
|
@ -11,16 +11,15 @@ use workspace::{dock::FocusDock, item::ItemHandle, NewTerminal, StatusItemView,
|
||||||
|
|
||||||
use crate::TerminalView;
|
use crate::TerminalView;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct DeployTerminalMenu;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct FocusTerminal {
|
pub struct FocusTerminal {
|
||||||
terminal_handle: WeakModelHandle<Terminal>,
|
terminal_handle: WeakModelHandle<Terminal>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
//actions!(terminal, [DeployTerminalMenu]);
|
||||||
pub struct DeployTerminalMenu {
|
|
||||||
position: Vector2F,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_internal_actions!(terminal, [FocusTerminal, DeployTerminalMenu]);
|
impl_internal_actions!(terminal, [FocusTerminal, DeployTerminalMenu]);
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
|
@ -82,11 +81,9 @@ impl View for TerminalButton {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.on_click(MouseButton::Left, move |e, cx| {
|
.on_click(MouseButton::Left, move |_, cx| {
|
||||||
if has_terminals {
|
if has_terminals {
|
||||||
cx.dispatch_action(DeployTerminalMenu {
|
cx.dispatch_action(DeployTerminalMenu);
|
||||||
position: e.region.upper_right(),
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if !active {
|
if !active {
|
||||||
cx.dispatch_action(FocusDock);
|
cx.dispatch_action(FocusDock);
|
||||||
|
@ -102,7 +99,13 @@ impl View for TerminalButton {
|
||||||
)
|
)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_child(ChildView::new(&self.popup_menu, cx).boxed())
|
.with_child(
|
||||||
|
ChildView::new(&self.popup_menu, cx)
|
||||||
|
.aligned()
|
||||||
|
.top()
|
||||||
|
.right()
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +118,7 @@ impl TerminalButton {
|
||||||
workspace: workspace.downgrade(),
|
workspace: workspace.downgrade(),
|
||||||
popup_menu: cx.add_view(|cx| {
|
popup_menu: cx.add_view(|cx| {
|
||||||
let mut menu = ContextMenu::new(cx);
|
let mut menu = ContextMenu::new(cx);
|
||||||
menu.set_position_mode(OverlayPositionMode::Window);
|
menu.set_position_mode(OverlayPositionMode::Local);
|
||||||
menu
|
menu
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -123,7 +126,7 @@ impl TerminalButton {
|
||||||
|
|
||||||
pub fn deploy_terminal_menu(
|
pub fn deploy_terminal_menu(
|
||||||
&mut self,
|
&mut self,
|
||||||
action: &DeployTerminalMenu,
|
_action: &DeployTerminalMenu,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let mut menu_options = vec![ContextMenuItem::item("New Terminal", NewTerminal)];
|
let mut menu_options = vec![ContextMenuItem::item("New Terminal", NewTerminal)];
|
||||||
|
@ -149,7 +152,12 @@ impl TerminalButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.popup_menu.update(cx, |menu, cx| {
|
self.popup_menu.update(cx, |menu, cx| {
|
||||||
menu.show(action.position, AnchorCorner::BottomRight, menu_options, cx);
|
menu.show(
|
||||||
|
Default::default(),
|
||||||
|
AnchorCorner::BottomRight,
|
||||||
|
menu_options,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue