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 30996784a987..0b56ef4755e3 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -741,35 +741,39 @@ public abstract class DialogWrapper { final JRootPane rootPane = getRootPane(); // if rootPane = null, dialog has already been disposed if (rootPane != null) { - new AwtVisitor(rootPane) { - public boolean visit(final Component component) { - if (component instanceof JComponent) { - final JComponent eachComp = (JComponent)component; - final ActionMap actionMap = eachComp.getActionMap(); - final KeyStroke[] strokes = eachComp.getRegisteredKeyStrokes(); - for (KeyStroke eachStroke : strokes) { - boolean remove = true; - if (actionMap != null) { - for (int i = 0; i < 3; i++) { - final InputMap inputMap = eachComp.getInputMap(i); - final Object key = inputMap.get(eachStroke); - if (key != null) { - final Action action = actionMap.get(key); - if (action instanceof UIResource) remove = false; - } - } - } - - if (remove) eachComp.unregisterKeyboardAction(eachStroke); - } - } - return false; - } - }; + unregisterKeyboardActions(rootPane); myPeer.dispose(); } } + public static void unregisterKeyboardActions(final JRootPane rootPane) { + new AwtVisitor(rootPane) { + public boolean visit(final Component component) { + if (component instanceof JComponent) { + final JComponent eachComp = (JComponent)component; + final ActionMap actionMap = eachComp.getActionMap(); + final KeyStroke[] strokes = eachComp.getRegisteredKeyStrokes(); + for (KeyStroke eachStroke : strokes) { + boolean remove = true; + if (actionMap != null) { + for (int i = 0; i < 3; i++) { + final InputMap inputMap = eachComp.getInputMap(i); + final Object key = inputMap.get(eachStroke); + if (key != null) { + final Action action = actionMap.get(key); + if (action instanceof UIResource) remove = false; + } + } + } + + if (remove) eachComp.unregisterKeyboardAction(eachStroke); + } + } + return false; + } + }; + } + /** * This method is invoked by default implementation of "Cancel" action. It just closes dialog 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 abbaba1700c9..b5f7116dacb7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java @@ -129,7 +129,7 @@ public class FrameWrapper implements Disposable, DataProvider { } else { ((JDialog)frame).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } - WindowAdapter focusListener = new WindowAdapter() { + final WindowAdapter focusListener = new WindowAdapter() { public void windowOpened(WindowEvent e) { IdeFocusManager fm = IdeFocusManager.getInstance(myProject); JComponent toFocus = myPreferedFocus; @@ -145,6 +145,12 @@ public class FrameWrapper implements Disposable, DataProvider { } }; frame.addWindowListener(focusListener); + Disposer.register(this, new Disposable() { + @Override + public void dispose() { + frame.removeWindowListener(focusListener); + } + }); if (myCloseOnEsc) addCloseOnEsc((RootPaneContainer)frame); ((RootPaneContainer)frame).getContentPane().add(myComponent, BorderLayout.CENTER); if (frame instanceof JFrame) { @@ -181,6 +187,12 @@ public class FrameWrapper implements Disposable, DataProvider { if (isDisposed()) return; Window frame = getFrame(); + + final JRootPane rootPane = ((RootPaneContainer)frame).getRootPane(); + if (rootPane != null) { + DialogWrapper.unregisterKeyboardActions(rootPane); + } + frame.setVisible(false); frame.dispose();