Remove internal actions from terminal_button
This commit is contained in:
parent
33da9e5690
commit
1d41a703ad
2 changed files with 23 additions and 48 deletions
|
@ -1,33 +1,14 @@
|
||||||
|
use crate::TerminalView;
|
||||||
use context_menu::{ContextMenu, ContextMenuItem};
|
use context_menu::{ContextMenu, ContextMenuItem};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::*,
|
elements::*,
|
||||||
impl_internal_actions,
|
|
||||||
platform::{CursorStyle, MouseButton},
|
platform::{CursorStyle, MouseButton},
|
||||||
AnyElement, AppContext, Element, Entity, View, ViewContext, ViewHandle, WeakModelHandle,
|
AnyElement, Element, Entity, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||||
WeakViewHandle,
|
|
||||||
};
|
};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
use terminal::Terminal;
|
|
||||||
use workspace::{dock::FocusDock, item::ItemHandle, NewTerminal, StatusItemView, Workspace};
|
use workspace::{dock::FocusDock, item::ItemHandle, NewTerminal, StatusItemView, Workspace};
|
||||||
|
|
||||||
use crate::TerminalView;
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
|
||||||
pub struct DeployTerminalMenu;
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
|
||||||
pub struct FocusTerminal {
|
|
||||||
terminal_handle: WeakModelHandle<Terminal>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_internal_actions!(terminal, [FocusTerminal, DeployTerminalMenu]);
|
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
|
||||||
cx.add_action(TerminalButton::deploy_terminal_menu);
|
|
||||||
cx.add_action(TerminalButton::focus_terminal);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TerminalButton {
|
pub struct TerminalButton {
|
||||||
workspace: WeakViewHandle<Workspace>,
|
workspace: WeakViewHandle<Workspace>,
|
||||||
popup_menu: ViewHandle<ContextMenu>,
|
popup_menu: ViewHandle<ContextMenu>,
|
||||||
|
@ -94,9 +75,9 @@ impl View for TerminalButton {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.on_click(MouseButton::Left, move |_, _, cx| {
|
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||||
if has_terminals {
|
if has_terminals {
|
||||||
cx.dispatch_action(DeployTerminalMenu);
|
this.deploy_terminal_menu(cx);
|
||||||
} else {
|
} else {
|
||||||
if !active {
|
if !active {
|
||||||
cx.dispatch_action(FocusDock);
|
cx.dispatch_action(FocusDock);
|
||||||
|
@ -129,11 +110,7 @@ impl TerminalButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deploy_terminal_menu(
|
pub fn deploy_terminal_menu(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
&mut self,
|
|
||||||
_action: &DeployTerminalMenu,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) {
|
|
||||||
let mut menu_options = vec![ContextMenuItem::action("New Terminal", NewTerminal)];
|
let mut menu_options = vec![ContextMenuItem::action("New Terminal", NewTerminal)];
|
||||||
|
|
||||||
if let Some(workspace) = self.workspace.upgrade(cx) {
|
if let Some(workspace) = self.workspace.upgrade(cx) {
|
||||||
|
@ -146,10 +123,24 @@ impl TerminalButton {
|
||||||
|
|
||||||
for local_terminal_handle in local_terminal_handles {
|
for local_terminal_handle in local_terminal_handles {
|
||||||
if let Some(terminal) = local_terminal_handle.upgrade(cx) {
|
if let Some(terminal) = local_terminal_handle.upgrade(cx) {
|
||||||
menu_options.push(ContextMenuItem::action(
|
let workspace = self.workspace.clone();
|
||||||
|
let local_terminal_handle = local_terminal_handle.clone();
|
||||||
|
menu_options.push(ContextMenuItem::handler(
|
||||||
terminal.read(cx).title(),
|
terminal.read(cx).title(),
|
||||||
FocusTerminal {
|
move |cx| {
|
||||||
terminal_handle: local_terminal_handle.clone(),
|
if let Some(workspace) = workspace.upgrade(cx) {
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
let terminal = workspace
|
||||||
|
.items_of_type::<TerminalView>(cx)
|
||||||
|
.find(|terminal| {
|
||||||
|
terminal.read(cx).model().downgrade()
|
||||||
|
== local_terminal_handle
|
||||||
|
});
|
||||||
|
if let Some(terminal) = terminal {
|
||||||
|
workspace.activate_item(&terminal, cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -165,21 +156,6 @@ impl TerminalButton {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus_terminal(&mut self, action: &FocusTerminal, cx: &mut ViewContext<Self>) {
|
|
||||||
if let Some(workspace) = self.workspace.upgrade(cx) {
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
|
||||||
let terminal = workspace
|
|
||||||
.items_of_type::<TerminalView>(cx)
|
|
||||||
.find(|terminal| {
|
|
||||||
terminal.read(cx).model().downgrade() == action.terminal_handle
|
|
||||||
});
|
|
||||||
if let Some(terminal) = terminal {
|
|
||||||
workspace.activate_item(&terminal, cx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StatusItemView for TerminalButton {
|
impl StatusItemView for TerminalButton {
|
||||||
|
|
|
@ -31,7 +31,7 @@ use serde::Deserialize;
|
||||||
use serde_json::to_string_pretty;
|
use serde_json::to_string_pretty;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::{borrow::Cow, env, path::Path, str, sync::Arc};
|
use std::{borrow::Cow, env, path::Path, str, sync::Arc};
|
||||||
use terminal_view::terminal_button::{self, TerminalButton};
|
use terminal_view::terminal_button::TerminalButton;
|
||||||
use util::{channel::ReleaseChannel, paths, ResultExt};
|
use util::{channel::ReleaseChannel, paths, ResultExt};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
pub use workspace;
|
pub use workspace;
|
||||||
|
@ -73,7 +73,6 @@ actions!(
|
||||||
const MIN_FONT_SIZE: f32 = 6.0;
|
const MIN_FONT_SIZE: f32 = 6.0;
|
||||||
|
|
||||||
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
||||||
terminal_button::init(cx);
|
|
||||||
cx.add_action(about);
|
cx.add_action(about);
|
||||||
cx.add_global_action(|_: &Hide, cx: &mut gpui::AppContext| {
|
cx.add_global_action(|_: &Hide, cx: &mut gpui::AppContext| {
|
||||||
cx.platform().hide();
|
cx.platform().hide();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue