Skip to content

Commit

Permalink
feat(gui): added keyboard shortcut ctrl+w to close tab (#1765)(PR #1766)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ran-Naor committed Jan 21, 2023
1 parent 1c36b3c commit 87b9ff3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/TabbedPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class TabbedPane extends JTabbedPane {
}
});
interceptTabKey();
interceptCloseKey();
enableSwitchingTabs();
}

Expand Down Expand Up @@ -120,6 +121,34 @@ public boolean dispatchKeyEvent(KeyEvent e) {
});
}

private void interceptCloseKey() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
private static final int closeKey = KeyEvent.VK_W;
private boolean canClose = true;

@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (!FocusManager.isActive()) {
return false; // do nothing when tab is not on focus.
}
if (e.getKeyCode() != closeKey) {
return false; // only intercept the events of the close key
}
if (e.getID() == KeyEvent.KEY_RELEASED) {
canClose = true; // after the close key is lifted we allow to use it again
return false;
}
if (e.isControlDown() && canClose) {
// close the current tab
closeCodePanel(curTab);
canClose = false; // make sure we dont close more tabs until the close key is lifted
return true;
}
return false;
}
});
}

private void enableSwitchingTabs() {
addChangeListener(e -> {
ContentPanel tab = getSelectedCodePanel();
Expand Down

0 comments on commit 87b9ff3

Please sign in to comment.