From 7e6efcf5c69f658290c02b5483d5d245dd070aaf Mon Sep 17 00:00:00 2001 From: dzmipt Date: Fri, 5 Jan 2024 23:06:57 +0100 Subject: [PATCH] adding ctrl+shift+W (or command+shift+W for Mac) for result tab closure --- src/studio/ui/ClosableTabbedPane.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/studio/ui/ClosableTabbedPane.java b/src/studio/ui/ClosableTabbedPane.java index c74b7951..bc52edc5 100644 --- a/src/studio/ui/ClosableTabbedPane.java +++ b/src/studio/ui/ClosableTabbedPane.java @@ -1,9 +1,12 @@ package studio.ui; import javax.swing.*; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import static javax.swing.JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT; + public class ClosableTabbedPane { public interface CloseTabAction { @@ -51,6 +54,13 @@ private boolean checkPopup(int tabIndex, MouseEvent e) { } }); + tabbedPane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_W, StudioWindow.menuShortcutKeyMask | KeyEvent.SHIFT_MASK), "closeTab"); + tabbedPane.getActionMap().put("closeTab", + UserAction.create("Close tab", e -> { + int index = tabbedPane.getSelectedIndex(); + if (index != -1) closeTabAction.close(index, true); + }) ); + } private static JPopupMenu createTabbedPopupMenu(JTabbedPane tabbedPane, CloseTabAction closeTabAction, int index) {