mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
leaks: unregister shortcuts and detach listeners
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user