From 86acbf22ed65bf0cea2f3513e843e66892d4eeb0 Mon Sep 17 00:00:00 2001 From: Olesya Smirnova Date: Mon, 14 Feb 2005 11:55:49 +0300 Subject: [PATCH] (no message) --- .../openapi/vcs/annotate/Annotater.java | 81 +++++++++++++++++++ .../vcs/annotate/AnnotationProvider.java | 5 ++ .../com/intellij/cvsSupport2/CvsVcs2.java | 26 +++++- .../annotate/CvsAnnotationProvider.java | 5 ++ .../cvsBrowser/ui/BrowserPanel.java | 17 +++- 5 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 openapi/src/com/intellij/openapi/vcs/annotate/Annotater.java diff --git a/openapi/src/com/intellij/openapi/vcs/annotate/Annotater.java b/openapi/src/com/intellij/openapi/vcs/annotate/Annotater.java new file mode 100644 index 000000000000..a54b8f5e2324 --- /dev/null +++ b/openapi/src/com/intellij/openapi/vcs/annotate/Annotater.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * -Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * -Redistribution in binary form must reproduct the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * + * Neither the name of JetBrains or IntelliJ IDEA + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT + * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT + * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN + * IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ +package com.intellij.openapi.vcs.annotate; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorGutter; +import com.intellij.openapi.editor.TextAnnotationGutterProvider; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.OpenFileDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vfs.VirtualFile; + +public class Annotater { + + private final Project myProject; + private final VirtualFile myVirtualFile; + private final FileAnnotation myFileAnnotation; + + public Annotater(FileAnnotation fileAnnotation, Project project, VirtualFile virtualFile) { + myFileAnnotation = fileAnnotation; + myProject = project; + myVirtualFile = virtualFile; + } + + public void showAnnotation() { + OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(myProject, myVirtualFile); + Editor editor = FileEditorManager.getInstance(myProject).openTextEditor(openFileDescriptor, true); + if (editor == null) { + Messages.showMessageDialog("Cannot open text editor for file " + myVirtualFile.getPresentableUrl(), + "Cannot Open Editor", Messages.getInformationIcon()); + return; + } + + EditorGutter gutterComponent = editor.getGutter(); + gutterComponent.closeAllAnnotations(); + + final LineAnnotationAspect[] aspects = myFileAnnotation.getAspects(); + for (int i = 0; i < aspects.length; i++) { + final LineAnnotationAspect aspect = aspects[i]; + gutterComponent.registerTextAnnotation(new TextAnnotationGutterProvider() { + public String getLineText(int line, Editor editor) { + return aspect.getValue(line); + } + + public void gutterClosed() { + } + }); + + } + } +} diff --git a/openapi/src/com/intellij/openapi/vcs/annotate/AnnotationProvider.java b/openapi/src/com/intellij/openapi/vcs/annotate/AnnotationProvider.java index 13050125414f..d149ca17554f 100644 --- a/openapi/src/com/intellij/openapi/vcs/annotate/AnnotationProvider.java +++ b/openapi/src/com/intellij/openapi/vcs/annotate/AnnotationProvider.java @@ -33,7 +33,12 @@ package com.intellij.openapi.vcs.annotate; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.history.VcsFileRevision; public interface AnnotationProvider { + FileAnnotation annotate(VirtualFile file) throws VcsException; + + FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException; + } diff --git a/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java index e8fcd3c655e6..1135817b3e07 100644 --- a/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java @@ -3,29 +3,38 @@ package com.intellij.cvsSupport2; import com.intellij.cvsSupport2.actions.EditAction; import com.intellij.cvsSupport2.actions.cvsContext.CvsContextAdapter; +import com.intellij.cvsSupport2.annotate.CvsAnnotationProvider; +import com.intellij.cvsSupport2.annotate.CvsFileAnnotation; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.application.CvsStorageComponent; import com.intellij.cvsSupport2.checkinProject.CvsCheckinEnvironment; import com.intellij.cvsSupport2.checkinProject.CvsCheckinFile; import com.intellij.cvsSupport2.config.CvsConfiguration; +import com.intellij.cvsSupport2.connections.CvsEnvironment; +import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor; +import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutorCallback; +import com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler; import com.intellij.cvsSupport2.cvsoperations.common.CvsOperation; +import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation; import com.intellij.cvsSupport2.cvsstatuses.CvsEntriesListener; import com.intellij.cvsSupport2.cvsstatuses.CvsStatusProvider; import com.intellij.cvsSupport2.cvsstatuses.CvsUpToDateRevisionProvider; import com.intellij.cvsSupport2.fileView.CvsFileViewEnvironment; import com.intellij.cvsSupport2.history.CvsHistoryProvider; -import com.intellij.cvsSupport2.annotate.CvsAnnotationProvider; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.annotate.AnnotationProvider; +import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.fileView.FileViewEnvironment; import com.intellij.openapi.vcs.history.VcsHistoryProvider; import com.intellij.openapi.vcs.update.UpdateEnvironment; import com.intellij.openapi.vfs.VirtualFile; +import java.io.File; + /** * This class intended to be an adapter of AbstractVcs and ProjectComponent interfaces for CVS * @@ -247,5 +256,20 @@ public class CvsVcs2 extends AbstractVcs implements ProjectComponent, public AnnotationProvider getAnnotationProvider() { return myCvsAnnotationProvider; } + + public FileAnnotation createAnnotation(File cvsLightweightFile, VirtualFile cvsVirtualFile, + String revision, CvsEnvironment environment) throws VcsException { + final AnnotateOperation annotateOperation = new AnnotateOperation(cvsLightweightFile, revision, environment); + CvsOperationExecutor executor = new CvsOperationExecutor(myProject); + executor.performActionSync(new CommandCvsHandler("Annotate", annotateOperation), + CvsOperationExecutorCallback.EMPTY); + + if (executor.getResult().hasNoErrors()) { + return new CvsFileAnnotation(annotateOperation.getContent(), annotateOperation.getLineAnnotations(), cvsVirtualFile); + } else { + throw executor.getResult().composeError(); + } + + } } diff --git a/plugins/cvs2/source/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java b/plugins/cvs2/source/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java index 9e574146e445..67c562166e3b 100644 --- a/plugins/cvs2/source/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java +++ b/plugins/cvs2/source/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java @@ -34,6 +34,7 @@ package com.intellij.cvsSupport2.annotate; import com.intellij.openapi.vcs.annotate.AnnotationProvider; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.project.Project; import com.intellij.openapi.application.ModalityState; @@ -62,4 +63,8 @@ public class CvsAnnotationProvider implements AnnotationProvider{ throw executor.getFirstError(); } } + + public FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException { + return null; + } } diff --git a/plugins/cvs2/source/com/intellij/cvsSupport2/cvsBrowser/ui/BrowserPanel.java b/plugins/cvs2/source/com/intellij/cvsSupport2/cvsBrowser/ui/BrowserPanel.java index 9dcf6376977e..856ced702b82 100644 --- a/plugins/cvs2/source/com/intellij/cvsSupport2/cvsBrowser/ui/BrowserPanel.java +++ b/plugins/cvs2/source/com/intellij/cvsSupport2/cvsBrowser/ui/BrowserPanel.java @@ -11,12 +11,16 @@ import com.intellij.cvsSupport2.cvsBrowser.CvsElement; import com.intellij.cvsSupport2.cvsBrowser.CvsTree; import com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler; import com.intellij.cvsSupport2.cvshandlers.CvsHandler; -import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotater; +import com.intellij.cvsSupport2.CvsVcs2; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vcs.vfs.VcsVirtualFile; +import com.intellij.openapi.vcs.annotate.Annotater; +import com.intellij.openapi.vcs.annotate.FileAnnotation; +import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.peer.PeerFactory; import com.intellij.ui.PopupHandler; @@ -125,9 +129,14 @@ public class BrowserPanel extends JPanel implements DataProvider { public void actionPerformed(AnActionEvent e) { VcsVirtualFile vcsVirtualFile = (VcsVirtualFile)getCvsVirtualFile(); - new Annotater(getCvsLightFile().getCvsFile(), myProject, - vcsVirtualFile, vcsVirtualFile.getRevision(), - myCvsRootConfiguration).execute(); + try { + final FileAnnotation annotation = CvsVcs2.getInstance(myProject) + .createAnnotation(getCvsLightFile().getCvsFile(), vcsVirtualFile, vcsVirtualFile.getRevision(), myCvsRootConfiguration); + new Annotater(annotation, myProject, vcsVirtualFile).showAnnotation(); + } + catch (VcsException e1) { + AbstractVcsHelper.getInstance(myProject).showError(e1, "CVS Annotate"); + } } }