diff --git a/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml b/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml
index ef03e419240c..48a34a79ae3f 100644
--- a/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml
+++ b/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml
@@ -78,7 +78,9 @@
-
+
diff --git a/platform/platform-resources/src/META-INF/VcsExtensions.xml b/platform/platform-resources/src/META-INF/VcsExtensions.xml
index 7b5a8f01920c..769a4b8e56d6 100644
--- a/platform/platform-resources/src/META-INF/VcsExtensions.xml
+++ b/platform/platform-resources/src/META-INF/VcsExtensions.xml
@@ -40,7 +40,7 @@
-
+
diff --git a/platform/platform-resources/src/idea/VcsActions.xml b/platform/platform-resources/src/idea/VcsActions.xml
index ecf6df0f61e5..bbc474171838 100644
--- a/platform/platform-resources/src/idea/VcsActions.xml
+++ b/platform/platform-resources/src/idea/VcsActions.xml
@@ -24,9 +24,10 @@
text="Com_pare with Specified Revision..." popup="true"/>
-
+
+
@@ -375,6 +376,7 @@
+
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowDiffWithLocalAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowDiffWithLocalAction.java
index ae56ad00304e..1faa3958b2ee 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowDiffWithLocalAction.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowDiffWithLocalAction.java
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.vcs.changes.actions;
+import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
@@ -24,6 +25,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.changes.*;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesBrowserUseCase;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -32,12 +34,17 @@ import java.util.List;
import static com.intellij.openapi.vcs.changes.actions.diff.ShowDiffAction.showDiffForChange;
-/**
- * @author yole
- */
public class ShowDiffWithLocalAction extends AnAction implements DumbAware {
+ private final boolean myBeforeWithLocal;
+
public ShowDiffWithLocalAction() {
- ActionUtil.copyFrom(this, "Vcs.ShowDiffWithLocal");
+ this(false);
+ getTemplatePresentation().setIcon(AllIcons.Actions.DiffWithCurrent);
+ }
+
+ public ShowDiffWithLocalAction(boolean beforeWithLocal) {
+ myBeforeWithLocal = beforeWithLocal;
+ ActionUtil.copyFrom(this, beforeWithLocal ? "Vcs.ShowDiffWithLocal.Before" : "Vcs.ShowDiffWithLocal");
}
public void actionPerformed(AnActionEvent e) {
@@ -49,9 +56,9 @@ public class ShowDiffWithLocalAction extends AnAction implements DumbAware {
List changesToLocal = new ArrayList<>();
for (int i = 0; i < selection.getChanges().size(); i++) {
if (i == selection.getIndex()) index = changesToLocal.size();
- ContentRevision afterRevision = selection.getChanges().get(i).getAfterRevision();
- if (afterRevision != null && isValidAfterRevision(afterRevision)) {
- changesToLocal.add(new Change(afterRevision, getCurrentRevision(afterRevision, e)));
+ Change change = getChangeWithLocal(selection.getChanges().get(i));
+ if (change != null) {
+ changesToLocal.add(change);
}
}
@@ -60,29 +67,30 @@ public class ShowDiffWithLocalAction extends AnAction implements DumbAware {
}
}
- @NotNull
- protected ContentRevision getCurrentRevision(@NotNull ContentRevision afterRevision, @NotNull AnActionEvent e) {
- return CurrentContentRevision.create(afterRevision.getFile());
- }
-
public void update(final AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
ChangesSelection selection = e.getData(VcsDataKeys.CHANGES_SELECTION);
boolean isInAir = CommittedChangesBrowserUseCase.IN_AIR.equals(CommittedChangesBrowserUseCase.DATA_KEY.getData(e.getDataContext()));
+ boolean isToolbar = "ChangesBrowser".equals(e.getPlace());
- e.getPresentation().setEnabled(project != null && selection != null && !isInAir && anyHasAfterRevision(selection.getChanges()));
+ e.getPresentation().setEnabled(project != null && !isToolbar && selection != null && !isInAir && canShowDiff(selection.getChanges()));
+ e.getPresentation().setVisible(!isToolbar);
}
- private static boolean isValidAfterRevision(@Nullable final ContentRevision afterRevision) {
- return afterRevision != null && !afterRevision.getFile().isNonLocal() && !afterRevision.getFile().isDirectory();
+ @Nullable
+ private Change getChangeWithLocal(@NotNull Change c) {
+ ContentRevision revision = myBeforeWithLocal ? c.getBeforeRevision() : c.getAfterRevision();
+ if (!isValidRevision(revision)) return null;
+
+ ContentRevision contentRevision = CurrentContentRevision.create(revision.getFile());
+ return new Change(revision, contentRevision);
}
- private static boolean anyHasAfterRevision(@NotNull final List changes) {
- for (Change c : changes) {
- if (isValidAfterRevision(c.getAfterRevision())) {
- return true;
- }
- }
- return false;
+ private boolean canShowDiff(@NotNull List changes) {
+ return ContainerUtil.exists(changes, c -> getChangeWithLocal(c) != null);
+ }
+
+ private static boolean isValidRevision(@Nullable ContentRevision revision) {
+ return revision != null && !revision.getFile().isNonLocal() && !revision.getFile().isDirectory();
}
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/RepositoryChangesBrowser.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/RepositoryChangesBrowser.java
index a595c8ffb516..9c66bba3d2d9 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/RepositoryChangesBrowser.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/RepositoryChangesBrowser.java
@@ -71,7 +71,9 @@ public class RepositoryChangesBrowser extends ChangesBrowser implements DataProv
protected void buildToolBar(final DefaultActionGroup toolBarGroup) {
super.buildToolBar(toolBarGroup);
- toolBarGroup.add(new ShowDiffWithLocalAction());
+ toolBarGroup.add(new ShowDiffWithLocalAction(true));
+ toolBarGroup.add(new ShowDiffWithLocalAction(false));
+
myEditSourceAction = new MyEditSourceAction();
myEditSourceAction.registerCustomShortcutSet(CommonShortcuts.getEditSource(), this);
toolBarGroup.add(myEditSourceAction);
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java
index 881bc0c35a44..a437986e8c60 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java
@@ -408,7 +408,9 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
diffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), null);
result.add(diffAction);
- result.add(ActionManager.getInstance().getAction("Vcs.ShowDiffWithLocal"));
+ if (popup) {
+ result.add(ActionManager.getInstance().getAction("Vcs.ShowDiffWithLocal"));
+ }
final AnAction diffGroup = ActionManager.getInstance().getAction(VCS_HISTORY_ACTIONS_GROUP);
if (diffGroup != null) result.add(diffGroup);
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffWithLocalAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffAfterWithLocalAction.java
similarity index 94%
rename from platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffWithLocalAction.java
rename to platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffAfterWithLocalAction.java
index 29e7c31fb2af..d1307d4ec7cc 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffWithLocalAction.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffAfterWithLocalAction.java
@@ -30,11 +30,11 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
-public class ShowDiffWithLocalAction extends ExtendableAction implements DumbAware {
+public class ShowDiffAfterWithLocalAction extends ExtendableAction implements DumbAware {
private static final ExtensionPointName EP_NAME =
- ExtensionPointName.create("com.intellij.openapi.vcs.history.actions.ShowDiffWithLocalAction.ExtensionProvider");
+ ExtensionPointName.create("com.intellij.openapi.vcs.history.actions.ShowDiffAfterWithLocalAction.ExtensionProvider");
- public ShowDiffWithLocalAction() {
+ public ShowDiffAfterWithLocalAction() {
super(EP_NAME);
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffBeforeWithLocalAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffBeforeWithLocalAction.java
new file mode 100644
index 000000000000..08f4dde1b9a6
--- /dev/null
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/ShowDiffBeforeWithLocalAction.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2000-2017 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.vcs.history.actions;
+
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.AnActionExtensionProvider;
+import com.intellij.openapi.actionSystem.ExtendableAction;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.project.DumbAware;
+import org.jetbrains.annotations.NotNull;
+
+public class ShowDiffBeforeWithLocalAction extends ExtendableAction implements DumbAware {
+ private static final ExtensionPointName EP_NAME =
+ ExtensionPointName.create("com.intellij.openapi.vcs.history.actions.ShowDiffBeforeWithLocalAction.ExtensionProvider");
+
+ public ShowDiffBeforeWithLocalAction() {
+ super(EP_NAME);
+ }
+
+ @Override
+ public void defaultActionPerformed(@NotNull AnActionEvent e) {
+ }
+
+ @Override
+ public void defaultUpdate(@NotNull AnActionEvent e) {
+ e.getPresentation().setEnabledAndVisible(false);
+ }
+}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java
index 00b63eec5489..f1cc469fcb26 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java
@@ -208,7 +208,7 @@ public class VcsSelectionHistoryDialog extends FrameWrapper implements DataProvi
final DefaultActionGroup popupActions = new DefaultActionGroup();
popupActions.add(new MyDiffAction());
- popupActions.add(new MyDiffLocalAction());
+ popupActions.add(new MyDiffAfterWithLocalAction());
popupActions.add(ShowAllAffectedGenericAction.getInstance());
popupActions.add(ActionManager.getInstance().getAction(VcsActions.ACTION_COPY_REVISION_NUMBER));
PopupHandler.installPopupHandler(myList, popupActions, ActionPlaces.UPDATE_POPUP, ActionManager.getInstance());
@@ -496,8 +496,8 @@ public class VcsSelectionHistoryDialog extends FrameWrapper implements DataProvi
}
}
- private class MyDiffLocalAction extends DumbAwareAction {
- public MyDiffLocalAction() {
+ private class MyDiffAfterWithLocalAction extends DumbAwareAction {
+ public MyDiffAfterWithLocalAction() {
ActionUtil.copyFrom(this, "Vcs.ShowDiffWithLocal");
}
diff --git a/platform/vcs-log/impl/src/META-INF/vcs-log.xml b/platform/vcs-log/impl/src/META-INF/vcs-log.xml
index 3a6fcc926c5f..7d8a9ff404cc 100644
--- a/platform/vcs-log/impl/src/META-INF/vcs-log.xml
+++ b/platform/vcs-log/impl/src/META-INF/vcs-log.xml
@@ -37,7 +37,8 @@
-
+
+
@@ -122,6 +123,7 @@
-
@@ -176,6 +177,7 @@
+
diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryUi.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryUi.java
index dade82b4dffa..a30cddb645bf 100644
--- a/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryUi.java
+++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/history/FileHistoryUi.java
@@ -129,7 +129,7 @@ public class FileHistoryUi extends AbstractVcsLogUi {
}
@Nullable
- public FilePath getPath(@NotNull VcsFullCommitDetails details) {
+ public FilePath getAfterPath(@NotNull VcsFullCommitDetails details) {
if (myPath.isDirectory()) return myPath;
List changes = collectRelevantChanges(details);
@@ -143,6 +143,21 @@ public class FileHistoryUi extends AbstractVcsLogUi {
return null;// file was deleted
}
+ @Nullable
+ public FilePath getBeforePath(@NotNull VcsFullCommitDetails details) {
+ if (myPath.isDirectory()) return myPath;
+
+ List changes = collectRelevantChanges(details);
+ for (Change change : changes) {
+ ContentRevision revision = change.getBeforeRevision();
+ if (revision != null) {
+ return revision.getFile();
+ }
+ }
+
+ return null;// file was created
+ }
+
@NotNull
public List collectRelevantChanges(@NotNull VcsFullCommitDetails details) {
Set fileNames = getFileNames(details);
diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/CompareRevisionsFromHistoryActionProvider.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/CompareRevisionsFromHistoryActionProvider.java
index ea2dfc46f6e2..d698ed3ca2fa 100644
--- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/CompareRevisionsFromHistoryActionProvider.java
+++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/CompareRevisionsFromHistoryActionProvider.java
@@ -113,8 +113,8 @@ public class CompareRevisionsFromHistoryActionProvider implements AnActionExtens
// so that it could return a single file path for each revision
VcsFullCommitDetails newestDetail = details.get(0);
VcsFullCommitDetails olderDetail = details.get(1);
- notNull(handler).showDiff(olderDetail.getRoot(), ui.getPath(olderDetail), olderDetail.getId(),
- ui.getPath(newestDetail), newestDetail.getId());
+ notNull(handler).showDiff(olderDetail.getRoot(), ui.getAfterPath(olderDetail), olderDetail.getId(),
+ ui.getAfterPath(newestDetail), newestDetail.getId());
}
else if (details.size() == 1) {
VcsFullCommitDetails detail = notNull(ContainerUtil.getFirstItem(details));
diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffWithLocalFromHistoryActionProvider.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffAfterWithLocalFromHistoryActionProvider.java
similarity index 84%
rename from platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffWithLocalFromHistoryActionProvider.java
rename to platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffAfterWithLocalFromHistoryActionProvider.java
index 6b0501b5b256..dcd3e2f63b70 100644
--- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffWithLocalFromHistoryActionProvider.java
+++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffAfterWithLocalFromHistoryActionProvider.java
@@ -28,19 +28,12 @@ import com.intellij.vcs.log.ui.VcsLogInternalDataKeys;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-public class ShowDiffWithLocalFromHistoryActionProvider extends FileHistorySingleCommitAction implements AnActionExtensionProvider {
+public class ShowDiffAfterWithLocalFromHistoryActionProvider extends FileHistorySingleCommitAction implements AnActionExtensionProvider {
@Override
public boolean isActive(@NotNull AnActionEvent e) {
return e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI) != null;
}
- @Override
- public void update(@NotNull AnActionEvent e) {
- super.update(e);
-
- e.getPresentation().setDescription("Compare selected revision with the local version of the file");
- }
-
@Override
protected boolean isEnabled(@NotNull FileHistoryUi ui, @Nullable VcsFullCommitDetails detail, @NotNull AnActionEvent e) {
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
@@ -59,6 +52,6 @@ public class ShowDiffWithLocalFromHistoryActionProvider extends FileHistorySingl
FilePath path = e.getRequiredData(VcsDataKeys.FILE_PATH);
VcsLogDiffHandler handler = e.getRequiredData(VcsLogInternalDataKeys.LOG_DIFF_HANDLER);
- handler.showDiffWithLocal(detail.getRoot(), ui.getPath(detail), detail.getId(), path);
+ handler.showDiffWithLocal(detail.getRoot(), ui.getAfterPath(detail), detail.getId(), path);
}
}
diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffBeforeWithLocalFromHistoryActionProvider.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffBeforeWithLocalFromHistoryActionProvider.java
new file mode 100644
index 000000000000..6e061bea210b
--- /dev/null
+++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffBeforeWithLocalFromHistoryActionProvider.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2000-2017 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.vcs.log.ui.actions.history;
+
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.AnActionExtensionProvider;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vcs.FilePath;
+import com.intellij.openapi.vcs.VcsDataKeys;
+import com.intellij.openapi.vcs.changes.ChangeListManager;
+import com.intellij.vcs.log.VcsFullCommitDetails;
+import com.intellij.vcs.log.VcsLogDiffHandler;
+import com.intellij.vcs.log.history.FileHistoryUi;
+import com.intellij.vcs.log.ui.VcsLogInternalDataKeys;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class ShowDiffBeforeWithLocalFromHistoryActionProvider extends FileHistorySingleCommitAction implements AnActionExtensionProvider {
+ @Override
+ public boolean isActive(@NotNull AnActionEvent e) {
+ return e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI) != null;
+ }
+
+ @Override
+ protected boolean isEnabled(@NotNull FileHistoryUi ui, @Nullable VcsFullCommitDetails detail, @NotNull AnActionEvent e) {
+ FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
+ VcsLogDiffHandler handler = e.getData(VcsLogInternalDataKeys.LOG_DIFF_HANDLER);
+
+ if (filePath == null || filePath.getVirtualFile() == null || handler == null) {
+ return false;
+ }
+
+ if (detail != null) {
+ return detail.getParents().size() == 1;
+ }
+
+ return true;
+ }
+
+ @Override
+ protected void performAction(@NotNull Project project,
+ @NotNull FileHistoryUi ui,
+ @NotNull VcsFullCommitDetails detail,
+ @NotNull AnActionEvent e) {
+ if (ChangeListManager.getInstance(project).isFreezedWithNotification(null)) return;
+ if (detail.getParents().size() != 1) return;
+
+ FilePath path = e.getRequiredData(VcsDataKeys.FILE_PATH);
+ VcsLogDiffHandler handler = e.getRequiredData(VcsLogInternalDataKeys.LOG_DIFF_HANDLER);
+
+ handler.showDiffWithLocal(detail.getRoot(), ui.getBeforePath(detail), detail.getParents().get(0), path);
+ }
+}