IDEA-125566 Start From Scratch: can't close Customize IDEA dialog
authorVassiliy <vassiliy.kudryashov@jetbrains.com>
Fri, 30 May 2014 13:36:31 +0000 (17:36 +0400)
committerVassiliy <vassiliy.kudryashov@jetbrains.com>
Fri, 30 May 2014 13:37:27 +0000 (17:37 +0400)
platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java
platform/platform-impl/src/com/intellij/ide/customize/CustomizeIDEWizardDialog.java

index 0144cf4fb58b249728517d077ee42b4c977e34a4..188618e2f31998c194c358eacef3f9ef36da7f97 100644 (file)
@@ -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) {
index 0d62d30fa51187481de05e7c9f3706ac60c4c700..1b0644a3a20fa7929994d6da0297612ab689a559 100644 (file)
@@ -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