Show a pop up menu for terminals
Co-Authored-By: Joseph T. Lyons <19867440+JosephTLyons@users.noreply.github.com> Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
ee154feda4
commit
caa6a75238
4 changed files with 111 additions and 62 deletions
|
@ -58,6 +58,10 @@ impl Project {
|
||||||
terminal
|
terminal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn local_terminal_handles(&self) -> &Vec<WeakModelHandle<terminal::Terminal>> {
|
||||||
|
&self.terminals.local_handles
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add a few tests for adding and removing terminal tabs
|
// TODO: Add a few tests for adding and removing terminal tabs
|
||||||
|
|
|
@ -166,8 +166,8 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx));
|
cx.add_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx));
|
||||||
cx.add_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx));
|
cx.add_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx));
|
||||||
cx.add_action(Pane::deploy_split_menu);
|
cx.add_action(Pane::deploy_split_menu);
|
||||||
cx.add_action(Pane::deploy_new_menu);
|
|
||||||
cx.add_action(Pane::deploy_dock_menu);
|
cx.add_action(Pane::deploy_dock_menu);
|
||||||
|
cx.add_action(Pane::deploy_new_menu);
|
||||||
cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| {
|
cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| {
|
||||||
Pane::reopen_closed_item(workspace, cx).detach();
|
Pane::reopen_closed_item(workspace, cx).detach();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
|
use context_menu::{ContextMenu, ContextMenuItem};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::{Empty, MouseEventHandler, Svg},
|
actions, elements::*, geometry::vector::vec2f, CursorStyle, Element, ElementBox, Entity,
|
||||||
CursorStyle, Element, ElementBox, Entity, MouseButton, RenderContext, View, ViewContext,
|
MouseButton, MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||||
ViewHandle, WeakViewHandle,
|
|
||||||
};
|
};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
|
||||||
use crate::{dock::FocusDock, item::ItemHandle, StatusItemView, Workspace};
|
use crate::{dock::FocusDock, item::ItemHandle, NewTerminal, StatusItemView, Workspace};
|
||||||
|
|
||||||
|
// #[derive(Clone, PartialEq)]
|
||||||
|
// pub struct DeployTerminalMenu {
|
||||||
|
// position: Vector2F,
|
||||||
|
// }
|
||||||
|
|
||||||
|
actions!(terminal, [DeployTerminalMenu]);
|
||||||
|
|
||||||
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
|
cx.add_action(TerminalButton::deploy_terminal_menu);
|
||||||
|
}
|
||||||
|
|
||||||
pub struct TerminalButton {
|
pub struct TerminalButton {
|
||||||
workspace: WeakViewHandle<Workspace>,
|
workspace: WeakViewHandle<Workspace>,
|
||||||
}
|
popup_menu: ViewHandle<ContextMenu>,
|
||||||
|
|
||||||
// TODO: Rename this to `DeployTerminalButton`
|
|
||||||
impl TerminalButton {
|
|
||||||
pub fn new(workspace: ViewHandle<Workspace>, cx: &mut ViewContext<Self>) -> Self {
|
|
||||||
// When terminal moves, redraw so that the icon and toggle status matches.
|
|
||||||
cx.subscribe(&workspace, |_, _, _, cx| cx.notify()).detach();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
workspace: workspace.downgrade(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for TerminalButton {
|
impl Entity for TerminalButton {
|
||||||
|
@ -34,52 +34,93 @@ impl View for TerminalButton {
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
||||||
let workspace = self.workspace.upgrade(cx);
|
let workspace = self.workspace.upgrade(cx);
|
||||||
|
let project = match workspace {
|
||||||
if workspace.is_none() {
|
Some(workspace) => workspace.read(cx).project().read(cx),
|
||||||
return Empty::new().boxed();
|
None => return Empty::new().boxed(),
|
||||||
}
|
};
|
||||||
|
let has_terminals = !project.local_terminal_handles().is_empty();
|
||||||
// let workspace = workspace.unwrap();
|
let terminal_count = project.local_terminal_handles().iter().count();
|
||||||
let theme = cx.global::<Settings>().theme.clone();
|
let theme = cx.global::<Settings>().theme.clone();
|
||||||
|
|
||||||
MouseEventHandler::<Self>::new(0, cx, {
|
Stack::new()
|
||||||
let theme = theme.clone();
|
.with_child(
|
||||||
move |state, _| {
|
MouseEventHandler::<Self>::new(0, cx, {
|
||||||
let style = theme
|
let theme = theme.clone();
|
||||||
.workspace
|
move |state, _| {
|
||||||
.status_bar
|
let style = theme
|
||||||
.sidebar_buttons
|
.workspace
|
||||||
.item
|
.status_bar
|
||||||
.style_for(state, true);
|
.sidebar_buttons
|
||||||
|
.item
|
||||||
|
.style_for(state, true);
|
||||||
|
|
||||||
Svg::new("icons/terminal_12.svg")
|
Svg::new("icons/terminal_12.svg")
|
||||||
.with_color(style.icon_color)
|
.with_color(style.icon_color)
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_width(style.icon_size)
|
.with_width(style.icon_size)
|
||||||
.with_height(style.icon_size)
|
.with_height(style.icon_size)
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.on_up(MouseButton::Left, move |_, _| {
|
.on_up(MouseButton::Left, move |_, _| {
|
||||||
// TODO: Do we need this stuff?
|
// TODO: Do we need this stuff?
|
||||||
// let dock_pane = workspace.read(cx.app).dock_pane();
|
// let dock_pane = workspace.read(cx.app).dock_pane();
|
||||||
// let drop_index = dock_pane.read(cx.app).items_len() + 1;
|
// let drop_index = dock_pane.read(cx.app).items_len() + 1;
|
||||||
// handle_dropped_item(event, &dock_pane.downgrade(), drop_index, false, None, cx);
|
// handle_dropped_item(event, &dock_pane.downgrade(), drop_index, false, None, cx);
|
||||||
})
|
})
|
||||||
.on_click(MouseButton::Left, |_, cx| {
|
.on_click(MouseButton::Left, move |_, cx| {
|
||||||
cx.dispatch_action(FocusDock);
|
if has_terminals {
|
||||||
})
|
cx.dispatch_action(DeployTerminalMenu);
|
||||||
.with_tooltip::<Self, _>(
|
println!("Yes, has_terminals {}", terminal_count);
|
||||||
0,
|
} else {
|
||||||
"Show Terminal".into(),
|
cx.dispatch_action(FocusDock);
|
||||||
Some(Box::new(FocusDock)),
|
};
|
||||||
theme.tooltip.clone(),
|
})
|
||||||
cx,
|
.with_tooltip::<Self, _>(
|
||||||
)
|
0,
|
||||||
.boxed()
|
"Show Terminal".into(),
|
||||||
|
Some(Box::new(FocusDock)),
|
||||||
|
theme.tooltip.clone(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_child(ChildView::new(&self.popup_menu, cx).boxed())
|
||||||
|
.boxed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Rename this to `DeployTerminalButton`
|
||||||
|
impl TerminalButton {
|
||||||
|
pub fn new(workspace: ViewHandle<Workspace>, cx: &mut ViewContext<Self>) -> Self {
|
||||||
|
// When terminal moves, redraw so that the icon and toggle status matches.
|
||||||
|
cx.subscribe(&workspace, |_, _, _, cx| cx.notify()).detach();
|
||||||
|
Self {
|
||||||
|
workspace: workspace.downgrade(),
|
||||||
|
popup_menu: cx.add_view(|cx| {
|
||||||
|
let mut menu = ContextMenu::new(cx);
|
||||||
|
menu.set_position_mode(OverlayPositionMode::Local);
|
||||||
|
menu
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deploy_terminal_menu(
|
||||||
|
&mut self,
|
||||||
|
_action: &DeployTerminalMenu,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
|
self.popup_menu.update(cx, |menu, cx| {
|
||||||
|
menu.show(
|
||||||
|
vec2f(0., 0.),
|
||||||
|
AnchorCorner::TopLeft,
|
||||||
|
vec![ContextMenuItem::item("New Terminal", NewTerminal)],
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ use status_bar::StatusBar;
|
||||||
pub use status_bar::StatusItemView;
|
pub use status_bar::StatusItemView;
|
||||||
use theme::{Theme, ThemeRegistry};
|
use theme::{Theme, ThemeRegistry};
|
||||||
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
||||||
use util::ResultExt;
|
use util::{ResultExt, StaffMode};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref ZED_WINDOW_SIZE: Option<Vector2F> = env::var("ZED_WINDOW_SIZE")
|
static ref ZED_WINDOW_SIZE: Option<Vector2F> = env::var("ZED_WINDOW_SIZE")
|
||||||
|
@ -185,6 +185,7 @@ impl_actions!(workspace, [ActivatePane]);
|
||||||
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
pane::init(cx);
|
pane::init(cx);
|
||||||
dock::init(cx);
|
dock::init(cx);
|
||||||
|
terminal_button::init(cx);
|
||||||
notifications::init(cx);
|
notifications::init(cx);
|
||||||
|
|
||||||
cx.add_global_action(open);
|
cx.add_global_action(open);
|
||||||
|
@ -595,7 +596,10 @@ impl Workspace {
|
||||||
status_bar.add_left_item(left_sidebar_buttons, cx);
|
status_bar.add_left_item(left_sidebar_buttons, cx);
|
||||||
status_bar.add_right_item(right_sidebar_buttons, cx);
|
status_bar.add_right_item(right_sidebar_buttons, cx);
|
||||||
status_bar.add_right_item(toggle_dock, cx);
|
status_bar.add_right_item(toggle_dock, cx);
|
||||||
status_bar.add_right_item(toggle_terminal, cx);
|
// TOOD: Remove this when things are done
|
||||||
|
if **cx.default_global::<StaffMode>() {
|
||||||
|
status_bar.add_right_item(toggle_terminal, cx);
|
||||||
|
}
|
||||||
status_bar
|
status_bar
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue