From bf0ec13e65b9842a4ed2675631502196d9d977ef Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 Aug 2022 15:59:25 -0700 Subject: [PATCH] New button --- assets/keymaps/default.json | 2 +- crates/terminal/src/terminal_view.rs | 10 +++-- crates/workspace/src/pane.rs | 57 ++++++++++++++++++++++++++-- crates/workspace/src/workspace.rs | 1 + 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 63b00c1d9ecfd2f1df71cf8b0361c365a9b6be3d..f9735e7cee05fada9613da6de18f48e3e837e010 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -31,7 +31,7 @@ "cmd-n": "workspace::NewFile", "cmd-shift-n": "workspace::NewWindow", "cmd-o": "workspace::Open", - "ctrl-`": "terminal::Deploy" + "ctrl-`": "workspace::NewTerminal" } }, { diff --git a/crates/terminal/src/terminal_view.rs b/crates/terminal/src/terminal_view.rs index 8acf1c233acf822931ce7864eef731d1c1446b1a..40a882e4885ddda8fd992d069e0d5e292638bec9 100644 --- a/crates/terminal/src/terminal_view.rs +++ b/crates/terminal/src/terminal_view.rs @@ -5,17 +5,17 @@ use gpui::{ actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, View, ViewContext, ViewHandle, }; +use workspace::{Item, Workspace}; use crate::TerminalSize; use project::{LocalWorktree, Project, ProjectPath}; use settings::{Settings, WorkingDirectory}; use smallvec::SmallVec; use std::path::{Path, PathBuf}; -use workspace::{Item, Workspace}; use crate::connected_el::TerminalEl; -actions!(terminal, [Deploy, DeployModal]); +actions!(terminal, [DeployModal]); //Make terminal view an enum, that can give you views for the error and non-error states //Take away all the result unwrapping in the current TerminalView by making it 'infallible' @@ -59,7 +59,11 @@ impl Entity for ErrorView { impl TerminalView { ///Create a new Terminal in the current working directory or the user's home directory - pub fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext) { + pub fn deploy( + workspace: &mut Workspace, + _: &workspace::NewTerminal, + cx: &mut ViewContext, + ) { let strategy = cx .global::() .terminal_overrides diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 7ba8badc9dce7d39d85c552574433a45cd558e53..386b151e243f5ca60a67dc11e463c9557b8702a0 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1,5 +1,5 @@ use super::{ItemHandle, SplitDirection}; -use crate::{toolbar::Toolbar, Item, WeakItemHandle, Workspace}; +use crate::{toolbar::Toolbar, Item, NewFile, NewTerminal, WeakItemHandle, Workspace}; use anyhow::Result; use collections::{HashMap, HashSet, VecDeque}; use context_menu::{ContextMenu, ContextMenuItem}; @@ -65,8 +65,13 @@ pub struct DeploySplitMenu { position: Vector2F, } +#[derive(Clone, PartialEq)] +pub struct DeployNewMenu { + position: Vector2F, +} + impl_actions!(pane, [GoBack, GoForward, ActivateItem]); -impl_internal_actions!(pane, [CloseItem, DeploySplitMenu]); +impl_internal_actions!(pane, [CloseItem, DeploySplitMenu, DeployNewMenu]); const MAX_NAVIGATION_HISTORY_LEN: usize = 1024; @@ -98,6 +103,7 @@ 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, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)); cx.add_action(Pane::deploy_split_menu); + cx.add_action(Pane::deploy_new_menu); cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| { Pane::reopen_closed_item(workspace, cx).detach(); }); @@ -845,6 +851,19 @@ impl Pane { }); } + fn deploy_new_menu(&mut self, action: &DeployNewMenu, cx: &mut ViewContext) { + self.split_menu.update(cx, |menu, cx| { + menu.show( + action.position, + vec![ + ContextMenuItem::item("New File", NewFile), + ContextMenuItem::item("New Terminal", NewTerminal), + ], + cx, + ); + }); + } + pub fn toolbar(&self) -> &ViewHandle { &self.toolbar } @@ -1083,10 +1102,40 @@ impl View for Pane { .with_child(self.render_tabs(cx).flex(1., true).named("tabs")); if self.is_active { - tab_row.add_child( + tab_row.add_children([ MouseEventHandler::new::( 0, cx, + |mouse_state, cx| { + let theme = + &cx.global::().theme.workspace.tab_bar; + let style = + theme.pane_button.style_for(mouse_state, false); + Svg::new("icons/bolt_12.svg") + .with_color(style.color) + .constrained() + .with_width(style.icon_width) + .aligned() + .contained() + .with_style(style.container) + .constrained() + .with_width(style.button_width) + .with_height(style.button_width) + .aligned() + .boxed() + }, + ) + .with_cursor_style(CursorStyle::PointingHand) + .on_down( + MouseButton::Left, + |MouseButtonEvent { position, .. }, cx| { + cx.dispatch_action(DeployNewMenu { position }); + }, + ) + .boxed(), + MouseEventHandler::new::( + 1, + cx, |mouse_state, cx| { let theme = &cx.global::().theme.workspace.tab_bar; @@ -1114,7 +1163,7 @@ impl View for Pane { }, ) .boxed(), - ) + ]) } tab_row diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index c060f57072692767305e12e55fed7c2c80ce7481..c2821e1365cf9d07acb1343f6397e8a12a28b9c2 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -96,6 +96,7 @@ actions!( FollowNextCollaborator, ToggleLeftSidebar, ToggleRightSidebar, + NewTerminal, ] );