diff --git a/openapi/src/com/intellij/openapi/vcs/actions/VcsRevisionListCellRenderer.java b/openapi/src/com/intellij/openapi/vcs/actions/VcsRevisionListCellRenderer.java new file mode 100644 index 000000000000..7c3982baf761 --- /dev/null +++ b/openapi/src/com/intellij/openapi/vcs/actions/VcsRevisionListCellRenderer.java @@ -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); + } +} diff --git a/plugins/cvs2/META-INF/plugin.xml b/plugins/cvs2/META-INF/plugin.xml index 9e35baa3e024..8db45024f5c6 100644 --- a/plugins/cvs2/META-INF/plugin.xml +++ b/plugins/cvs2/META-INF/plugin.xml @@ -100,11 +100,9 @@ - - - + + + diff --git a/plugins/cvs2/source/com/intellij/cvsSupport2/CvsDiffProvider.java b/plugins/cvs2/source/com/intellij/cvsSupport2/CvsDiffProvider.java new file mode 100644 index 000000000000..66494bd87aac --- /dev/null +++ b/plugins/cvs2/source/com/intellij/cvsSupport2/CvsDiffProvider.java @@ -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; + } + }; + } +} diff --git a/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java index 1135817b3e07..3c175e3da403 100644 --- a/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs2/source/com/intellij/cvsSupport2/CvsVcs2.java @@ -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; + } } diff --git a/plugins/cvs2/source/com/intellij/cvsSupport2/history/CvsFileContent.java b/plugins/cvs2/source/com/intellij/cvsSupport2/history/CvsFileContent.java new file mode 100644 index 000000000000..d84e17c4831f --- /dev/null +++ b/plugins/cvs2/source/com/intellij/cvsSupport2/history/CvsFileContent.java @@ -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(); + } +} diff --git a/plugins/cvs2/source/com/intellij/cvsSupport2/history/CvsFileRevisionImpl.java b/plugins/cvs2/source/com/intellij/cvsSupport2/history/CvsFileRevisionImpl.java index 0d5c851b8adc..5d46a7547a72 100644 --- a/plugins/cvs2/source/com/intellij/cvsSupport2/history/CvsFileRevisionImpl.java +++ b/plugins/cvs2/source/com/intellij/cvsSupport2/history/CvsFileRevisionImpl.java @@ -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(); - } - } diff --git a/resources/src/idea/ActionManager.xml b/resources/src/idea/ActionManager.xml index 93866019eb03..330139db8666 100644 --- a/resources/src/idea/ActionManager.xml +++ b/resources/src/idea/ActionManager.xml @@ -150,7 +150,7 @@ - + diff --git a/source/com/intellij/openapi/vcs/actions/AbstractShowDiffAction.java b/source/com/intellij/openapi/vcs/actions/AbstractShowDiffAction.java index eadeb45d639e..82fa66c19eb8 100644 --- a/source/com/intellij/openapi/vcs/actions/AbstractShowDiffAction.java +++ b/source/com/intellij/openapi/vcs/actions/AbstractShowDiffAction.java @@ -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); diff --git a/source/com/intellij/openapi/vcs/actions/CompareWithSelectedRevisionAction.java b/source/com/intellij/openapi/vcs/actions/CompareWithSelectedRevisionAction.java index afbf2350233f..717e26a0ceb9 100644 --- a/source/com/intellij/openapi/vcs/actions/CompareWithSelectedRevisionAction.java +++ b/source/com/intellij/openapi/vcs/actions/CompareWithSelectedRevisionAction.java @@ -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 actions = new ArrayList(); try { final VcsHistorySession session = vcsHistoryProvider.createSessionFor(new FilePathImpl(file)); final List revisions = session.getRevisionList(); for (Iterator 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); + } + }