From 8bef182ed5762fbb19512b76572e49136a51281d Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 18 Jun 2013 13:29:38 +0200 Subject: [PATCH] IDEA-105708 "Annotate" command works incorrectly --- .../vcs/actions/AnnotateToggleAction.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) 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 37ab3dd37a6b..b869c574b0f9 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 @@ -101,7 +101,25 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann public boolean isSelected(AnActionEvent e) { VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e); Editor editor = context.getEditor(); - if (editor == null) return false; + if (editor != null) { + return isAnnotated(editor); + } + VirtualFile selectedFile = context.getSelectedFile(); + if (selectedFile == null) { + return false; + } + + for (FileEditor fileEditor : FileEditorManager.getInstance(context.getProject()).getEditors(selectedFile)) { + if (fileEditor instanceof TextEditor) { + if (isAnnotated(((TextEditor)fileEditor).getEditor())) { + return true; + } + } + } + return false; + } + + private static boolean isAnnotated(@NotNull Editor editor) { Collection annotations = editor.getUserData(KEY_IN_EDITOR); return annotations != null && !annotations.isEmpty(); } @@ -109,14 +127,18 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann public void setSelected(AnActionEvent e, boolean selected) { final VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e); Editor editor = context.getEditor(); + VirtualFile selectedFile = context.getSelectedFile(); + if (selectedFile == null) return; + if (!selected) { - if (editor != null) { - editor.getGutter().closeAllAnnotations(); + for (FileEditor fileEditor : FileEditorManager.getInstance(context.getProject()).getEditors(selectedFile)) { + if (fileEditor instanceof TextEditor) { + ((TextEditor)fileEditor).getEditor().getGutter().closeAllAnnotations(); + } } } else { if (editor == null) { - VirtualFile selectedFile = context.getSelectedFile(); FileEditor[] fileEditors = FileEditorManager.getInstance(context.getProject()).openFile(selectedFile, false); for (FileEditor fileEditor : fileEditors) { if (fileEditor instanceof TextEditor) {