IDEA-73775 Close content shortcut closes dialogs.

This commit is contained in:
Maxim Shafirov
2012-04-28 18:49:45 +04:00
parent 4206aea3a4
commit 4c9bcf64d8
2 changed files with 28 additions and 20 deletions
@@ -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));
}
}
@@ -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()) {