From a31277fd784bf139756a721543c6ee25cdc9fb23 Mon Sep 17 00:00:00 2001 From: ifengqi <362254883@qq.com> Date: Fri, 20 Sep 2024 17:31:50 +0800 Subject: [PATCH] Add "Stop" and "Restart" commands to the right-click menu in the terminal. (#3526) --- lapce-app/src/command.rs | 6 +++++ lapce-app/src/panel/terminal_view.rs | 39 ++++++++++++++++++---------- lapce-app/src/panel/view.rs | 2 +- lapce-app/src/window_tab.rs | 13 ++++++++++ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lapce-app/src/command.rs b/lapce-app/src/command.rs index 20352612..a958f333 100644 --- a/lapce-app/src/command.rs +++ b/lapce-app/src/command.rs @@ -791,6 +791,12 @@ pub enum InternalCommand { CallHierarchyIncoming { item_id: ViewId, }, + StopTerminal { + term_id: TermId, + }, + RestartTerminal { + term_id: TermId, + }, } #[derive(Clone)] diff --git a/lapce-app/src/panel/terminal_view.rs b/lapce-app/src/panel/terminal_view.rs index c35cd30b..81be2d63 100644 --- a/lapce-app/src/panel/terminal_view.rs +++ b/lapce-app/src/panel/terminal_view.rs @@ -13,6 +13,7 @@ }, View, ViewId, }; +use lapce_rpc::terminal::TermId; use super::kind::PanelKind; use crate::{ @@ -294,17 +295,21 @@ fn terminal_tab_split( workspace.clone(), ); let view_id = terminal_view.id(); + let have_task = terminal.run_debug.get_untracked().is_some(); terminal_view .on_event_cont(EventListener::PointerDown, move |_| { active.set(index.get_untracked()); }) .on_secondary_click_stop(move |_| { - tab_secondary_click( - internal_command, - view_id, - tab_index, - index.get_untracked(), - ); + if have_task { + tab_secondary_click( + internal_command, + view_id, + tab_index, + index.get_untracked(), + terminal.term_id, + ); + } }) .on_event(EventListener::PointerWheel, move |event| { if let Event::PointerWheel(pointer_event) = event { @@ -355,14 +360,22 @@ fn tab_secondary_click( view_id: ViewId, tab_index: usize, terminal_index: usize, + term_id: TermId, ) { let mut menu = Menu::new(""); - menu = menu.entry(MenuItem::new("Clear All").action(move || { - internal_command.send(InternalCommand::ClearTerminalBuffer { - view_id, - tab_index, - terminal_index, - }); - })); + menu = menu + .entry(MenuItem::new("Stop").action(move || { + internal_command.send(InternalCommand::StopTerminal { term_id }); + })) + .entry(MenuItem::new("Restart").action(move || { + internal_command.send(InternalCommand::RestartTerminal { term_id }); + })) + .entry(MenuItem::new("Clear All").action(move || { + internal_command.send(InternalCommand::ClearTerminalBuffer { + view_id, + tab_index, + terminal_index, + }); + })); show_context_menu(menu, None); } diff --git a/lapce-app/src/panel/view.rs b/lapce-app/src/panel/view.rs index 158b7aa5..54544fae 100644 --- a/lapce-app/src/panel/view.rs +++ b/lapce-app/src/panel/view.rs @@ -26,13 +26,13 @@ source_control_view::source_control_panel, terminal_view::terminal_panel, }; -use crate::panel::implementation_view::implementation_panel; use crate::{ app::{clickable_icon, clickable_icon_base}, config::{color::LapceColor, icon::LapceIcons, LapceConfig}, file_explorer::view::file_explorer_panel, panel::{ call_hierarchy_view::show_hierarchy_panel, document_symbol::symbol_panel, + implementation_view::implementation_panel, references_view::references_panel, }, window_tab::{DragContent, WindowTabData}, diff --git a/lapce-app/src/window_tab.rs b/lapce-app/src/window_tab.rs index 80125f60..1158615d 100644 --- a/lapce-app/src/window_tab.rs +++ b/lapce-app/src/window_tab.rs @@ -2059,6 +2059,19 @@ pub fn run_internal_command(&self, cmd: InternalCommand) { raw.write().term.reset_state(); view_id.request_paint(); } + InternalCommand::StopTerminal { term_id } => { + self.terminal.stop_run_debug(term_id); + } + InternalCommand::RestartTerminal { term_id } => { + if let Some(is_debug) = self.terminal.restart_run_debug(term_id) { + self.panel.show_panel(&PanelKind::Terminal); + if is_debug { + self.panel.show_panel(&PanelKind::Debug); + } + } else { + self.palette.run(PaletteKind::RunAndDebug); + } + } InternalCommand::CallHierarchyIncoming { item_id } => { self.call_hierarchy_incoming(item_id); }