Rework new terminal actions
This commit is contained in:
parent
e80ab5f096
commit
9c707eff27
4 changed files with 41 additions and 56 deletions
|
@ -22,7 +22,7 @@ const TERMINAL_PANEL_KEY: &'static str = "TerminalPanel";
|
||||||
actions!(terminal_panel, [ToggleFocus]);
|
actions!(terminal_panel, [ToggleFocus]);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(TerminalPanel::add_terminal);
|
cx.add_action(TerminalPanel::new_terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
|
@ -80,7 +80,7 @@ impl TerminalPanel {
|
||||||
cx.window_context().defer(move |cx| {
|
cx.window_context().defer(move |cx| {
|
||||||
if let Some(this) = this.upgrade(cx) {
|
if let Some(this) = this.upgrade(cx) {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.add_terminal(&Default::default(), cx);
|
this.add_terminal(cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -220,7 +220,18 @@ impl TerminalPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_terminal(&mut self, _: &workspace::NewTerminal, cx: &mut ViewContext<Self>) {
|
|
||||||
|
fn new_terminal(workspace: &mut Workspace, _: &workspace::NewTerminal, cx: &mut ViewContext<Workspace>) {
|
||||||
|
let Some(this) = workspace.focus_panel::<Self>(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.add_terminal(cx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_terminal(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
let workspace = self.workspace.clone();
|
let workspace = self.workspace.clone();
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let pane = this.read_with(&cx, |this, _| this.pane.clone())?;
|
let pane = this.read_with(&cx, |this, _| this.pane.clone())?;
|
||||||
|
@ -363,7 +374,7 @@ impl Panel for TerminalPanel {
|
||||||
|
|
||||||
fn set_active(&mut self, active: bool, cx: &mut ViewContext<Self>) {
|
fn set_active(&mut self, active: bool, cx: &mut ViewContext<Self>) {
|
||||||
if active && self.pane.read(cx).items_len() == 0 {
|
if active && self.pane.read(cx).items_len() == 0 {
|
||||||
self.add_terminal(&Default::default(), cx)
|
self.add_terminal(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ use workspace::{
|
||||||
notifications::NotifyResultExt,
|
notifications::NotifyResultExt,
|
||||||
pane, register_deserializable_item,
|
pane, register_deserializable_item,
|
||||||
searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle},
|
searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle},
|
||||||
Pane, ToolbarItemLocation, Workspace, WorkspaceId,
|
Pane, ToolbarItemLocation, Workspace, WorkspaceId, NewCenterTerminal,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use terminal::TerminalSettings;
|
pub use terminal::TerminalSettings;
|
||||||
|
@ -66,10 +66,10 @@ pub fn init(cx: &mut AppContext) {
|
||||||
terminal_panel::init(cx);
|
terminal_panel::init(cx);
|
||||||
terminal::init(cx);
|
terminal::init(cx);
|
||||||
|
|
||||||
cx.add_action(TerminalView::deploy);
|
|
||||||
|
|
||||||
register_deserializable_item::<TerminalView>(cx);
|
register_deserializable_item::<TerminalView>(cx);
|
||||||
|
|
||||||
|
cx.add_action(TerminalView::deploy);
|
||||||
|
|
||||||
//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);
|
||||||
|
@ -101,7 +101,7 @@ impl TerminalView {
|
||||||
///Create a new Terminal in the current working directory or the user's home directory
|
///Create a new Terminal in the current working directory or the user's home directory
|
||||||
pub fn deploy(
|
pub fn deploy(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
_: &workspace::NewTerminal,
|
_: &NewCenterTerminal,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
let strategy = settings::get::<TerminalSettings>(cx);
|
let strategy = settings::get::<TerminalSettings>(cx);
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod dragged_item_receiver;
|
||||||
use super::{ItemHandle, SplitDirection};
|
use super::{ItemHandle, SplitDirection};
|
||||||
use crate::{
|
use crate::{
|
||||||
item::WeakItemHandle, toolbar::Toolbar, AutosaveSetting, Item, NewFile, NewSearch, NewTerminal,
|
item::WeakItemHandle, toolbar::Toolbar, AutosaveSetting, Item, NewFile, NewSearch, NewTerminal,
|
||||||
ToggleZoom, Workspace, WorkspaceSettings,
|
ToggleZoom, Workspace, WorkspaceSettings, NewCenterTerminal,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::{HashMap, HashSet, VecDeque};
|
use collections::{HashMap, HashSet, VecDeque};
|
||||||
|
@ -131,7 +131,6 @@ pub enum Event {
|
||||||
pub struct Pane {
|
pub struct Pane {
|
||||||
items: Vec<Box<dyn ItemHandle>>,
|
items: Vec<Box<dyn ItemHandle>>,
|
||||||
activation_history: Vec<usize>,
|
activation_history: Vec<usize>,
|
||||||
is_active: bool,
|
|
||||||
zoomed: bool,
|
zoomed: bool,
|
||||||
active_item_index: usize,
|
active_item_index: usize,
|
||||||
last_focused_view_by_item: HashMap<usize, AnyWeakViewHandle>,
|
last_focused_view_by_item: HashMap<usize, AnyWeakViewHandle>,
|
||||||
|
@ -238,7 +237,6 @@ impl Pane {
|
||||||
Self {
|
Self {
|
||||||
items: Vec::new(),
|
items: Vec::new(),
|
||||||
activation_history: Vec::new(),
|
activation_history: Vec::new(),
|
||||||
is_active: true,
|
|
||||||
zoomed: false,
|
zoomed: false,
|
||||||
active_item_index: 0,
|
active_item_index: 0,
|
||||||
last_focused_view_by_item: Default::default(),
|
last_focused_view_by_item: Default::default(),
|
||||||
|
@ -996,7 +994,7 @@ impl Pane {
|
||||||
AnchorCorner::TopRight,
|
AnchorCorner::TopRight,
|
||||||
vec![
|
vec![
|
||||||
ContextMenuItem::action("New File", NewFile),
|
ContextMenuItem::action("New File", NewFile),
|
||||||
ContextMenuItem::action("New Terminal", NewTerminal),
|
ContextMenuItem::action("New Terminal", NewCenterTerminal),
|
||||||
ContextMenuItem::action("New Search", NewSearch),
|
ContextMenuItem::action("New Search", NewSearch),
|
||||||
],
|
],
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -55,7 +55,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
str,
|
str,
|
||||||
sync::{atomic::AtomicUsize, Arc},
|
sync::{atomic::AtomicUsize, Arc},
|
||||||
time::Duration,
|
time::Duration, rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -119,6 +119,7 @@ actions!(
|
||||||
ActivateNextPane,
|
ActivateNextPane,
|
||||||
FollowNextCollaborator,
|
FollowNextCollaborator,
|
||||||
NewTerminal,
|
NewTerminal,
|
||||||
|
NewCenterTerminal,
|
||||||
ToggleTerminalFocus,
|
ToggleTerminalFocus,
|
||||||
NewSearch,
|
NewSearch,
|
||||||
Feedback,
|
Feedback,
|
||||||
|
@ -1621,44 +1622,15 @@ impl Workspace {
|
||||||
self.serialize_workspace(cx);
|
self.serialize_workspace(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_panel(
|
pub fn focus_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) -> Option<ViewHandle<T>> {
|
||||||
&mut self,
|
self.show_or_hide_panel::<T>(cx, |_, _| true)?.as_any().clone().downcast()
|
||||||
position: DockPosition,
|
|
||||||
panel_index: usize,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) {
|
|
||||||
let dock = match position {
|
|
||||||
DockPosition::Left => &mut self.left_dock,
|
|
||||||
DockPosition::Bottom => &mut self.bottom_dock,
|
|
||||||
DockPosition::Right => &mut self.right_dock,
|
|
||||||
};
|
|
||||||
let active_item = dock.update(cx, move |dock, cx| {
|
|
||||||
if dock.is_open() && dock.active_panel_index() == panel_index {
|
|
||||||
dock.set_open(false, cx);
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
dock.set_open(true, cx);
|
|
||||||
dock.activate_panel(panel_index, cx);
|
|
||||||
dock.visible_panel().cloned()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(active_item) = active_item {
|
|
||||||
if active_item.has_focus(cx) {
|
|
||||||
cx.focus_self();
|
|
||||||
} else {
|
|
||||||
cx.focus(active_item.as_any());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cx.focus_self();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.serialize_workspace(cx);
|
|
||||||
|
|
||||||
cx.notify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
self.show_or_hide_panel::<T>(cx, |panel, cx| !panel.has_focus(cx));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show_or_hide_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>, show: impl Fn(&dyn PanelHandle, &mut ViewContext<Dock>) -> bool) -> Option<Rc<dyn PanelHandle>> {
|
||||||
for (dock, position) in [
|
for (dock, position) in [
|
||||||
self.left_dock.clone(),
|
self.left_dock.clone(),
|
||||||
self.bottom_dock.clone(),
|
self.bottom_dock.clone(),
|
||||||
|
@ -1676,21 +1648,24 @@ impl Workspace {
|
||||||
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
||||||
let mut focus_center = false;
|
let mut focus_center = false;
|
||||||
let mut zoom_out = false;
|
let mut zoom_out = false;
|
||||||
dock.update(cx, |dock, cx| {
|
let panel = dock.update(cx, |dock, cx| {
|
||||||
dock.activate_panel(panel_index, cx);
|
dock.activate_panel(panel_index, cx);
|
||||||
|
|
||||||
if let Some(panel) = dock.active_panel().cloned() {
|
let panel = dock.active_panel().cloned();
|
||||||
if panel.has_focus(cx) {
|
if let Some(panel) = panel.as_ref() {
|
||||||
|
let should_show = show(&**panel, cx);
|
||||||
|
if should_show {
|
||||||
|
dock.set_open(true, cx);
|
||||||
|
cx.focus(panel.as_any());
|
||||||
|
zoom_out = true;
|
||||||
|
} else {
|
||||||
if panel.is_zoomed(cx) {
|
if panel.is_zoomed(cx) {
|
||||||
dock.set_open(false, cx);
|
dock.set_open(false, cx);
|
||||||
}
|
}
|
||||||
focus_center = true;
|
focus_center = true;
|
||||||
} else {
|
|
||||||
dock.set_open(true, cx);
|
|
||||||
cx.focus(panel.as_any());
|
|
||||||
zoom_out = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
panel
|
||||||
});
|
});
|
||||||
|
|
||||||
if zoom_out {
|
if zoom_out {
|
||||||
|
@ -1702,9 +1677,10 @@ impl Workspace {
|
||||||
|
|
||||||
self.serialize_workspace(cx);
|
self.serialize_workspace(cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
break;
|
return panel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue