--- /dev/null
+/*
+ * Copyright 2000-2010 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.actions;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public abstract class DiffRequestPresentableProxy implements DiffRequestPresentable {
+ private DiffRequestPresentable myDelegate;
+ private List<? extends AnAction> myCachedActions;
+ private MyResult myStepResult;
+
+ @Nullable
+ protected abstract DiffRequestPresentable init();
+
+ @Nullable
+ private DiffRequestPresentable initRequest() {
+ if (myDelegate == null) {
+ myDelegate = init();
+ }
+ return myDelegate;
+ }
+
+ public List<? extends AnAction> createActions(ShowDiffAction.DiffExtendUIFactory uiFactory) {
+ if (myCachedActions == null) {
+ myCachedActions = initRequest().createActions(uiFactory);
+ }
+ return myCachedActions;
+ }
+
+ public MyResult step() {
+ final DiffRequestPresentable request = initRequest();
+ if (request == null) {
+ return new MyResult(null, DiffPresentationReturnValue.removeFromList);
+ }
+ myStepResult = request.step();
+ return myStepResult;
+ }
+
+ public boolean haveStuff() {
+ final DiffRequestPresentable request = initRequest();
+ if (request == null) {
+ return false;
+ }
+ return request.haveStuff();
+ }
+}
import com.intellij.openapi.vcs.changes.SimpleContentRevision;
import com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable;
import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
+import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentableProxy;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
@Nullable
public DiffRequestPresentable createDiffRequestPresentable(final Project project) {
- if (myPatchInProgress.isConflictingChange()) {
- final ApplyPatchForBaseRevisionTexts texts = ApplyPatchForBaseRevisionTexts
- .create(project, myPatchInProgress.getCurrentBase(), new FilePathImpl(myPatchInProgress.getCurrentBase()),
- myPatchInProgress.getPatch());
- if ((texts != null) &&
- (ApplyPatchStatus.SUCCESS.equals(texts.getStatus()) || ApplyPatchStatus.ALREADY_APPLIED.equals(texts.getStatus()))) {
- return new MergedDiffRequestPresentable(project, texts,
- myPatchInProgress.getCurrentBase(), myPatchInProgress.getPatch().getAfterVersionId());
+ return new DiffRequestPresentableProxy() {
+ @Override
+ protected DiffRequestPresentable init() {
+ if (myPatchInProgress.isConflictingChange()) {
+ final ApplyPatchForBaseRevisionTexts texts = ApplyPatchForBaseRevisionTexts
+ .create(project, myPatchInProgress.getCurrentBase(), new FilePathImpl(myPatchInProgress.getCurrentBase()),
+ myPatchInProgress.getPatch());
+ if ((texts != null) &&
+ (ApplyPatchStatus.SUCCESS.equals(texts.getStatus()) || ApplyPatchStatus.ALREADY_APPLIED.equals(texts.getStatus()))) {
+ return new MergedDiffRequestPresentable(project, texts,
+ myPatchInProgress.getCurrentBase(), myPatchInProgress.getPatch().getAfterVersionId());
+ }
+ return null;
+ } else {
+ return new ChangeDiffRequestPresentable(project, PatchChange.this);
+ }
}
- return null;
- } else {
- return new ChangeDiffRequestPresentable(project, this);
- }
+ };
}
}
import com.intellij.openapi.vcs.changes.ContentRevision;
import com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable;
import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
+import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentableProxy;
import com.intellij.openapi.vcs.changes.actions.ShowDiffAction;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts;
import com.intellij.openapi.vcs.changes.patch.MergedDiffRequestPresentable;
}
public static void showShelvedChangesDiff(final DataContext dc) {
- Project project = PlatformDataKeys.PROJECT.getData(dc);
+ final Project project = PlatformDataKeys.PROJECT.getData(dc);
ShelvedChangeList[] changeLists = ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY.getData(dc);
if (changeLists == null) {
changeLists = ShelvedChangesViewManager.SHELVED_RECYCLED_CHANGELIST_KEY.getData(dc);
int toSelectIdx = 0;
final ArrayList<DiffRequestPresentable> diffRequestPresentables = new ArrayList<DiffRequestPresentable>();
- ApplyPatchContext context = new ApplyPatchContext(project.getBaseDir(), 0, false, false);
+ final ApplyPatchContext context = new ApplyPatchContext(project.getBaseDir(), 0, false, false);
final PatchesPreloader preloader = new PatchesPreloader();
final List<String> missing = new LinkedList<String>();
final Change change = shelvedChange.getChange(project);
final String beforePath = shelvedChange.getBeforePath();
try {
- VirtualFile f = FilePatch.findPatchTarget(context, beforePath, shelvedChange.getAfterPath(), beforePath == null);
+ final VirtualFile f = FilePatch.findPatchTarget(context, beforePath, shelvedChange.getAfterPath(), beforePath == null);
if ((f == null) || (! f.exists())) {
if (beforePath != null) {
missing.add(beforePath);
continue;
}
- if (isConflictingChange(change)) {
- TextFilePatch patch = preloader.getPatch(shelvedChange);
- if (patch == null) continue;
-
- final FilePath pathBeforeRename = context.getPathBeforeRename(f);
-
- final ApplyPatchForBaseRevisionTexts threeTexts = ApplyPatchForBaseRevisionTexts.create(project, f, pathBeforeRename, patch);
- if ((threeTexts == null) || (threeTexts.getStatus() == null) || (ApplyPatchStatus.FAILURE.equals(threeTexts.getStatus()))) {
- continue;
+ diffRequestPresentables.add(new DiffRequestPresentableProxy() {
+ @Override
+ protected DiffRequestPresentable init() {
+ if (isConflictingChange(change)) {
+ TextFilePatch patch = preloader.getPatch(shelvedChange);
+ if (patch == null) return null;
+
+ final FilePath pathBeforeRename = context.getPathBeforeRename(f);
+
+ final ApplyPatchForBaseRevisionTexts threeTexts = ApplyPatchForBaseRevisionTexts.create(project, f, pathBeforeRename, patch);
+ if ((threeTexts == null) || (threeTexts.getStatus() == null) || (ApplyPatchStatus.FAILURE.equals(threeTexts.getStatus()))) {
+ return null;
+ }
+
+ return new MergedDiffRequestPresentable(project, threeTexts, f, "Shelved Version");
+ }
+ else {
+ return new ChangeDiffRequestPresentable(project, change);
+ }
}
-
- diffRequestPresentables.add(new MergedDiffRequestPresentable(project, threeTexts, f, "Shelved Version"));
- }
- else {
- diffRequestPresentables.add(new ChangeDiffRequestPresentable(project, change));
- }
+ });
}
catch (IOException e) {
continue;
ChangesViewBalloonProblemNotifier.showMe(project, "Show Diff: Cannot find base for: " + StringUtil.join(missing, ",\n"), MessageType.WARNING);
}
- ShowDiffAction.showDiffImpl(project, diffRequestPresentables, toSelectIdx, ShowDiffAction.DiffExtendUIFactory.NONE, true);
+ ShowDiffAction.showDiffImpl(project, diffRequestPresentables, toSelectIdx, ShowDiffAction.DiffExtendUIFactory.NONE, false);
}
private static class PatchesPreloader {