Add "Stop" and "Restart" commands to the right-click menu in the terminal. (#3526)

This commit is contained in:
ifengqi 2024-09-20 17:31:50 +08:00 committed by GitHub
parent d88fc896d7
commit a31277fd78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 14 deletions

View File

@ -791,6 +791,12 @@ pub enum InternalCommand {
CallHierarchyIncoming {
item_id: ViewId,
},
StopTerminal {
term_id: TermId,
},
RestartTerminal {
term_id: TermId,
},
}
#[derive(Clone)]

View File

@ -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);
}

View File

@ -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},

View File

@ -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);
}