mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
Implementing DiffProvider for CVS
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.intellij.openapi.vcs.actions;
|
||||
|
||||
import com.intellij.ui.ColoredListCellRenderer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.DateFormat;
|
||||
|
||||
public class VcsRevisionListCellRenderer extends ColoredListCellRenderer {
|
||||
private static final DateFormat DATE_FORMAT = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT);
|
||||
|
||||
protected void customizeCellRenderer(
|
||||
JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean selected,
|
||||
boolean hasFocus
|
||||
) {
|
||||
final VcsFileRevision revision = ((VcsFileRevision)value);
|
||||
append(revision.getRevisionNumber().asString() + " " + DATE_FORMAT.format(revision.getRevisionDate()) + " " + revision.getAuthor(),
|
||||
SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
@@ -100,11 +100,9 @@
|
||||
<reference id="Cvs.Ignore"/>
|
||||
|
||||
<separator/>
|
||||
<action id="Cvs.Diff" class="com.intellij.cvsSupport2.actions.DiffAction" text="Compare with The _Same Version" description="Show local changes to the file"/>
|
||||
<action id="Cvs.CompareWithLastVersion" class="com.intellij.cvsSupport2.actions.DiffWithCvsVersionAction" text="Compare with _Latest Repository Version"
|
||||
description="Compare local copy with the latest version from repository"/>
|
||||
<action id="Cvs.DiffWithSelectedVersion" class="com.intellij.cvsSupport2.actions.DiffWithSelectedVersionAction"
|
||||
text="Compare with Se_lected Version..." description="Compare local copy with some selected version"/>
|
||||
<reference id="Compare.SameVersion"/>
|
||||
<reference id="Compare.LastVersion"/>
|
||||
<reference id="Compare.Selected"/>
|
||||
|
||||
<reference id="Vcs.ShowTabbedFileHistory"/>
|
||||
<reference id="Vcs.ShowHistoryForBlock"/>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.intellij.cvsSupport2;
|
||||
|
||||
import com.intellij.cvsSupport2.application.CvsEntriesManager;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsContent.GetFileContentOperation;
|
||||
import com.intellij.cvsSupport2.cvsoperations.dateOrRevision.SimpleRevision;
|
||||
import com.intellij.cvsSupport2.history.ComparableVcsRevisionOnOperation;
|
||||
import com.intellij.cvsSupport2.history.CvsFileContent;
|
||||
import com.intellij.cvsSupport2.history.CvsRevisionNumber;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.diff.DiffProvider;
|
||||
import com.intellij.openapi.vcs.history.VcsFileContent;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CvsDiffProvider implements DiffProvider{
|
||||
private final Project myProject;
|
||||
|
||||
public CvsDiffProvider(final Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public VcsRevisionNumber getCurrentRevision(VirtualFile file) {
|
||||
return new CvsRevisionNumber(CvsEntriesManager.getInstance().getEntryFor(file).getRevision());
|
||||
}
|
||||
|
||||
public VcsRevisionNumber getLastRevision(VirtualFile virtualFile) {
|
||||
return new CvsRevisionNumber("HEAD");
|
||||
}
|
||||
|
||||
public VcsFileContent createFileContent(final VcsRevisionNumber revisionNumber, VirtualFile selectedFile) {
|
||||
final GetFileContentOperation operation = new GetFileContentOperation(new File(CvsUtil.getModuleName(new File(selectedFile.getPath()))),
|
||||
CvsEntriesManager.getInstance()
|
||||
.getCvsConnectionSettingsFor(selectedFile.getParent()),
|
||||
new SimpleRevision(revisionNumber.asString()));
|
||||
return new CvsFileContent(new ComparableVcsRevisionOnOperation(operation, myProject)) {
|
||||
public VcsRevisionNumber getRevisionNumber() {
|
||||
return revisionNumber;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ 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.diff.DiffProvider;
|
||||
import com.intellij.openapi.vcs.annotate.AnnotationProvider;
|
||||
import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
|
||||
@@ -60,6 +61,7 @@ public class CvsVcs2 extends AbstractVcs implements ProjectComponent,
|
||||
private final CvsStatusEnvironment myCvsStatusEnvironment;
|
||||
private final CvsUpToDateRevisionProvider myUpToDateRevisionProvider;
|
||||
private final CvsAnnotationProvider myCvsAnnotationProvider;
|
||||
private final CvsDiffProvider myDiffProvider;
|
||||
|
||||
public CvsVcs2(Project project, CvsStorageComponent cvsStorageComponent) {
|
||||
super(project);
|
||||
@@ -74,6 +76,7 @@ public class CvsVcs2 extends AbstractVcs implements ProjectComponent,
|
||||
myStorageComponent = cvsStorageComponent;
|
||||
myFileViewEnvironment = new CvsFileViewEnvironment(getProject());
|
||||
myCvsAnnotationProvider = new CvsAnnotationProvider(myProject);
|
||||
myDiffProvider = new CvsDiffProvider(myProject);
|
||||
}
|
||||
|
||||
/* ======================================= ProjectComponent */
|
||||
@@ -271,5 +274,9 @@ public class CvsVcs2 extends AbstractVcs implements ProjectComponent,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DiffProvider getDiffProvider() {
|
||||
return myDiffProvider;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.intellij.cvsSupport2.history;
|
||||
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vcs.history.VcsFileContent;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
|
||||
public abstract class CvsFileContent implements VcsFileContent{
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.history.CvsFileContent");
|
||||
protected final ComparableVcsRevisionOnOperation myComparableCvsRevisionOnOperation;
|
||||
|
||||
protected CvsFileContent(final ComparableVcsRevisionOnOperation comparableCvsRevisionOnOperation) {
|
||||
myComparableCvsRevisionOnOperation = comparableCvsRevisionOnOperation;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return myComparableCvsRevisionOnOperation.isDeleted();
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return myComparableCvsRevisionOnOperation.isLoaded();
|
||||
}
|
||||
|
||||
public byte[] getContent() {
|
||||
LOG.assertTrue(isLoaded());
|
||||
return myComparableCvsRevisionOnOperation.getContent();
|
||||
}
|
||||
|
||||
public abstract VcsRevisionNumber getRevisionNumber();
|
||||
|
||||
public void loadContent() throws VcsException {
|
||||
myComparableCvsRevisionOnOperation.loadContent();
|
||||
if (!isLoaded()) {
|
||||
throw new VcsException("Cannot load revision " + getRevisionNumber());
|
||||
}
|
||||
if (fileNotFound()) {
|
||||
throw new VcsException("Cannot find revision " + getRevisionNumber());
|
||||
}
|
||||
|
||||
if (isDeleted()) {
|
||||
throw new VcsException("Rrevision " + getRevisionNumber() + " was deleted from repository");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean fileNotFound() {
|
||||
return myComparableCvsRevisionOnOperation.fileNotFound();
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ package com.intellij.cvsSupport2.history;
|
||||
import com.intellij.cvsSupport2.connections.CvsEnvironment;
|
||||
import com.intellij.cvsSupport2.cvsoperations.cvsContent.GetFileContentOperation;
|
||||
import com.intellij.cvsSupport2.cvsoperations.dateOrRevision.SimpleRevision;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.util.ListWithSelection;
|
||||
import org.netbeans.lib.cvsclient.command.log.LogInformation;
|
||||
@@ -18,37 +16,26 @@ import java.util.*;
|
||||
/**
|
||||
* author: lesya
|
||||
*/
|
||||
public class CvsFileRevisionImpl implements CvsFileRevision {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.history.CvsFileRevisionImpl");
|
||||
|
||||
private final File myCvsLightweightFile;
|
||||
public class CvsFileRevisionImpl extends CvsFileContent implements CvsFileRevision {
|
||||
|
||||
private Revision myCvsRevision;
|
||||
private LogInformation myLogInformation;
|
||||
private Collection myTags;
|
||||
|
||||
private final CvsEnvironment myCvsEnvironment;
|
||||
|
||||
private final ComparableVcsRevisionOnOperation myComparableCvsRevisionOnOperation;
|
||||
|
||||
public CvsFileRevisionImpl(Revision cvsRevision, File file, LogInformation logInfo,
|
||||
CvsEnvironment cvsRoot, Project project) {
|
||||
myCvsLightweightFile = file;
|
||||
myCvsEnvironment = cvsRoot;
|
||||
super(new ComparableVcsRevisionOnOperation(createGetFileContentOperation(cvsRevision,
|
||||
file,
|
||||
cvsRoot), project));
|
||||
myCvsRevision = cvsRevision;
|
||||
myLogInformation = logInfo;
|
||||
|
||||
myComparableCvsRevisionOnOperation = new ComparableVcsRevisionOnOperation(createGetFileContentOperation(), project);
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return myComparableCvsRevisionOnOperation.isDeleted();
|
||||
}
|
||||
|
||||
private GetFileContentOperation createGetFileContentOperation() {
|
||||
String revisionNumber = myCvsRevision != null ? myCvsRevision.getNumber() : null;
|
||||
return new GetFileContentOperation(myCvsLightweightFile, myCvsEnvironment, new SimpleRevision(revisionNumber));
|
||||
private static GetFileContentOperation createGetFileContentOperation(final Revision cvsRevision,
|
||||
final File cvsLightweightFile,
|
||||
final CvsEnvironment cvsEnvironment) {
|
||||
String revisionNumber = cvsRevision != null ? cvsRevision.getNumber() : null;
|
||||
return new GetFileContentOperation(cvsLightweightFile, cvsEnvironment, new SimpleRevision(revisionNumber));
|
||||
}
|
||||
|
||||
private CvsRevisionNumber getNumber() {
|
||||
@@ -87,15 +74,6 @@ public class CvsFileRevisionImpl implements CvsFileRevision {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return myComparableCvsRevisionOnOperation.isLoaded();
|
||||
}
|
||||
|
||||
public byte[] getContent() {
|
||||
LOG.assertTrue(isLoaded());
|
||||
return myComparableCvsRevisionOnOperation.getContent();
|
||||
}
|
||||
|
||||
public VcsRevisionNumber getRevisionNumber() {
|
||||
if (getNumber() == null) {
|
||||
return VcsRevisionNumber.NULL;
|
||||
@@ -111,26 +89,8 @@ public class CvsFileRevisionImpl implements CvsFileRevision {
|
||||
return myCvsRevision.getMessage();
|
||||
}
|
||||
|
||||
public void loadContent() throws VcsException {
|
||||
myComparableCvsRevisionOnOperation.loadContent();
|
||||
if (!isLoaded()) {
|
||||
throw new VcsException("Cannot load revision " + getRevisionNumber());
|
||||
}
|
||||
if (fileNotFound()) {
|
||||
throw new VcsException("Cannot find revision " + getRevisionNumber());
|
||||
}
|
||||
|
||||
if (isDeleted()) {
|
||||
throw new VcsException("Rrevision " + getRevisionNumber() + " was deleted from repository");
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getRevisionNumber().asString();
|
||||
}
|
||||
|
||||
public boolean fileNotFound() {
|
||||
return myComparableCvsRevisionOnOperation.fileNotFound();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@
|
||||
<action id="Annotate" class="com.intellij.openapi.vcs.actions.AnnotateToggleAction" text="A_nnotate" description="Show information about last modification date and author for each line"/>
|
||||
<action id="Compare.SameVersion" class="com.intellij.openapi.vcs.actions.CompareWithTheSameVersionAction" text="Compare with The Same Repository Version"/>
|
||||
<action id="Compare.LastVersion" class="com.intellij.openapi.vcs.actions.CompareWithLastVersion" text="Compare with The Last Repository Version"/>
|
||||
<group id="Compare.Selected" class="com.intellij.openapi.vcs.actions.CompareWithSelectedRevisionAction" text="Compare with..." popup="true"/>
|
||||
<action id="Compare.Selected" class="com.intellij.openapi.vcs.actions.CompareWithSelectedRevisionAction" text="Compare with..." popup="true"/>
|
||||
|
||||
<group id="NewGroup" text="New" popup="true">
|
||||
<action id="NewClass" text="Class" class="com.intellij.ide.actions.CreateClassAction"/>
|
||||
|
||||
@@ -75,6 +75,15 @@ public abstract class AbstractShowDiffAction extends AbstractVcsAction{
|
||||
|
||||
VcsRevisionNumber revisionNumber = getRevisionNumber(diffProvider, selectedFile);
|
||||
|
||||
showDiff(diffProvider, revisionNumber, selectedFile, project);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected static void showDiff(final DiffProvider diffProvider,
|
||||
final VcsRevisionNumber revisionNumber,
|
||||
final VirtualFile selectedFile,
|
||||
final Project project) {
|
||||
try {
|
||||
final VcsFileContent fileRevision = diffProvider.createFileContent(revisionNumber, selectedFile);
|
||||
fileRevision.loadContent();
|
||||
@@ -85,9 +94,8 @@ public abstract class AbstractShowDiffAction extends AbstractVcsAction{
|
||||
final DocumentContent content2 = new DocumentContent(project, FileDocumentManager.getInstance().getDocument(selectedFile));
|
||||
|
||||
final VcsRevisionNumber currentRevision = diffProvider.getCurrentRevision(selectedFile);
|
||||
final VcsRevisionNumber lastRevision = diffProvider.getLastRevision(selectedFile);
|
||||
|
||||
if (lastRevision.compareTo(currentRevision) > 0) {
|
||||
if (revisionNumber.compareTo(currentRevision) > 0) {
|
||||
request.setContents(content2, content1);
|
||||
request.setContentTitles("Local", revisionNumber.asString());
|
||||
} else {
|
||||
@@ -103,8 +111,6 @@ public abstract class AbstractShowDiffAction extends AbstractVcsAction{
|
||||
catch (IOException e) {
|
||||
AbstractVcsHelper.getInstance(project).showError(new VcsException(e), "Diff");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected abstract VcsRevisionNumber getRevisionNumber(DiffProvider diffProvider, VirtualFile file);
|
||||
|
||||
@@ -1,69 +1,106 @@
|
||||
package com.intellij.openapi.vcs.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.FilePathImpl;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.diff.DiffProvider;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsHistoryProvider;
|
||||
import com.intellij.openapi.vcs.history.VcsHistorySession;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.peer.PeerFactory;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ex.WindowManagerEx;
|
||||
import com.intellij.ui.ListPopup;
|
||||
import com.intellij.ui.ListSpeedSearch;
|
||||
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.ArrayList;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.DateFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class CompareWithSelectedRevisionAction extends ActionGroup{
|
||||
private static final DateFormat DATE_FORMAT = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT);
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
final VcsContext vcsContext = createVcsContext(e);
|
||||
AbstractShowDiffAction.updateDiffAction(e.getPresentation(), vcsContext);
|
||||
public class CompareWithSelectedRevisionAction extends AbstractVcsAction{
|
||||
public void update(VcsContext e, Presentation presentation) {
|
||||
AbstractShowDiffAction.updateDiffAction(presentation, e);
|
||||
}
|
||||
|
||||
private VcsContext createVcsContext(final AnActionEvent e) {
|
||||
return PeerFactory.getInstance().getVcsContextFactory().createOn(e);
|
||||
}
|
||||
protected void actionPerformed(VcsContext vcsContext) {
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
|
||||
public AnAction[] getChildren(AnActionEvent e) {
|
||||
final VcsContext vcsContext = createVcsContext(e);
|
||||
final VirtualFile file = vcsContext.getSelectedFiles()[0];
|
||||
final Project project = vcsContext.getProject();
|
||||
final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
|
||||
final VcsHistoryProvider vcsHistoryProvider = vcs.getVcsHistoryProvider();
|
||||
final ArrayList<AnAction> actions = new ArrayList<AnAction>();
|
||||
|
||||
try {
|
||||
final VcsHistorySession session = vcsHistoryProvider.createSessionFor(new FilePathImpl(file));
|
||||
final List<VcsFileRevision> revisions = session.getRevisionList();
|
||||
for (Iterator<VcsFileRevision> iterator = revisions.iterator(); iterator.hasNext();) {
|
||||
final VcsFileRevision vcsFileRevision = iterator.next();
|
||||
actions.add(new AbstractShowDiffAction() {
|
||||
protected VcsRevisionNumber getRevisionNumber(DiffProvider diffProvider, VirtualFile file) {
|
||||
return vcsFileRevision.getRevisionNumber();
|
||||
}
|
||||
|
||||
protected void update(VcsContext vcsContext, Presentation presentation) {
|
||||
presentation.setText(vcsFileRevision.getRevisionNumber().asString() +" " + DATE_FORMAT.format(vcsFileRevision.getRevisionDate()) + " " + vcsFileRevision.getAuthor());
|
||||
super.update(vcsContext, presentation);
|
||||
}
|
||||
});
|
||||
model.addElement(iterator.next());
|
||||
}
|
||||
|
||||
}
|
||||
catch (VcsException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return actions.toArray(new AnAction[actions.size()]);
|
||||
|
||||
final JList list = new JList(model);
|
||||
list.setCellRenderer(new VcsRevisionListCellRenderer());
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
int index = list.getSelectedIndex();
|
||||
if (index == -1 || index >= list.getModel().getSize()){
|
||||
return;
|
||||
}
|
||||
VcsFileRevision revision = (VcsFileRevision)list.getSelectedValue();
|
||||
AbstractShowDiffAction.showDiff(vcs.getDiffProvider(), revision.getRevisionNumber(),
|
||||
file, project);
|
||||
}
|
||||
};
|
||||
|
||||
if (list.getModel().getSize() == 0) {
|
||||
list.clearSelection();
|
||||
}
|
||||
new ListSpeedSearch(list);
|
||||
|
||||
Window window = null;
|
||||
|
||||
Component focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent(project);
|
||||
if(focusedComponent!=null){
|
||||
if(focusedComponent instanceof Window){
|
||||
window=(Window)focusedComponent;
|
||||
}else{
|
||||
window=SwingUtilities.getWindowAncestor(focusedComponent);
|
||||
}
|
||||
}
|
||||
if (window == null) {
|
||||
window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
|
||||
}
|
||||
|
||||
Rectangle r;
|
||||
if (window != null) {
|
||||
r = window.getBounds();
|
||||
}
|
||||
else {
|
||||
r = WindowManagerEx.getInstanceEx().getScreenBounds();
|
||||
}
|
||||
|
||||
ListPopup popup = new ListPopup("File Revisions",list, runnable, project);
|
||||
|
||||
if (model.getSize() > 0) {
|
||||
Dimension listPreferredSize = list.getPreferredSize();
|
||||
list.setVisibleRowCount(0);
|
||||
Dimension viewPreferredSize = new Dimension(listPreferredSize.width, Math.min(listPreferredSize.height, r.height - 20));
|
||||
((JViewport)list.getParent()).setPreferredSize(viewPreferredSize);
|
||||
}
|
||||
|
||||
popup.getWindow().pack();
|
||||
Dimension popupSize=popup.getSize();
|
||||
int x = r.x + r.width/2 - popupSize.width/2;
|
||||
int y = r.y + r.height/2 - popupSize.height/2;
|
||||
|
||||
popup.show(x,y);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user