From 2fbbcbf39c9c4e43388fc262c28271498ea7dace Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Sat, 20 Jun 2015 15:00:25 +0300 Subject: [PATCH] vcs annotate: cleanup - remove unnecessary user data key --- .../intellij/openapi/editor/EditorGutter.java | 2 ++ .../editor/ex/EditorGutterComponentEx.java | 2 -- .../vcs/actions/AnnotateToggleAction.java | 18 ++++-------------- .../vcs/actions/AnnotationFieldGutter.java | 6 ------ 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/EditorGutter.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/EditorGutter.java index b7ce47cc2481..b9404aaac1fb 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/EditorGutter.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/EditorGutter.java @@ -46,6 +46,8 @@ public interface EditorGutter { */ void registerTextAnnotation(@NotNull TextAnnotationGutterProvider provider, @NotNull EditorGutterAction action); + boolean isAnnotationsShown(); + /** * Removes all text annotations from the gutter. */ diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java index 38c8290cea6f..6478aaa96ae5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java @@ -32,8 +32,6 @@ public abstract class EditorGutterComponentEx extends JComponent implements Edit public abstract boolean isLineMarkersShown(); - public abstract boolean isAnnotationsShown(); - @Nullable public abstract FoldRegion findFoldingAnchorAt(int x, int y); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java index 657a2df5fbf7..0273c10a834e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java @@ -61,7 +61,6 @@ import java.util.List; */ public class AnnotateToggleAction extends ToggleAction implements DumbAware, AnnotationColors { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.actions.AnnotateToggleAction"); - protected static final Key> KEY_IN_EDITOR = Key.create("Annotations"); @Override public void update(@NotNull AnActionEvent e) { @@ -126,8 +125,7 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann } private static boolean isAnnotated(@NotNull Editor editor) { - Collection annotations = editor.getUserData(KEY_IN_EDITOR); - return annotations != null && !annotations.isEmpty(); + return editor.getGutter().isAnnotationsShown(); } @Override @@ -223,10 +221,10 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann final Project project, final VirtualFile file, final FileAnnotation fileAnnotation, - final AbstractVcs vcs, final boolean onCurrentRevision) { + final AbstractVcs vcs, + final boolean onCurrentRevision) { final UpToDateLineNumberProvider getUpToDateLineNumber = new UpToDateLineNumberProviderImpl(editor.getDocument(), project); editor.getGutter().closeAllAnnotations(); - final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(project).getAnnotationLocalChangesListener(); fileAnnotation.setCloser(new Runnable() { @Override @@ -242,14 +240,7 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann } }); if (onCurrentRevision) { - listener.registerAnnotation(file, fileAnnotation); - } - - // be careful, not proxies but original items are put there (since only their presence not behaviour is important) - Collection annotations = editor.getUserData(KEY_IN_EDITOR); - if (annotations == null) { - annotations = new HashSet(); - editor.putUserData(KEY_IN_EDITOR, annotations); + ProjectLevelVcsManager.getInstance(project).getAnnotationLocalChangesListener().registerAnnotation(file, fileAnnotation); } final EditorGutterComponentEx editorGutter = (EditorGutterComponentEx)editor.getGutter(); @@ -318,7 +309,6 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann else { editor.getGutter().registerTextAnnotation(proxy); } - annotations.add(gutter); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationFieldGutter.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationFieldGutter.java index 25069ad9009c..d532835fa54c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationFieldGutter.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationFieldGutter.java @@ -41,7 +41,6 @@ import java.util.Map; */ public class AnnotationFieldGutter implements ActiveAnnotationGutter { protected final FileAnnotation myAnnotation; - private final Editor myEditor; protected final LineAnnotationAspect myAspect; private final TextAnnotationPresentation myPresentation; private final boolean myIsGutterAction; @@ -53,7 +52,6 @@ public class AnnotationFieldGutter implements ActiveAnnotationGutter { final TextAnnotationPresentation presentation, Couple> colorScheme) { myAnnotation = annotation; - myEditor = editor; myAspect = aspect; myPresentation = presentation; myIsGutterAction = myAspect instanceof EditorGutterAction; @@ -137,10 +135,6 @@ public class AnnotationFieldGutter implements ActiveAnnotationGutter { public void gutterClosed() { myAnnotation.unregister(); myAnnotation.dispose(); - final Collection gutters = myEditor.getUserData(AnnotateToggleAction.KEY_IN_EDITOR); - if (gutters != null) { - gutters.remove(this); - } } @Nullable