Make context menu work better with panes

This commit is contained in:
Mattias Eriksson 2024-02-02 13:56:17 +01:00 • committed by Jeremy Soller
parent e322fc86f7
commit 623a193ad4

View file

@ -271,7 +271,7 @@ pub enum Message {
TabActivateJump(usize), TabActivateJump(usize),
TabClose(Option<segmented_button::Entity>), TabClose(Option<segmented_button::Entity>),
TabContextAction(segmented_button::Entity, Action), TabContextAction(segmented_button::Entity, Action),
TabContextMenu(segmented_button::Entity, Option<Point>), TabContextMenu(pane_grid::Pane, Option<Point>),
TabNew, TabNew,
TabPrev, TabPrev,
TabNext, TabNext,
@ -1253,8 +1253,23 @@ impl Application for App {
} }
} }
} }
Message::TabContextMenu(entity, position_opt) => { Message::TabContextMenu(pane, position_opt) => {
if let Some(tab_model) = self.pane_model.active() { // Close any existing context menues
let panes: Vec<_> = self.pane_model.panes.iter().collect();
for (_pane, tab_model) in panes {
let entity = tab_model.active();
match tab_model.data::<Mutex<Terminal>>(entity) {
Some(terminal) => {
let mut terminal = terminal.lock().unwrap();
terminal.context_menu = None;
}
_ => {}
}
}
// Show the context menu on the correct pane / terminal
if let Some(tab_model) = self.pane_model.panes.get(pane) {
let entity = tab_model.active();
match tab_model.data::<Mutex<Terminal>>(entity) { match tab_model.data::<Mutex<Terminal>>(entity) {
Some(terminal) => { Some(terminal) => {
// Update context menu position // Update context menu position
@ -1264,6 +1279,11 @@ impl Application for App {
_ => {} _ => {}
} }
} }
// Shift focus to the pane / terminal
// with the context menu
self.pane_model.focus = pane;
return self.update_title(Some(pane));
} }
Message::TabNew => self.create_and_focus_new_terminal(self.pane_model.focus), Message::TabNew => self.create_and_focus_new_terminal(self.pane_model.focus),
Message::TabNext => { Message::TabNext => {
@ -1490,7 +1510,7 @@ impl Application for App {
match tab_model.data::<Mutex<Terminal>>(entity) { match tab_model.data::<Mutex<Terminal>>(entity) {
Some(terminal) => { Some(terminal) => {
let mut terminal_box = terminal_box(terminal).id(terminal_id).on_context_menu( let mut terminal_box = terminal_box(terminal).id(terminal_id).on_context_menu(
move |position_opt| Message::TabContextMenu(entity, position_opt), move |position_opt| Message::TabContextMenu(pane, position_opt),
); );
if self.config.focus_follow_mouse { if self.config.focus_follow_mouse {