1 package com.intellij.openapi.vcs.actions;
3 import com.intellij.openapi.actionSystem.AnActionEvent;
4 import com.intellij.openapi.fileTypes.FileType;
5 import com.intellij.openapi.project.DumbAware;
6 import com.intellij.openapi.vcs.AbstractVcs;
7 import com.intellij.openapi.vcs.FilePath;
8 import com.intellij.openapi.vcs.annotate.FileAnnotation;
9 import com.intellij.openapi.vcs.annotate.UpToDateLineNumberListener;
10 import com.intellij.openapi.vcs.history.VcsFileRevision;
11 import com.intellij.openapi.vcs.history.VcsFileRevisionEx;
12 import com.intellij.openapi.vcs.vfs.VcsFileSystem;
13 import com.intellij.openapi.vcs.vfs.VcsVirtualFile;
14 import com.intellij.openapi.vfs.VirtualFile;
15 import com.intellij.vcsUtil.VcsUtil;
16 import org.jetbrains.annotations.NotNull;
17 import org.jetbrains.annotations.Nullable;
20 import java.util.List;
22 abstract class AnnotateRevisionAction extends AnnotateRevisionActionBase implements DumbAware, UpToDateLineNumberListener {
23 @NotNull private final FileAnnotation myAnnotation;
24 @NotNull private final AbstractVcs myVcs;
26 private int currentLine;
28 public AnnotateRevisionAction(@Nullable String text, @Nullable String description, @Nullable Icon icon,
29 @NotNull FileAnnotation annotation, @NotNull AbstractVcs vcs) {
30 super(text, description, icon);
31 myAnnotation = annotation;
36 public void update(@NotNull AnActionEvent e) {
37 if (getRevisions() == null) {
38 e.getPresentation().setEnabledAndVisible(false);
41 e.getPresentation().setVisible(true);
47 protected abstract List<VcsFileRevision> getRevisions();
50 protected AbstractVcs getVcs(@NotNull AnActionEvent e) {
56 protected VirtualFile getFile(@NotNull AnActionEvent e) {
57 VcsFileRevision revision = getFileRevision(e);
58 if (revision == null) return null;
60 final FileType currentFileType = myAnnotation.getFile().getFileType();
62 (revision instanceof VcsFileRevisionEx ? ((VcsFileRevisionEx)revision).getPath() : VcsUtil.getFilePath(myAnnotation.getFile()));
63 return new VcsVirtualFile(filePath.getPath(), revision, VcsFileSystem.getInstance()) {
66 public FileType getFileType() {
67 FileType type = super.getFileType();
68 return type.isBinary() ? currentFileType : type;
75 protected VcsFileRevision getFileRevision(@NotNull AnActionEvent e) {
76 List<VcsFileRevision> revisions = getRevisions();
77 assert getRevisions() != null;
79 if (currentLine < 0 || currentLine >= revisions.size()) return null;
80 return revisions.get(currentLine);
84 public void consume(Integer integer) {
85 currentLine = integer;