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 28692d3ebea1..f7c6bee418d2 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 @@ -26,7 +26,6 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.PanelWithActionsAndCloseButton; import com.intellij.openapi.ui.Splitter; @@ -44,6 +43,7 @@ import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkRenderer; import com.intellij.openapi.vcs.changes.issueLinks.TableLinkMouseListener; import com.intellij.openapi.vcs.history.actions.AnnotateRevisionAction; import com.intellij.openapi.vcs.history.actions.CreatePatchAction; +import com.intellij.openapi.vcs.history.actions.CompareRevisionsAction; import com.intellij.openapi.vcs.history.actions.GetVersionAction; import com.intellij.openapi.vcs.vfs.VcsFileSystem; import com.intellij.openapi.vcs.vfs.VcsVirtualFile; @@ -345,7 +345,7 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme myDualView.setTreeCellRenderer(new MyTreeCellRenderer(myDualView.getTree().getCellRenderer(), () -> myHistorySession)); myDualView.setCellWrapper(new MyCellWrapper(() -> myHistorySession)); - myDualView.installDoubleClickHandler(new MyDiffAction()); + myDualView.installDoubleClickHandler(new CompareRevisionsAction()); myDualView.getFlatView().getTableViewModel().setSortable(true); RowSorter rowSorter = myDualView.getFlatView().getRowSorter(); @@ -403,7 +403,7 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme result.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE)); } - final MyDiffAction diffAction = new MyDiffAction(); + CompareRevisionsAction diffAction = new CompareRevisionsAction(); diffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), null); result.add(diffAction); @@ -1002,52 +1002,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme } } - private class MyDiffAction extends DumbAwareAction { - public MyDiffAction() { - super(VcsBundle.message("action.name.compare"), VcsBundle.message("action.description.compare"), AllIcons.Actions.Diff); - } - - public void actionPerformed(@NotNull AnActionEvent e) { - VcsFileRevision[] revisions = e.getRequiredData(VcsDataKeys.VCS_FILE_REVISIONS); - FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH); - VcsHistoryProvider provider = e.getRequiredData(VcsDataKeys.HISTORY_PROVIDER); - - DiffFromHistoryHandler customDiffHandler = provider.getHistoryDiffHandler(); - DiffFromHistoryHandler diffHandler = customDiffHandler == null ? new StandardDiffFromHistoryHandler() : customDiffHandler; - - if (revisions.length == 2){ - diffHandler.showDiffForTwo(e.getRequiredData(CommonDataKeys.PROJECT), filePath, revisions[0], revisions[1]); - } - else if (revisions.length == 1) { - VcsFileRevision previousRevision = e.getRequiredData(PREVIOUS_REVISION_FOR_DIFF); - if (revisions[0] != null) { - diffHandler.showDiffForOne(e, e.getRequiredData(CommonDataKeys.PROJECT), filePath, previousRevision, revisions[0]); - } - } - } - - public void update(@NotNull AnActionEvent e) { - e.getPresentation().setEnabled(isEnabled(e)); - } - - public boolean isEnabled(@NotNull AnActionEvent e) { - VcsFileRevision[] revisions = e.getData(VcsDataKeys.VCS_FILE_REVISIONS); - VcsHistorySession historySession = e.getData(VcsDataKeys.HISTORY_SESSION); - FilePath filePath = e.getData(VcsDataKeys.FILE_PATH); - VcsHistoryProvider provider = e.getData(VcsDataKeys.HISTORY_PROVIDER); - if (revisions == null || historySession == null || filePath == null || provider == null) return false; - - if (revisions.length == 1) { - return historySession.isContentAvailable(revisions[0]) && e.getData(PREVIOUS_REVISION_FOR_DIFF) != null; - } - else if (revisions.length == 2) { - return historySession.isContentAvailable(revisions[0]) && - historySession.isContentAvailable(revisions[revisions.length - 1]); - } - return false; - } - } - private class RefreshFileHistoryAction extends RefreshAction implements DumbAware { public RefreshFileHistoryAction() { super(VcsBundle.message("action.name.refresh"), VcsBundle.message("action.description.refresh"), AllIcons.Actions.Refresh); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/CompareRevisionsAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/CompareRevisionsAction.java new file mode 100644 index 000000000000..1d6cd44455d8 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/CompareRevisionsAction.java @@ -0,0 +1,72 @@ +/* + * 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.icons.AllIcons; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.VcsDataKeys; +import com.intellij.openapi.vcs.history.*; +import org.jetbrains.annotations.NotNull; + +public class CompareRevisionsAction extends DumbAwareAction { + public CompareRevisionsAction() { + super(VcsBundle.message("action.name.compare"), VcsBundle.message("action.description.compare"), AllIcons.Actions.Diff); + } + + public void actionPerformed(@NotNull AnActionEvent e) { + VcsFileRevision[] revisions = e.getRequiredData(VcsDataKeys.VCS_FILE_REVISIONS); + FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH); + VcsHistoryProvider provider = e.getRequiredData(VcsDataKeys.HISTORY_PROVIDER); + + DiffFromHistoryHandler customDiffHandler = provider.getHistoryDiffHandler(); + DiffFromHistoryHandler diffHandler = customDiffHandler == null ? new StandardDiffFromHistoryHandler() : customDiffHandler; + + if (revisions.length == 2) { + diffHandler.showDiffForTwo(e.getRequiredData(CommonDataKeys.PROJECT), filePath, revisions[0], revisions[1]); + } + else if (revisions.length == 1) { + VcsFileRevision previousRevision = e.getRequiredData(FileHistoryPanelImpl.PREVIOUS_REVISION_FOR_DIFF); + if (revisions[0] != null) { + diffHandler.showDiffForOne(e, e.getRequiredData(CommonDataKeys.PROJECT), filePath, previousRevision, revisions[0]); + } + } + } + + public void update(@NotNull AnActionEvent e) { + e.getPresentation().setEnabled(isEnabled(e)); + } + + public boolean isEnabled(@NotNull AnActionEvent e) { + VcsFileRevision[] revisions = e.getData(VcsDataKeys.VCS_FILE_REVISIONS); + VcsHistorySession historySession = e.getData(VcsDataKeys.HISTORY_SESSION); + FilePath filePath = e.getData(VcsDataKeys.FILE_PATH); + VcsHistoryProvider provider = e.getData(VcsDataKeys.HISTORY_PROVIDER); + if (revisions == null || historySession == null || filePath == null || provider == null) return false; + + if (revisions.length == 1) { + return historySession.isContentAvailable(revisions[0]) && e.getData(FileHistoryPanelImpl.PREVIOUS_REVISION_FOR_DIFF) != null; + } + else if (revisions.length == 2) { + return historySession.isContentAvailable(revisions[0]) && + historySession.isContentAvailable(revisions[revisions.length - 1]); + } + return false; + } +}