IDEA-125566 Start From Scratch: can't close Customize IDEA dialog

This commit is contained in:
Vassiliy
2014-05-30 17:37:27 +04:00
parent ab7b2a0ecf
commit 8150b8b3a2
2 changed files with 38 additions and 24 deletions
@@ -1569,33 +1569,17 @@ public abstract class DialogWrapper {
}
private void registerKeyboardShortcuts() {
ActionListener cancelKeyboardAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager();
MenuElement[] selectedPath = menuSelectionManager.getSelectedPath();
if (selectedPath.length > 0) { // hide popup menu if any
menuSelectionManager.clearSelectedPath();
}
else {
if (ApplicationManager.getApplication() == null) {
doCancelAction(e);
return;
}
final StackingPopupDispatcher popupDispatcher = StackingPopupDispatcher.getInstance();
if (popupDispatcher != null && !popupDispatcher.isPopupFocused()) {
doCancelAction(e);
}
}
}
};
final JRootPane rootPane = getRootPane();
if (rootPane == null) return;
rootPane.registerKeyboardAction(cancelKeyboardAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
registerForEveryKeyboardShortcut(cancelKeyboardAction, CommonShortcuts.getCloseActiveWindow());
ActionListener cancelKeyboardAction = createCancelAction();
if (cancelKeyboardAction != null) {
rootPane
.registerKeyboardAction(cancelKeyboardAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
registerForEveryKeyboardShortcut(cancelKeyboardAction, CommonShortcuts.getCloseActiveWindow());
}
if (ApplicationInfo.contextHelpAvailable()) {
ActionListener helpAction = new ActionListener() {
@@ -1633,6 +1617,34 @@ public abstract class DialogWrapper {
}
}
/**
*
* @return null if we should ignore <Esc> for window closing
*/
@Nullable
protected ActionListener createCancelAction() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager();
MenuElement[] selectedPath = menuSelectionManager.getSelectedPath();
if (selectedPath.length > 0) { // hide popup menu if any
menuSelectionManager.clearSelectedPath();
}
else {
if (ApplicationManager.getApplication() == null) {
doCancelAction(e);
return;
}
final StackingPopupDispatcher popupDispatcher = StackingPopupDispatcher.getInstance();
if (popupDispatcher != null && !popupDispatcher.isPopupFocused()) {
doCancelAction(e);
}
}
}
};
}
private void registerForEveryKeyboardShortcut(ActionListener action, @NotNull ShortcutSet shortcuts) {
for (Shortcut shortcut : shortcuts.getShortcuts()) {
if (shortcut instanceof KeyboardShortcut) {
@@ -21,6 +21,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.ui.JBCardLayout;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
@@ -148,9 +149,10 @@ public class CustomizeIDEWizardDialog extends DialogWrapper implements ActionLis
}
}
@Nullable
@Override
public void doCancelAction() {
// lets pretend it is the wind..
protected ActionListener createCancelAction() {
return null;//Prevent closing by <Esc>
}
@Override