From 623a193ad46fba84f889f2b411fbed4f5c1a181b Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Fri, 2 Feb 2024 13:56:17 +0100 Subject: [PATCH] Make context menu work better with panes --- src/main.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index bdbcf88..153fb67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -271,7 +271,7 @@ pub enum Message { TabActivateJump(usize), TabClose(Option), TabContextAction(segmented_button::Entity, Action), - TabContextMenu(segmented_button::Entity, Option), + TabContextMenu(pane_grid::Pane, Option), TabNew, TabPrev, TabNext, @@ -1253,8 +1253,23 @@ impl Application for App { } } } - Message::TabContextMenu(entity, position_opt) => { - if let Some(tab_model) = self.pane_model.active() { + Message::TabContextMenu(pane, position_opt) => { + // 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::>(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::>(entity) { Some(terminal) => { // 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::TabNext => { @@ -1490,7 +1510,7 @@ impl Application for App { match tab_model.data::>(entity) { Some(terminal) => { 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 {