From 4c9bcf64d8be50d77d122340ebdbc01173fb506f Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Sat, 28 Apr 2012 18:46:45 +0400 Subject: [PATCH] IDEA-73775 Close content shortcut closes dialogs. --- .../openapi/actionSystem/CommonShortcuts.java | 6 +++ .../intellij/openapi/ui/DialogWrapper.java | 42 ++++++++++--------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java index 415bd600254e..069b7ca89f87 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java @@ -105,4 +105,10 @@ public class CommonShortcuts { public static ShortcutSet getContextHelp() { return new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_CONTEXT_HELP)); } + + public static ShortcutSet getCloseActiveWindow() { + return new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_CLOSE)); + } + + } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index 5a1379b16642..bff6336086e2 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -1400,7 +1400,7 @@ public abstract class DialogWrapper { } private void registerKeyboardShortcuts() { - getRootPane().registerKeyboardAction(new ActionListener() { + ActionListener cancelKeyboardAction = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); MenuElement[] selectedPath = menuSelectionManager.getSelectedPath(); @@ -1411,30 +1411,19 @@ public abstract class DialogWrapper { doCancelAction(e); } } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); + }; + getRootPane().registerKeyboardAction(cancelKeyboardAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); + registerForEveryKeyboardShortcut(cancelKeyboardAction, CommonShortcuts.getCloseActiveWindow()); if (ApplicationInfo.contextHelpAvailable()) { - ShortcutSet help = CommonShortcuts.getContextHelp(); - for (Shortcut shortcut : help.getShortcuts()) { - if (shortcut instanceof KeyboardShortcut) { - KeyboardShortcut ks = (KeyboardShortcut)shortcut; - KeyStroke first = ks.getFirstKeyStroke(); - KeyStroke second = ks.getSecondKeyStroke(); - if (second == null) { - getRootPane().registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - doHelpAction(); - } - }, first, JComponent.WHEN_IN_FOCUSED_WINDOW); - } - } - } - - getRootPane().registerKeyboardAction(new ActionListener() { + ActionListener helpAction = new ActionListener() { public void actionPerformed(ActionEvent e) { doHelpAction(); } - }, KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); + }; + + registerForEveryKeyboardShortcut(helpAction, CommonShortcuts.getContextHelp()); + getRootPane().registerKeyboardAction(helpAction, KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); } if (myButtons != null) { @@ -1459,6 +1448,19 @@ public abstract class DialogWrapper { } } + private void registerForEveryKeyboardShortcut(ActionListener action, ShortcutSet shortcuts) { + for (Shortcut shortcut : shortcuts.getShortcuts()){ + if (shortcut instanceof KeyboardShortcut) { + KeyboardShortcut ks = (KeyboardShortcut)shortcut; + KeyStroke first = ks.getFirstKeyStroke(); + KeyStroke second = ks.getSecondKeyStroke(); + if (second == null) { + getRootPane().registerKeyboardAction(action, first, JComponent.WHEN_IN_FOCUSED_WINDOW); + } + } + } + } + private void focusPreviousButton() { for (int i = 0; i < myButtons.length; i++) { if (myButtons[i].hasFocus()) {