To support plugin unloading from Search Everywhere, store weak reference to editor component (IDEA-233601)

GitOrigin-RevId: 1114c3dadf8316a6f922c49e28a79f324f47506a
This commit is contained in:
Dmitry Jemerov
2020-03-10 09:34:33 +00:00
committed by intellij-monorepo-bot
parent 6e3069867d
commit f6231edb77
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.util.gotoByName;
@@ -54,6 +54,7 @@ import javax.accessibility.AccessibleContext;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.*;
import java.util.regex.Matcher;
@@ -71,7 +72,7 @@ public class GotoActionModel implements ChooseByNameModel, Comparator<Object>, D
@Nullable private final Project myProject;
private final Component myContextComponent;
@Nullable private final Editor myEditor;
@Nullable private final WeakReference<Editor> myEditor;
protected final ActionManager myActionManager = ActionManager.getInstance();
@@ -100,7 +101,7 @@ public class GotoActionModel implements ChooseByNameModel, Comparator<Object>, D
public GotoActionModel(@Nullable Project project, Component component, @Nullable Editor editor, @Nullable ModalityState modalityState) {
myProject = project;
myContextComponent = component;
myEditor = editor;
myEditor = new WeakReference<>(editor);
myModality = modalityState;
buildActions();
}
@@ -120,10 +121,11 @@ public class GotoActionModel implements ChooseByNameModel, Comparator<Object>, D
@NotNull
Map<String, ApplyIntentionAction> getAvailableIntentions() {
Map<String, ApplyIntentionAction> map = new TreeMap<>();
Editor editor = myEditor != null ? myEditor.get() : null;
if (myProject != null && !myProject.isDisposed() && !DumbService.isDumb(myProject) &&
myEditor != null && !myEditor.isDisposed()) {
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
ApplyIntentionAction[] children = file == null ? null : ApplyIntentionAction.getAvailableIntentions(myEditor, file);
editor != null && !editor.isDisposed()) {
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
ApplyIntentionAction[] children = file == null ? null : ApplyIntentionAction.getAvailableIntentions(editor, file);
if (children != null) {
for (ApplyIntentionAction action : children) {
map.put(action.getName(), action);