use of com.intellij.openapi.vcs.annotate.FileAnnotation in project intellij-community by JetBrains.
the class AnnotateLocalFileAction method doAnnotate.
private static void doAnnotate(@NotNull final Editor editor, @NotNull final Project project) {
final VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
if (file == null)
return;
final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
if (vcs == null)
return;
final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
assert annotationProvider != null;
final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
final Ref<VcsException> exceptionRef = new Ref<>();
VcsAnnotateUtil.getBackgroundableLock(project, file).lock();
final Task.Backgroundable annotateTask = new Task.Backgroundable(project, VcsBundle.message("retrieving.annotations"), true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
try {
fileAnnotationRef.set(annotationProvider.annotate(file));
} catch (VcsException e) {
exceptionRef.set(e);
} catch (ProcessCanceledException pce) {
throw pce;
} catch (Throwable t) {
exceptionRef.set(new VcsException(t));
}
}
@Override
public void onCancel() {
onSuccess();
}
@Override
public void onSuccess() {
VcsAnnotateUtil.getBackgroundableLock(project, file).unlock();
if (!exceptionRef.isNull()) {
LOG.warn(exceptionRef.get());
AbstractVcsHelper.getInstance(project).showErrors(Collections.singletonList(exceptionRef.get()), VcsBundle.message("message.title.annotate"));
}
if (!fileAnnotationRef.isNull()) {
AnnotateToggleAction.doAnnotate(editor, project, file, fileAnnotationRef.get(), vcs);
}
}
};
ProgressManager.getInstance().run(annotateTask);
}
use of com.intellij.openapi.vcs.annotate.FileAnnotation in project intellij-community by JetBrains.
the class AnnotateRevisionActionBase method annotate.
public static void annotate(@NotNull VirtualFile file, @NotNull VcsFileRevision fileRevision, @NotNull AbstractVcs vcs, @Nullable Editor editor, int annotatedLine) {
final CharSequence oldContent = editor == null ? null : editor.getDocument().getImmutableCharSequence();
final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
assert annotationProvider != null;
final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
final Ref<Integer> newLineRef = new Ref<>();
final Ref<VcsException> exceptionRef = new Ref<>();
VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).lock();
Semaphore semaphore = new Semaphore(0);
AtomicBoolean shouldOpenEditorInSync = new AtomicBoolean(true);
ProgressManager.getInstance().run(new Task.Backgroundable(vcs.getProject(), VcsBundle.message("retrieving.annotations"), true) {
public void run(@NotNull ProgressIndicator indicator) {
try {
FileAnnotation fileAnnotation = annotationProvider.annotate(file, fileRevision);
int newLine = translateLine(oldContent, fileAnnotation.getAnnotatedContent(), annotatedLine);
fileAnnotationRef.set(fileAnnotation);
newLineRef.set(newLine);
shouldOpenEditorInSync.set(false);
semaphore.release();
} catch (VcsException e) {
exceptionRef.set(e);
}
}
@Override
public void onFinished() {
VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).unlock();
}
@Override
public void onSuccess() {
if (!exceptionRef.isNull()) {
AbstractVcsHelper.getInstance(myProject).showError(exceptionRef.get(), VcsBundle.message("operation.name.annotate"));
}
if (fileAnnotationRef.isNull())
return;
AbstractVcsHelper.getInstance(myProject).showAnnotation(fileAnnotationRef.get(), file, vcs, newLineRef.get());
}
});
try {
semaphore.tryAcquire(ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS, TimeUnit.MILLISECONDS);
// This will remove blinking on editor opening (step 1 - editor opens, step 2 - annotations are shown).
if (shouldOpenEditorInSync.get()) {
CharSequence content = LoadTextUtil.loadText(file);
int newLine = translateLine(oldContent, content, annotatedLine);
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(vcs.getProject(), file, newLine, 0);
FileEditorManager.getInstance(vcs.getProject()).openTextEditor(openFileDescriptor, true);
}
} catch (InterruptedException ignore) {
}
}
use of com.intellij.openapi.vcs.annotate.FileAnnotation in project intellij-community by JetBrains.
the class AnnotateToggleAction method computeBgColors.
@Nullable
private static Couple<Map<VcsRevisionNumber, Color>> computeBgColors(@NotNull FileAnnotation fileAnnotation, @NotNull Editor editor) {
Map<VcsRevisionNumber, Color> commitOrderColors = new HashMap<>();
Map<VcsRevisionNumber, Color> commitAuthorColors = new HashMap<>();
EditorColorsScheme colorScheme = editor.getColorsScheme();
AnnotationsSettings settings = AnnotationsSettings.getInstance();
List<Color> authorsColorPalette = settings.getAuthorsColors(colorScheme);
List<Color> orderedColorPalette = settings.getOrderedColors(colorScheme);
FileAnnotation.AuthorsMappingProvider authorsMappingProvider = fileAnnotation.getAuthorsMappingProvider();
if (authorsMappingProvider != null) {
Map<VcsRevisionNumber, String> authorsMap = authorsMappingProvider.getAuthors();
Map<String, Color> authorColors = new HashMap<>();
for (String author : ContainerUtil.sorted(authorsMap.values(), Comparing::compare)) {
int index = authorColors.size();
Color color = authorsColorPalette.get(index % authorsColorPalette.size());
authorColors.put(author, color);
}
for (Map.Entry<VcsRevisionNumber, String> entry : authorsMap.entrySet()) {
VcsRevisionNumber revision = entry.getKey();
String author = entry.getValue();
Color color = authorColors.get(author);
commitAuthorColors.put(revision, color);
}
}
FileAnnotation.RevisionsOrderProvider revisionsOrderProvider = fileAnnotation.getRevisionsOrderProvider();
if (revisionsOrderProvider != null) {
List<List<VcsRevisionNumber>> orderedRevisions = revisionsOrderProvider.getOrderedRevisions();
int revisionsCount = orderedRevisions.size();
for (int index = 0; index < revisionsCount; index++) {
Color color = orderedColorPalette.get(orderedColorPalette.size() * index / revisionsCount);
for (VcsRevisionNumber number : orderedRevisions.get(index)) {
commitOrderColors.put(number, color);
}
}
}
return Couple.of(commitOrderColors.size() > 1 ? commitOrderColors : null, commitAuthorColors.size() > 1 ? commitAuthorColors : null);
}
use of com.intellij.openapi.vcs.annotate.FileAnnotation in project intellij-community by JetBrains.
the class VcsAnnotationCachedProxy method annotate.
@Override
public FileAnnotation annotate(final VirtualFile file) throws VcsException {
final DiffProvider diffProvider = myVcs.getDiffProvider();
final VcsRevisionNumber currentRevision = diffProvider.getCurrentRevision(file);
return annotate(file, currentRevision, true, new ThrowableComputable<FileAnnotation, VcsException>() {
@Override
public FileAnnotation compute() throws VcsException {
return myAnnotationProvider.annotate(file);
}
});
}
use of com.intellij.openapi.vcs.annotate.FileAnnotation in project intellij-community by JetBrains.
the class CvsAnnotationProvider method annotate.
public FileAnnotation annotate(VirtualFile cvsVirtualFile, String revision, CvsEnvironment environment) throws VcsException {
// the VirtualFile has a full path if annotate is called from history (when we have a real file on disk),
// and has the path equal to a CVS module name if annotate is called from the CVS repository browser
// (when there's no real path)
boolean hasLocalFile = false;
File cvsFile = new File(cvsVirtualFile.getPath());
if (cvsFile.isAbsolute()) {
hasLocalFile = true;
cvsFile = new File(CvsUtil.getModuleName(cvsVirtualFile));
}
final boolean binary = annotateBinary(cvsVirtualFile, environment);
final AnnotateOperation annotateOperation = executeOperation(cvsFile, revision, environment, binary, true);
final Annotation[] lineAnnotations = annotateOperation.getLineAnnotations();
final List<VcsFileRevision> revisions;
if (hasLocalFile) {
final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(cvsVirtualFile);
revisions = myCvsHistoryProvider.createRevisions(filePath);
// in annotation cvs returns only 8 symbols of username
// try to find usernames in history and use them
adjustAnnotation(revisions, lineAnnotations);
} else {
// imitation
revisions = new ArrayList<>();
final Set<String> usedRevisions = new HashSet<>();
for (Annotation annotation : lineAnnotations) {
if (!usedRevisions.contains(annotation.getRevision())) {
revisions.add(new RevisionPresentation(annotation.getRevision(), annotation.getUserName(), annotation.getDate()));
usedRevisions.add(annotation.getRevision());
}
}
}
return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile, revision, myProject);
}
Aggregations