mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: correct closing of annotations (+ unregister when editor closes etc)
This commit is contained in:
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.annotate;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsKey;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -27,8 +30,13 @@ import java.util.List;
|
||||
* A provider of file annotations related to VCS
|
||||
*/
|
||||
public abstract class FileAnnotation {
|
||||
private final Project myProject;
|
||||
private Runnable myCloser;
|
||||
|
||||
protected FileAnnotation(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is invoked when the annotation provider is no
|
||||
* more used by UI.
|
||||
@@ -121,4 +129,10 @@ public abstract class FileAnnotation {
|
||||
final VcsRevisionNumber currentRevision = getCurrentRevision();
|
||||
return currentRevision != null && ! currentRevision.equals(number);
|
||||
}
|
||||
|
||||
public abstract VirtualFile getFile();
|
||||
|
||||
public void unregister() {
|
||||
ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener().unregisterAnnotation(getFile(), this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,9 +199,6 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann
|
||||
editor.getGutter().closeAllAnnotations();
|
||||
}
|
||||
});
|
||||
if (onCurrentRevision) {
|
||||
listener.unregisterAnnotation(file, fileAnnotation);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (onCurrentRevision) {
|
||||
|
||||
@@ -132,6 +132,7 @@ public class AnnotationFieldGutter implements ActiveAnnotationGutter {
|
||||
}
|
||||
|
||||
public void gutterClosed() {
|
||||
myAnnotation.unregister();
|
||||
myAnnotation.dispose();
|
||||
final Collection<ActiveAnnotationGutter> gutters = myEditor.getUserData(AnnotateToggleAction.KEY_IN_EDITOR);
|
||||
if (gutters != null) {
|
||||
|
||||
+3
@@ -213,6 +213,9 @@ public class VcsAnnotationLocalChangesListenerImpl implements Disposable, VcsAnn
|
||||
if (annotations != null && ! annotations.isEmpty()) {
|
||||
annotations.remove(annotation);
|
||||
}
|
||||
if (annotations != null && annotations.isEmpty()) {
|
||||
myFileAnnotationMap.remove(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ public class CvsAnnotationProvider implements AnnotationProvider{
|
||||
final List<VcsFileRevision> revisions = myCvsHistoryProvider.createRevisions(filePath);
|
||||
final Annotation[] lineAnnotations = operation.getLineAnnotations();
|
||||
adjustAnnotation(revisions, lineAnnotations);
|
||||
return new CvsFileAnnotation(operation.getContent(), lineAnnotations, revisions, virtualFile, revision);
|
||||
return new CvsFileAnnotation(operation.getContent(), lineAnnotations, revisions, virtualFile, revision, myProject);
|
||||
}
|
||||
|
||||
public FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException {
|
||||
@@ -118,7 +118,7 @@ public class CvsAnnotationProvider implements AnnotationProvider{
|
||||
}
|
||||
}
|
||||
}
|
||||
return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile, revision);
|
||||
return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile, revision, myProject);
|
||||
}
|
||||
|
||||
private static boolean annotateBinary(VirtualFile cvsVirtualFile, CvsEnvironment environment) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.cvsSupport2.application.CvsEntriesManager;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation;
|
||||
import com.intellij.cvsSupport2.cvsstatuses.CvsEntriesListener;
|
||||
import com.intellij.cvsSupport2.history.CvsRevisionNumber;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.VcsKey;
|
||||
import com.intellij.openapi.vcs.annotate.AnnotationSourceSwitcher;
|
||||
import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
@@ -77,7 +78,8 @@ public class CvsFileAnnotation extends FileAnnotation{
|
||||
|
||||
|
||||
public CvsFileAnnotation(final String content, final Annotation[] annotations,
|
||||
@Nullable final List<VcsFileRevision> revisions, VirtualFile file, String currentRevision) {
|
||||
@Nullable final List<VcsFileRevision> revisions, VirtualFile file, String currentRevision, Project project) {
|
||||
super(project);
|
||||
myContent = content;
|
||||
myAnnotations = annotations;
|
||||
myRevisions = revisions;
|
||||
@@ -200,4 +202,9 @@ public class CvsFileAnnotation extends FileAnnotation{
|
||||
public VcsKey getVcsKey() {
|
||||
return CvsVcs2.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile getFile() {
|
||||
return myFile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ public class GitFileAnnotation extends FileAnnotation {
|
||||
* @param revision
|
||||
*/
|
||||
public GitFileAnnotation(@NotNull final Project project, @NotNull VirtualFile file, final boolean monitorFlag, final VcsRevisionNumber revision) {
|
||||
super(project);
|
||||
myProject = project;
|
||||
myVcs = GitVcs.getInstance(myProject);
|
||||
myFile = file;
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.vcs.annotate.*;
|
||||
import com.intellij.openapi.vcs.changes.CurrentContentRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -56,6 +57,7 @@ public class HgAnnotation extends FileAnnotation {
|
||||
|
||||
public HgAnnotation(@NotNull Project project, @NotNull HgFile hgFile, @NotNull List<HgAnnotationLine> lines,
|
||||
@NotNull List<HgFileRevision> vcsFileRevisions, VcsRevisionNumber revision) {
|
||||
super(project);
|
||||
myProject = project;
|
||||
myLines = lines;
|
||||
myFileRevisions = vcsFileRevisions;
|
||||
@@ -214,4 +216,9 @@ public class HgAnnotation extends FileAnnotation {
|
||||
public VcsKey getVcsKey() {
|
||||
return HgVcs.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile getFile() {
|
||||
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myFile.getFile());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +159,7 @@ public abstract class BaseSvnFileAnnotation extends FileAnnotation {
|
||||
}
|
||||
|
||||
public BaseSvnFileAnnotation(final SvnVcs vcs, final String contents, final VcsRevisionNumber baseRevision) {
|
||||
super(vcs.getProject());
|
||||
myVcs = vcs;
|
||||
myContents = contents;
|
||||
myBaseRevision = baseRevision;
|
||||
|
||||
@@ -49,4 +49,9 @@ public class SvnRemoteFileAnnotation extends BaseSvnFileAnnotation {
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile getFile() {
|
||||
return myCurrentFile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user