diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java index 772fc2514639..00e00f1a4458 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/DiffShelvedChangesActionProvider.java @@ -18,7 +18,6 @@ package com.intellij.openapi.vcs.changes.shelf; import com.intellij.diff.DiffContentFactory; import com.intellij.diff.DiffDialogHints; import com.intellij.diff.DiffManager; -import com.intellij.diff.actions.impl.GoToChangePopupBuilder; import com.intellij.diff.chains.DiffRequestChain; import com.intellij.diff.chains.DiffRequestProducer; import com.intellij.diff.chains.DiffRequestProducerException; @@ -28,7 +27,10 @@ import com.intellij.diff.requests.SimpleDiffRequest; import com.intellij.diff.requests.UnknownFileTypeDiffRequest; import com.intellij.diff.tools.util.SoftHardCacheMap; import com.intellij.diff.util.DiffUtil; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.AnActionExtensionProvider; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.diff.impl.patch.*; import com.intellij.openapi.diff.impl.patch.apply.ApplyFilePatchBase; import com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier; @@ -38,7 +40,6 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.UserDataHolder; -import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FileStatus; @@ -48,12 +49,11 @@ import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vcs.changes.CommitContext; import com.intellij.openapi.vcs.changes.FilePathsHelper; -import com.intellij.openapi.vcs.changes.actions.diff.ChangeGoToChangePopupAction; import com.intellij.openapi.vcs.changes.patch.AppliedTextPatch; import com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts; import com.intellij.openapi.vcs.changes.patch.tool.PatchDiffRequest; +import com.intellij.openapi.vcs.changes.ui.ChangeDiffRequestChain; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; import com.intellij.util.containers.ContainerUtil; import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.CalledInBackground; @@ -138,7 +138,7 @@ public class DiffShelvedChangesActionProvider implements AnActionExtensionProvid } } - MyDiffRequestChain chain = new MyDiffRequestChain(diffRequestProducers, index); + DiffRequestChain chain = new ChangeDiffRequestChain(diffRequestProducers, index); DiffManager.getInstance().showDiff(project, chain, DiffDialogHints.FRAME); } @@ -366,52 +366,7 @@ public class DiffShelvedChangesActionProvider implements AnActionExtensionProvid } } - private static class MyDiffRequestChain extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain { - @NotNull private final List myProducers; - private int myIndex = 0; - - public MyDiffRequestChain(@NotNull List producers, int index) { - myProducers = producers; - myIndex = index; - } - - @NotNull - @Override - public List getRequests() { - return myProducers; - } - - @Override - public int getIndex() { - return myIndex; - } - - @Override - public void setIndex(int index) { - assert index >= 0 && index < myProducers.size(); - myIndex = index; - } - - @NotNull - @Override - public AnAction createGoToChangeAction(@NotNull Consumer onSelected) { - return new ChangeGoToChangePopupAction.Fake(this, myIndex, onSelected) { - @NotNull - @Override - protected FilePath getFilePath(int index) { - return myProducers.get(index).getFilePath(); - } - - @NotNull - @Override - protected FileStatus getFileStatus(int index) { - return myProducers.get(index).getFileStatus(); - } - }; - } - } - - private static abstract class MyDiffRequestProducer implements DiffRequestProducer { + private static abstract class MyDiffRequestProducer implements ChangeDiffRequestChain.Producer { @Nullable private final ShelvedChange myTextChange; @Nullable private final ShelvedBinaryFile myBinaryChange; @NotNull private final FilePath myFilePath; @@ -445,7 +400,8 @@ public class DiffShelvedChangesActionProvider implements AnActionExtensionProvid } @NotNull - protected FileStatus getFileStatus() { + @Override + public FileStatus getFileStatus() { if (myTextChange != null) { return myTextChange.getFileStatus(); } @@ -456,6 +412,7 @@ public class DiffShelvedChangesActionProvider implements AnActionExtensionProvid } @NotNull + @Override public FilePath getFilePath() { return myFilePath; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeDiffRequestChain.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeDiffRequestChain.java new file mode 100644 index 000000000000..3a9e82e2616a --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeDiffRequestChain.java @@ -0,0 +1,83 @@ +/* + * 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.changes.ui; + +import com.intellij.diff.actions.impl.GoToChangePopupBuilder; +import com.intellij.diff.chains.DiffRequestChain; +import com.intellij.diff.chains.DiffRequestProducer; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.FileStatus; +import com.intellij.openapi.vcs.changes.actions.diff.ChangeGoToChangePopupAction; +import com.intellij.util.Consumer; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class ChangeDiffRequestChain extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain { + @NotNull private final List myProducers; + private int myIndex; + + public ChangeDiffRequestChain(@NotNull List producers, int index) { + myProducers = producers; + myIndex = index; + } + + @Override + @NotNull + public List getRequests() { + //noinspection unchecked + return (List)myProducers; + } + + @Override + public int getIndex() { + return myIndex; + } + + @Override + public void setIndex(int index) { + assert index >= 0 && index < myProducers.size(); + myIndex = index; + } + + @NotNull + @Override + public AnAction createGoToChangeAction(@NotNull Consumer onSelected) { + return new ChangeGoToChangePopupAction.Fake(this, myIndex, onSelected) { + @NotNull + @Override + protected FilePath getFilePath(int index) { + return myProducers.get(index).getFilePath(); + } + + @NotNull + @Override + protected FileStatus getFileStatus(int index) { + return myProducers.get(index).getFileStatus(); + } + }; + } + + public interface Producer extends DiffRequestProducer { + @NotNull + FilePath getFilePath(); + + @NotNull + FileStatus getFileStatus(); + } +}