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 967d918e41b7..1735d41c10dc 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -31,6 +31,7 @@ import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.StackingPopupDispatcher; +import com.intellij.openapi.ui.popup.util.PopupUtil; import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; @@ -1720,20 +1721,8 @@ public abstract class DialogWrapper { 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); - } + if (!PopupUtil.handleEscKeyEvent()) { + doCancelAction(e); } } }; diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/util/PopupUtil.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/util/PopupUtil.java index f6b844ff7f98..fa1ce0b8617b 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/util/PopupUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/util/PopupUtil.java @@ -21,10 +21,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.MessageType; -import com.intellij.openapi.ui.popup.Balloon; -import com.intellij.openapi.ui.popup.BalloonBuilder; -import com.intellij.openapi.ui.popup.JBPopup; -import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.ui.popup.*; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.WindowManager; @@ -205,4 +202,23 @@ public class PopupUtil { ComboPopup popup = ReflectionUtil.getField(comboBox.getUI().getClass(), comboBox.getUI(), ComboPopup.class, "popup"); return popup != null && SwingUtilities.isDescendingFrom(popup.getList(), component); } + + public static boolean handleEscKeyEvent() { + MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); + MenuElement[] selectedPath = menuSelectionManager.getSelectedPath(); + if (selectedPath.length > 0) { // hide popup menu if any + menuSelectionManager.clearSelectedPath(); + return true; + } + else { + if (ApplicationManager.getApplication() == null) { + return false; + } + final StackingPopupDispatcher popupDispatcher = StackingPopupDispatcher.getInstance(); + if (popupDispatcher != null && !popupDispatcher.isPopupFocused()) { + return false; + } + return true; + } + } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java index 3d0dbeeb2b7e..2e8c451441da 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java @@ -18,14 +18,16 @@ package com.intellij.openapi.ui; import com.intellij.ide.DataManager; import com.intellij.ide.ui.UISettings; import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.CommonShortcuts; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; import com.intellij.openapi.actionSystem.impl.MouseGestureManager; import com.intellij.openapi.application.impl.ApplicationInfoImpl; -import com.intellij.openapi.project.*; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.project.ProjectManagerAdapter; +import com.intellij.openapi.project.ProjectManagerListener; +import com.intellij.openapi.ui.popup.util.PopupUtil; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.SystemInfo; @@ -49,9 +51,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.awt.event.FocusEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; +import java.awt.event.*; import java.io.File; import java.util.Map; @@ -227,14 +227,10 @@ public class FrameWrapper implements Disposable, DataProvider { } private void addCloseOnEsc(final RootPaneContainer frame) { - new DumbAwareAction() { + frame.getRootPane().registerKeyboardAction(new ActionListener() { @Override - public void actionPerformed(@NotNull AnActionEvent e) { - MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); - MenuElement[] selectedPath = menuSelectionManager.getSelectedPath(); - if (selectedPath.length > 0) { // hide popup menu if any - menuSelectionManager.clearSelectedPath(); - } else { + public void actionPerformed(ActionEvent e) { + if (!PopupUtil.handleEscKeyEvent()) { // if you remove this line problems will start happen on Mac OS X // 2 projects opened, call Cmd+D on the second opened project and then Esc. // Weird situation: 2nd IdeFrame will be active, but focus will be somewhere inside the 1st IdeFrame @@ -243,7 +239,7 @@ public class FrameWrapper implements Disposable, DataProvider { close(); } } - }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myComponent, this); + }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); } public Window getFrame() {