Skip to content

Commit

Permalink
Merge pull request #124 from gyorokpeter/hotkey
Browse files Browse the repository at this point in the history
allow chart windows to be closed with Ctrl+W
  • Loading branch information
gyorokpeter authored Jun 17, 2022
2 parents b70d6c0 + e161d08 commit 0bd43cb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/studio/ui/chart/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
import javax.swing.Timer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.util.List;
import java.util.*;

Expand All @@ -43,6 +47,8 @@ public class Chart implements ComponentListener {
private static final Logger log = LogManager.getLogger();
private static final Config config = Config.getInstance();

public final static int menuShortcutKeyMask = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

private static final int CONFIG_UPDATE_DELAY = 1000;

private Timer configUpdateTimer;
Expand Down Expand Up @@ -142,6 +148,17 @@ private void initComponents() {
frame.setVisible(true);
frame.requestFocus();
frame.toFront();

JRootPane rootPane = frame.getRootPane();
rootPane.registerKeyboardAction ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_W, menuShortcutKeyMask), JComponent.WHEN_IN_FOCUSED_WINDOW );

} finally {
WindowsAppUserMode.setMainId();
}
Expand Down

0 comments on commit 0bd43cb

Please sign in to comment.