diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/EditorTracker.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/EditorTracker.java index 9087247b6169..8495c587c270 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/EditorTracker.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/EditorTracker.java @@ -60,7 +60,6 @@ public class EditorTracker extends AbstractProjectComponent { private final Map myEditorToWindowMap = new HashMap(); private List myActiveEditors = Collections.emptyList(); - private MyEditorFactoryListener myEditorFactoryListener; private final EventDispatcher myDispatcher = EventDispatcher.create(EditorTrackerListener.class); private IdeFrameImpl myIdeFrame; @@ -85,12 +84,11 @@ public class EditorTracker extends AbstractProjectComponent { } }); - myEditorFactoryListener = new MyEditorFactoryListener(); - myEditorFactory.addEditorFactoryListener(myEditorFactoryListener); + final MyEditorFactoryListener myEditorFactoryListener = new MyEditorFactoryListener(); + myEditorFactory.addEditorFactoryListener(myEditorFactoryListener,myProject); Disposer.register(myProject, new Disposable() { public void dispose() { myEditorFactoryListener.dispose(null); - myEditorFactory.removeEditorFactoryListener(myEditorFactoryListener); } }); } @@ -222,12 +220,8 @@ public class EditorTracker extends AbstractProjectComponent { myDispatcher.getMulticaster().activeEditorsChanged(editors); } - public void addEditorTrackerListener(EditorTrackerListener listener) { - myDispatcher.addListener(listener); - } - - public void removeEditorTrackerListener(EditorTrackerListener listener) { - myDispatcher.removeListener(listener); + public void addEditorTrackerListener(@NotNull EditorTrackerListener listener, @NotNull Disposable parentDisposable) { + myDispatcher.addListener(listener,parentDisposable); } private class MyEditorFactoryListener implements EditorFactoryListener { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java index 7e17c991bcfc..3a386a25e6ca 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java @@ -24,14 +24,12 @@ import com.intellij.codeInsight.documentation.DocumentationManager; import com.intellij.codeInsight.hint.EditorHintListener; import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.lookup.*; -import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.event.EditorFactoryAdapter; import com.intellij.openapi.editor.event.EditorFactoryEvent; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.ui.LightweightHint; @@ -84,12 +82,7 @@ public class LookupManagerImpl extends LookupManager { } } }; - EditorFactory.getInstance().addEditorFactoryListener(myEditorFactoryListener); - Disposer.register(myProject, new Disposable() { - public void dispose() { - EditorFactory.getInstance().removeEditorFactoryListener(myEditorFactoryListener); - } - }); + EditorFactory.getInstance().addEditorFactoryListener(myEditorFactoryListener, myProject); } public Lookup showLookup(final Editor editor, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java index 3e2fa71f1335..652f1daa0806 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java @@ -78,12 +78,7 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo editor.putUserData(TEMPLATE_STATE_KEY, null); } }; - EditorFactory.getInstance().addEditorFactoryListener(myEditorFactoryListener); - Disposer.register(myProject, new Disposable() { - public void dispose() { - EditorFactory.getInstance().removeEditorFactoryListener(myEditorFactoryListener); - } - }); + EditorFactory.getInstance().addEditorFactoryListener(myEditorFactoryListener, myProject); } public void setTemplateTesting(final boolean templateTesting) { diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 093cbf98b966..94bbf5de32b3 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -492,12 +492,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { } } }; - EditorFactory.getInstance().addEditorFactoryListener(factoryListener); - Disposer.register(this, new Disposable() { - public void dispose() { - EditorFactory.getInstance().removeEditorFactoryListener(factoryListener); - } - }); + EditorFactory.getInstance().addEditorFactoryListener(factoryListener, this); } protected void registerActionShortcuts(JComponent component) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java index 4a7329b1e846..ffbcf2da2e61 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java @@ -105,11 +105,10 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme @Override public void projectOpened() { myPsiManager.addPsiTreeChangeListener(this); - EditorFactory.getInstance().addEditorFactoryListener(this); + EditorFactory.getInstance().addEditorFactoryListener(this,myProject); Disposer.register(myProject, new Disposable() { public void dispose() { myPsiManager.removePsiTreeChangeListener(ChangeSignatureGestureDetector.this); - EditorFactory.getInstance().removeEditorFactoryListener(ChangeSignatureGestureDetector.this); LOG.assertTrue(myListenerMap.isEmpty(), myListenerMap); } }); diff --git a/platform/platform-api/src/com/intellij/openapi/editor/EditorFactory.java b/platform/platform-api/src/com/intellij/openapi/editor/EditorFactory.java index 20f4ec47c6d7..78c7ce26b9b0 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/EditorFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/EditorFactory.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.editor; +import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ApplicationComponent; @@ -161,14 +162,25 @@ public abstract class EditorFactory implements ApplicationComponent { * and released. * * @param listener the listener instance. + * @deprecated use the {@link #addEditorFactoryListener(EditorFactoryListener, Disposable)} instead */ public abstract void addEditorFactoryListener(@NotNull EditorFactoryListener listener); + /** + * Registers a listener for receiving notifications when editor instances are created and released + * and removes the listener when {@link parentDisposable} get disposed. + * + * @param listener the listener instance. + * @param parentDisposable the Disposable which triggers the removal of the listener + */ + public abstract void addEditorFactoryListener(@NotNull EditorFactoryListener listener, @NotNull Disposable parentDisposable); + /** * Unregisters a listener for receiving notifications when editor instances are created * and released. * * @param listener the listener instance. + * @deprecated you should have used the {@link #addEditorFactoryListener(EditorFactoryListener, Disposable)} instead */ public abstract void removeEditorFactoryListener(@NotNull EditorFactoryListener listener); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java index 866098615cf8..5a7cf84cf03c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorFactoryImpl.java @@ -16,6 +16,7 @@ package com.intellij.openapi.editor.impl; import com.intellij.injected.editor.DocumentWindow; +import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ModalityStateListener; import com.intellij.openapi.application.impl.LaterInvocator; import com.intellij.openapi.diagnostic.Logger; @@ -212,6 +213,11 @@ public class EditorFactoryImpl extends EditorFactory { myEditorFactoryEventDispatcher.addListener(listener); } + @Override + public void addEditorFactoryListener(@NotNull EditorFactoryListener listener, @NotNull Disposable parentDisposable) { + myEditorFactoryEventDispatcher.addListener(listener,parentDisposable); + } + public void removeEditorFactoryListener(@NotNull EditorFactoryListener listener) { myEditorFactoryEventDispatcher.removeListener(listener); } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index 7c0201e3a10c..be3d0e920fa3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -934,8 +934,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt public void addProjectManagerListener(Project project, ProjectManagerListener listener) { List listeners = project.getUserData(LISTENERS_IN_PROJECT_KEY); if (listeners == null) { - listeners = new ArrayList(); - project.putUserData(LISTENERS_IN_PROJECT_KEY, listeners); + listeners = ((UserDataHolderEx)project).putUserDataIfAbsent(LISTENERS_IN_PROJECT_KEY, new ArrayList()); } listeners.add(listener); } diff --git a/platform/testFramework/src/com/intellij/mock/MockEditorFactory.java b/platform/testFramework/src/com/intellij/mock/MockEditorFactory.java index 378f0944ada6..fa9a832be149 100644 --- a/platform/testFramework/src/com/intellij/mock/MockEditorFactory.java +++ b/platform/testFramework/src/com/intellij/mock/MockEditorFactory.java @@ -15,6 +15,7 @@ */ package com.intellij.mock; +import com.intellij.openapi.Disposable; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -88,6 +89,10 @@ public class MockEditorFactory extends EditorFactory { public void addEditorFactoryListener(@NotNull EditorFactoryListener listener) { } + @Override + public void addEditorFactoryListener(@NotNull EditorFactoryListener listener, @NotNull Disposable parentDisposable) { + } + @Override public void removeEditorFactoryListener(@NotNull EditorFactoryListener listener) { } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.java index 3549106eb496..5bd61146daad 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.java @@ -114,7 +114,7 @@ public class LineStatusTrackerManager implements ProjectComponent { fsManager.addFileStatusListener(fileStatusListener, myProject); final EditorFactory editorFactory = EditorFactory.getInstance(); - editorFactory.addEditorFactoryListener(editorFactoryListener); + editorFactory.addEditorFactoryListener(editorFactoryListener,myProject); final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance(); virtualFileManager.addVirtualFileListener(virtualFileListener,myProject); @@ -126,7 +126,6 @@ public class LineStatusTrackerManager implements ProjectComponent { public void dispose() { trackAwtThread(); fsManager.removeFileStatusListener(fileStatusListener); - editorFactory.removeEditorFactoryListener(editorFactoryListener); virtualFileManager.removeVirtualFileListener(virtualFileListener); editorColorsManager.removeEditorColorsListener(editorColorsListener); } diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/quickedit/QuickEditAction.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/quickedit/QuickEditAction.java index 1b14caf3978a..4bb9a1a5e4b5 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/quickedit/QuickEditAction.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/quickedit/QuickEditAction.java @@ -128,7 +128,7 @@ public class QuickEditAction implements IntentionAction, LowPriorityAction { return false; } - private static Key QUICK_EDIT_HANDLER = Key.create("QUICK_EDIT_HANDLER"); + private static final Key QUICK_EDIT_HANDLER = Key.create("QUICK_EDIT_HANDLER"); @NotNull private static MyHandler getHandler(Project project, PsiFile injectedFile, Editor editor, PsiFile origFile) { MyHandler handler = injectedFile.getUserData(QUICK_EDIT_HANDLER); @@ -212,7 +212,7 @@ public class QuickEditAction implements IntentionAction, LowPriorityAction { myInjectedFile.putUserData(QUICK_EDIT_HANDLER, null); } } - }); + }, project); initMarkers(shreds); }