Rework new terminal actions

This commit is contained in:
Mikayla Maki 2023-05-30 16:10:07 -07:00
parent e80ab5f096
commit 9c707eff27
No known key found for this signature in database
4 changed files with 41 additions and 56 deletions

View file

@ -22,7 +22,7 @@ const TERMINAL_PANEL_KEY: &'static str = "TerminalPanel";
actions!(terminal_panel, [ToggleFocus]);
pub fn init(cx: &mut AppContext) {
cx.add_action(TerminalPanel::add_terminal);
cx.add_action(TerminalPanel::new_terminal);
}
pub enum Event {
@ -80,7 +80,7 @@ impl TerminalPanel {
cx.window_context().defer(move |cx| {
if let Some(this) = this.upgrade(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();
cx.spawn(|this, mut cx| async move {
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>) {
if active && self.pane.read(cx).items_len() == 0 {
self.add_terminal(&Default::default(), cx)
self.add_terminal(cx)
}
}