From 970bfa3a2832d518f66f6d321f4505477c88630b Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 26 Sep 2016 19:23:18 +0300 Subject: [PATCH] diff: remove unused code --- .../src/idea/VcsActions.xml | 12 +- .../com/intellij/openapi/vcs/VcsDataKeys.java | 2 - .../vcs/changes/ChangeRequestChain.java | 47 --- .../vcs/changes/actions/DiffChainContext.java | 35 --- .../changes/actions/DiffExtendUIFactory.java | 42 --- .../actions/DiffPresentationReturnValue.java | 22 -- .../actions/DiffRequestPresentable.java | 78 ----- .../changes/actions/ChangeDiffRequest.java | 277 ----------------- .../actions/ChangeDiffRequestPresentable.java | 292 ------------------ .../actions/ChangeForDiffConvertor.java | 88 ------ .../ConflictedDiffRequestPresentable.java | 110 ------- .../actions/DiffRequestPresentableProxy.java | 70 ----- .../MultipleDiffRequestPresentable.java | 117 ------- .../actions/ShowChangeAbstractAction.java | 84 ----- .../changes/actions/ShowNextChangeAction.java | 42 --- .../changes/actions/ShowPrevChangeAction.java | 42 --- .../actions/ShowSelectedChangeAction.java | 161 ---------- .../actions/migrate/MigrateToNewDiffUtil.java | 153 +-------- .../patch/MergedDiffRequestPresentable.java | 147 --------- 19 files changed, 8 insertions(+), 1813 deletions(-) delete mode 100644 platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeRequestChain.java delete mode 100644 platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffChainContext.java delete mode 100644 platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffExtendUIFactory.java delete mode 100644 platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffPresentationReturnValue.java delete mode 100644 platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentable.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequest.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeForDiffConvertor.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentableProxy.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/MultipleDiffRequestPresentable.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowChangeAbstractAction.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowNextChangeAction.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowPrevChangeAction.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowSelectedChangeAction.java delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java diff --git a/platform/platform-resources/src/idea/VcsActions.xml b/platform/platform-resources/src/idea/VcsActions.xml index cc55a94f7f75..84bf48b48570 100644 --- a/platform/platform-resources/src/idea/VcsActions.xml +++ b/platform/platform-resources/src/idea/VcsActions.xml @@ -226,12 +226,12 @@ - - - + + + diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java index 6572323fe708..c7b943d0a89c 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java @@ -20,7 +20,6 @@ import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ChangeList; -import com.intellij.openapi.vcs.changes.ChangeRequestChain; import com.intellij.openapi.vcs.changes.ChangesSelection; import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vcs.history.VcsHistoryProvider; @@ -63,7 +62,6 @@ public interface VcsDataKeys { DataKey SELECTED_CHANGES = DataKey.create("ChangeListView.SelectedChange"); DataKey HAVE_SELECTED_CHANGES = DataKey.create("ChangeListView.HaveSelectedChanges"); DataKey CHANGE_LEAD_SELECTION = DataKey.create("ChangeListView.ChangeLeadSelection"); - DataKey DIFF_REQUEST_CHAIN = DataKey.create("diffRequestChain"); DataKey UPDATE_VIEW_SELECTED_PATH = DataKey.create("AbstractCommonUpdateAction.UpdateViewSelectedPath"); DataKey>> UPDATE_VIEW_FILES_ITERABLE = DataKey.create("AbstractCommonUpdateAction.UpdatedFilesIterable"); DataKey LABEL_BEFORE = DataKey.create("LABEL_BEFORE"); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeRequestChain.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeRequestChain.java deleted file mode 100644 index 6e8e95a7f9ce..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeRequestChain.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2000-2009 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; - -import com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public interface ChangeRequestChain { - boolean canMoveForward(); - - boolean canMoveBack(); - - @Nullable - DiffRequest moveForward(); - - @Nullable - DiffRequest moveBack(); - - @NotNull - List getAllRequests(); - - @Nullable - DiffRequest moveTo(DiffRequestPresentable request); - - /** - * Returns the diff request which is currently shown in the diff dialog. - */ - @Nullable - DiffRequestPresentable getCurrentRequest(); -} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffChainContext.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffChainContext.java deleted file mode 100644 index 9caf3c7dd984..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffChainContext.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 java.util.LinkedList; -import java.util.List; - -public class DiffChainContext { - private final List mySkippedBinaryExtentions; - - public DiffChainContext() { - mySkippedBinaryExtentions = new LinkedList<>(); - } - - public void add(final String extention) { - mySkippedBinaryExtentions.add(extention); - } - - public boolean contains(final String extention) { - return mySkippedBinaryExtentions.contains(extention); - } -} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffExtendUIFactory.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffExtendUIFactory.java deleted file mode 100644 index 91ac8b7be744..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffExtendUIFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2012 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 com.intellij.openapi.vcs.changes.Change; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.Collections; -import java.util.List; - -@Deprecated -public interface DiffExtendUIFactory { - DiffExtendUIFactory NONE = new DiffExtendUIFactory() { - public List createActions(Change change) { - return Collections.emptyList(); - } - - @Nullable - public JComponent createBottomComponent() { - return null; - } - }; - List createActions(Change change); - - @Nullable - JComponent createBottomComponent(); -} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffPresentationReturnValue.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffPresentationReturnValue.java deleted file mode 100644 index 8cd4ead05e67..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffPresentationReturnValue.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2000-2009 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; - -public enum DiffPresentationReturnValue { - removeFromList, - useRequest, - quit -} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentable.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentable.java deleted file mode 100644 index b17c9ad5cc3e..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentable.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2000-2009 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 com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.VcsException; - -import java.util.ArrayList; -import java.util.List; - -public interface DiffRequestPresentable { - MyResult step(DiffChainContext context); - - void haveStuff() throws VcsException; - List createActions(final DiffExtendUIFactory uiFactory); - String getPathPresentation(); - - class MyResult { - private final List myErrors; - private final DiffRequest myRequest; - private final DiffPresentationReturnValue myReturnValue; - - public MyResult(DiffRequest request, DiffPresentationReturnValue returnValue) { - myRequest = request; - myReturnValue = returnValue; - myErrors = new ArrayList<>(); - } - - public MyResult(DiffRequest request, DiffPresentationReturnValue returnValue, final String error) { - myRequest = request; - myReturnValue = returnValue; - myErrors = new ArrayList<>(); - if (! StringUtil.isEmptyOrSpaces(error)) { - myErrors.add(error); - } - } - - public void addError(final String e) { - myErrors.add(e); - } - - public List getErrors() { - return myErrors; - } - - public DiffRequest getRequest() { - return myRequest; - } - - public DiffPresentationReturnValue getReturnValue() { - return myReturnValue; - } - - public boolean hasErrors() { - return ! myErrors.isEmpty(); - } - - public String getAsOneError() { - if (myErrors.isEmpty()) return null; - return StringUtil.join(myErrors, "\n"); - } - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequest.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequest.java deleted file mode 100644 index 0e344df39549..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequest.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright 2000-2009 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.ActionManager; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.diff.DiffTool; -import com.intellij.openapi.diff.DiffToolbar; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.NullableFactory; -import com.intellij.openapi.vcs.VcsDataKeys; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.ChangeRequestChain; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; - -/** - * @author yole - */ -public class ChangeDiffRequest implements ChangeRequestChain { - @NotNull private final List mySteps; - private final boolean myShowFrame; - private int myIndex; - - private final DiffExtendUIFactory myActionsFactory; - - private final AnAction myPrevChangeAction; - private final AnAction myNextChangeAction; - private final Project myProject; - private final DiffChainContext myContext; - private final AnAction mySelectChangeAction; - - public ChangeDiffRequest(final Project project, @NotNull List steps, final DiffExtendUIFactory actionsFactory, - final boolean showFrame) { - myProject = project; - mySteps = steps; - myShowFrame = showFrame; - myContext = new DiffChainContext(); - - myIndex = 0; - myActionsFactory = actionsFactory; - - myPrevChangeAction = ActionManager.getInstance().getAction("Diff.PrevChange"); - myNextChangeAction = ActionManager.getInstance().getAction("Diff.NextChange"); - mySelectChangeAction = ActionManager.getInstance().getAction("Diff.SelectedChange"); - } - - @NotNull - @Override - public List getAllRequests() { - return mySteps; - } - - private void onEveryMove(final DiffRequest simpleRequest, final boolean showFrame) { - simpleRequest.passForDataContext(VcsDataKeys.DIFF_REQUEST_CHAIN, this); - if (showFrame) { - simpleRequest.addHint(DiffTool.HINT_SHOW_FRAME); - } - else { - simpleRequest.addHint(DiffTool.HINT_SHOW_MODAL_DIALOG); - } - if (mySteps.size() > 1) { - simpleRequest.addHint(DiffTool.HINT_ALLOW_NO_DIFFERENCES); - } - } - - public void quickCheckHaveStuff() throws VcsException { - if (mySteps.isEmpty()) { - throw new VcsException("Nothing selected to show diff"); - } - if (mySteps.size() == 1) { - mySteps.get(0).haveStuff(); - } - } - - @Nullable - public DiffRequest init(final int idx) { - if (idx < 0 || idx > (mySteps.size() - 1)) return null; - myIndex = idx - 1; - final DiffRequest result = moveForward(); - if (result == null && idx > 0) { - myIndex = -1; - return moveForward(); - } - return result; - } - - public boolean canMoveForward() { - return myIndex < (mySteps.size() - 1); - } - - public boolean canMoveBack() { - return myIndex > 0; - } - - @Nullable - public DiffRequest moveForward() { - return moveWithErrorReport(new MoveDirection() { - public boolean canMove() { - return canMoveForward(); - } - - public int direction() { - return 1; - } - }); - } - - @Nullable - @Override - public DiffRequest moveTo(DiffRequestPresentable presentable) { - int index = findRequest(presentable); - if (index == -1) { - return null; - } - - final List errors = new ArrayList<>(); - DiffRequestPresentable.MyResult result = moveImpl(presentable, errors); - showErrors(errors); - if (result == null) { - return null; - } - if (DiffPresentationReturnValue.removeFromList.equals(result.getReturnValue())) { - return null; - } - myIndex = index; - return result.getRequest(); - } - - @Nullable - @Override - public DiffRequestPresentable getCurrentRequest() { - if (myIndex < 0 || myIndex >= mySteps.size()) { - return null; - } - return mySteps.get(myIndex); - } - - private int findRequest(DiffRequestPresentable presentable) { - for (int i = 0; i < mySteps.size(); i++) { - DiffRequestPresentable step = mySteps.get(i); - if (step.equals(presentable)) { - return i; - } - } - return -1; - } - - @Nullable - private DiffRequest moveWithErrorReport(final MoveDirection moveDirection) { - final List errors = new ArrayList<>(); - final DiffRequest diffRequest = moveInc(moveDirection, errors); - showErrors(errors); - return diffRequest; - } - - @Nullable - private DiffRequestPresentable.MyResult moveImpl(DiffRequestPresentable requestPresentable, final List errors) { - final DiffRequestPresentable.MyResult result = requestPresentable.step(myContext); - final DiffPresentationReturnValue returnValue = result.getReturnValue(); - if (DiffPresentationReturnValue.quit.equals(returnValue)) { - errors.addAll(result.getErrors()); - return null; - } - - if (DiffPresentationReturnValue.removeFromList.equals(returnValue)) { - mySteps.remove(requestPresentable); - errors.addAll(result.getErrors()); - return result; - } - - final DiffRequest request = result.getRequest(); - takeStuffFromFactory(request, requestPresentable.createActions(myActionsFactory)); - onEveryMove(request, myShowFrame); - return result; - } - - @Nullable - private DiffRequest moveInc(final MoveDirection moveDirection, final List errors) { - while (moveDirection.canMove()) { - final int nextIdx = myIndex + moveDirection.direction(); - final DiffRequestPresentable diffRequestPresentable = mySteps.get(nextIdx); - - DiffRequestPresentable.MyResult result = moveImpl(diffRequestPresentable, errors); - if (result == null) { - return null; - } - if (DiffPresentationReturnValue.removeFromList.equals(result.getReturnValue())) { - if (moveDirection.direction() < 0) { - // our position moves to head - myIndex += moveDirection.direction(); - } - continue; - } - - myIndex = nextIdx; - return result.getRequest(); - } - return null; - } - - private void showErrors(final List errors) { - if (errors.isEmpty()) return; - final StringBuilder sb = new StringBuilder("Following problems have occurred:\n\n"); - for (String error : errors) { - sb.append(error).append('\n'); - } - Messages.showErrorDialog(myProject, sb.toString(), "Show Diff"); - } - - private interface MoveDirection { - boolean canMove(); - int direction(); - } - - @Nullable - public DiffRequest moveBack() { - return moveWithErrorReport(new MoveDirection() { - public boolean canMove() { - return canMoveBack(); - } - - public int direction() { - return -1; - } - }); - } - - private void takeStuffFromFactory(final DiffRequest request, final List actions) { - if (mySteps.size() > 1 || (myActionsFactory != null)) { - request.setToolbarAddons(new DiffRequest.ToolbarAddons() { - public void customize(final DiffToolbar toolbar) { - if (mySteps.size() > 1) { - toolbar.addSeparator(); - } - toolbar.addAction(myPrevChangeAction); - toolbar.addAction(myNextChangeAction); - toolbar.addAction(mySelectChangeAction); - - if (myActionsFactory != null) { - toolbar.addSeparator(); - for (AnAction action : actions) { - toolbar.addAction(action); - } - } - } - }); - } - - if (myActionsFactory != null) { - request.setBottomComponentFactory(new NullableFactory() { - public JComponent create() { - return myActionsFactory.createBottomComponent(); - } - }); - } - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java deleted file mode 100644 index 24b6044127e6..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright 2000-2013 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.CommonBundle; -import com.intellij.diff.FileAwareSimpleContent; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.diff.DiffContent; -import com.intellij.openapi.diff.FileContent; -import com.intellij.openapi.diff.SimpleContent; -import com.intellij.openapi.diff.SimpleDiffRequest; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypes; -import com.intellij.openapi.fileTypes.ex.FileTypeChooser; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.io.FileUtilRt; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.*; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ArrayUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class ChangeDiffRequestPresentable implements DiffRequestPresentable { - private final Project myProject; - private final Change myChange; - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable"); - // I don't like that much - private boolean myIgnoreDirectoryFlag; - - public ChangeDiffRequestPresentable(final Project project, final Change change) { - myChange = change; - myProject = project; - } - - public Change getChange() { - return myChange; - } - - public void setIgnoreDirectoryFlag(boolean ignoreDirectoryFlag) { - myIgnoreDirectoryFlag = ignoreDirectoryFlag; - } - - public MyResult step(DiffChainContext context) { - final SimpleDiffRequest request = new SimpleDiffRequest(myProject, null); - final List errSb = new ArrayList<>(); - if (! canShowChange(context, errSb)) { - return new MyResult(request, DiffPresentationReturnValue.removeFromList, StringUtil.join(errSb, "\n")); - } - if (! loadCurrentContents(request, myChange)) return new MyResult(request, DiffPresentationReturnValue.quit); - return new MyResult(request, DiffPresentationReturnValue.useRequest); - } - - @Override - public String getPathPresentation() { - return ChangesUtil.getFilePath(myChange).getPath(); - } - - @Override - public void haveStuff() throws VcsException { - final List errSb = new ArrayList<>(); - final boolean canShow = checkContentsAvailable(myChange.getBeforeRevision(), myChange.getAfterRevision(), errSb); - if (! canShow) { - throw new VcsException(StringUtil.join(errSb, "\n")); - } - } - - public List createActions(DiffExtendUIFactory uiFactory) { - return uiFactory.createActions(myChange); - } - - private boolean loadCurrentContents(final SimpleDiffRequest request, final Change change) { - final ContentRevision bRev = change.getBeforeRevision(); - final ContentRevision aRev = change.getAfterRevision(); - - String beforePath = bRev != null ? bRev.getFile().getPath() : null; - String afterPath = aRev != null ? aRev.getFile().getPath() : null; - String title; - if (beforePath != null && afterPath != null && !beforePath.equals(afterPath)) { - beforePath = FileUtil.toSystemDependentName(beforePath); - afterPath = FileUtil.toSystemDependentName(afterPath); - title = beforePath + " -> " + afterPath; - } - else if (beforePath != null) { - beforePath = FileUtil.toSystemDependentName(beforePath); - title = beforePath; - } - else if (afterPath != null) { - afterPath = FileUtil.toSystemDependentName(afterPath); - title = afterPath; - } - else { - title = VcsBundle.message("diff.unknown.path.title"); - } - request.setWindowTitle(title); - - boolean result = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { - public void run() { - final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator(); - if (pi != null) { - pi.setIndeterminate(true); - } - request.setContents(createContent(bRev), createContent(aRev)); - } - }, VcsBundle.message("progress.loading.diff.revisions"), true, myProject); - if (! result) return false; - - String beforeRevisionTitle = (bRev != null) ? bRev.getRevisionNumber().asString() : ""; - String afterRevisionTitle = (aRev != null) ? aRev.getRevisionNumber().asString() : ""; - if ((beforeRevisionTitle == null) || (beforeRevisionTitle.length() == 0)) { - beforeRevisionTitle = "Base version"; - } - if ((afterRevisionTitle == null) || (afterRevisionTitle.length() == 0)) { - afterRevisionTitle = "Your version"; - } - request.setContentTitles(beforeRevisionTitle, afterRevisionTitle); - return true; - } - - @NotNull - private DiffContent createContent(final ContentRevision revision) { - ProgressManager.checkCanceled(); - if (revision == null) return SimpleContent.createEmpty(); - if (revision instanceof CurrentContentRevision) { - final CurrentContentRevision current = (CurrentContentRevision)revision; - final VirtualFile vFile = current.getVirtualFile(); - return vFile != null ? new FileContent(myProject, vFile) : new SimpleContent(""); - } - FilePath filePath = revision.getFile(); - if (revision instanceof BinaryContentRevision) { - final String name = filePath.getName(); - try { - return FileContent.createFromTempFile(myProject, name, name, ((BinaryContentRevision)revision).getBinaryContent()); - } - catch (IOException e) { - LOG.info(e); - try { - return FileContent.createFromTempFile(myProject, name, name, ArrayUtil.EMPTY_BYTE_ARRAY); - } - catch (IOException e1) { - LOG.info(e1); - return null; - } - } - catch (VcsException e) { - LOG.info(e); - try { - return FileContent.createFromTempFile(myProject, name, name, ArrayUtil.EMPTY_BYTE_ARRAY); - } - catch (IOException e1) { - LOG.info(e1); - return null; - } - } - } - - String revisionContent; - try { - revisionContent = revision.getContent(); - } - catch(VcsException ex) { - LOG.info(ex); - // TODO: correct exception handling - revisionContent = null; - } - SimpleContent content = revisionContent == null - ? new SimpleContent("") - : new FileAwareSimpleContent(myProject, filePath, revisionContent, filePath.getFileType()); - VirtualFile vFile = filePath.getVirtualFile(); - if (vFile != null) { - content.setCharset(vFile.getCharset()); - content.setBOM(vFile.getBOM()); - } - content.setReadOnly(true); - return content; - } - - private boolean canShowChange(DiffChainContext context, List errSb) { - final ContentRevision bRev = myChange.getBeforeRevision(); - final ContentRevision aRev = myChange.getAfterRevision(); - - if (myIgnoreDirectoryFlag) { - if (! checkContentsAvailable(bRev, aRev, errSb)) return false; - return true; - } - - boolean isOk = checkContentRevision(bRev, context, errSb); - isOk &= checkContentRevision(aRev, context, errSb); - - return isOk; - } - - private boolean checkContentRevision(ContentRevision rev, final DiffChainContext context, final List errSb) { - if (rev == null) return true; - if (rev.getFile().isDirectory()) return false; - if (! hasContents(rev, errSb)) { - return false; - } - final FileType type = rev.getFile().getFileType(); - if (! type.isBinary()) return true; - if (FileTypes.UNKNOWN.equals(type)) { - final boolean associatedToText = checkAssociate(myProject, rev.getFile().getName(), context); - } - return true; - } - - private static boolean hasContents(@Nullable final ContentRevision rev, final List errSb) { - if (rev == null) return false; - try { - if (rev instanceof BinaryContentRevision) { - return ((BinaryContentRevision) rev).getBinaryContent() != null; - } else { - return rev.getContent() != null; - } - } - catch (VcsException e) { - LOG.info(e); - errSb.add(e.getMessage()); - return false; - } - } - - private static boolean checkContentsAvailable(@Nullable final ContentRevision bRev, @Nullable final ContentRevision aRev, final List errSb) { - if (hasContents(bRev, errSb)) return true; - if (hasContents(aRev, errSb)) return true; - errSb.add("Can't load revisions content:"); - if (bRev != null) errSb.add("Can't load content of " + bRev.getFile().getPresentableUrl() + " at " + bRev.getRevisionNumber().asString()); - if (aRev != null) errSb.add("Can't load content of " + aRev.getFile().getPresentableUrl() + " at " + aRev.getRevisionNumber().asString()); - if (aRev == null && bRev == null) errSb.add("Both revisions are empty"); - return false; - } - - public static boolean checkAssociate(final Project project, String fileName, DiffChainContext context) { - final String pattern = FileUtilRt.getExtension(fileName).toLowerCase(); - if (context.contains(pattern)) return false; - int rc = Messages.showOkCancelDialog(project, - VcsBundle.message("diff.unknown.file.type.prompt", fileName), - VcsBundle.message("diff.unknown.file.type.title"), - VcsBundle.message("diff.unknown.file.type.associate"), - CommonBundle.getCancelButtonText(), - Messages.getQuestionIcon()); - if (rc == Messages.OK) { - FileType fileType = FileTypeChooser.associateFileType(fileName); - return fileType != null && !fileType.isBinary(); - } else { - context.add(pattern); - } - return false; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ChangeDiffRequestPresentable that = (ChangeDiffRequestPresentable)o; - - if (myChange != null ? !myChange.equals(that.myChange) : that.myChange != null) return false; - - return true; - } - - @Override - public int hashCode() { - return myChange != null ? myChange.hashCode() : 0; - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeForDiffConvertor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeForDiffConvertor.java deleted file mode 100644 index 118b66978740..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeForDiffConvertor.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2000-2012 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.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangesUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.containers.Convertor; - -/** - * Created with IntelliJ IDEA. - * User: Irina.Chernushina - * Date: 2/14/12 - * Time: 3:07 PM - */ -public class ChangeForDiffConvertor implements Convertor { - private final Project myProject; - private final boolean myRecursive; - - public ChangeForDiffConvertor(Project project, final boolean recursive) { - myProject = project; - myRecursive = recursive; - } - - @Override - public DiffRequestPresentable convert(Change o) { - return convert(o, false); - } - - public DiffRequestPresentable convert(final Change ch, final boolean forceText) { - if (ch.hasOtherLayers() && myRecursive) { - return new MultipleDiffRequestPresentable(myProject, ch); - } - if (ChangesUtil.isTextConflictingChange(ch)) { - final AbstractVcs vcs = ChangesUtil.getVcsForChange(ch, myProject); - if (vcs == null || vcs.getMergeProvider() == null) return null; - final FilePath path = ChangesUtil.getFilePath(ch); - VirtualFile vf = path.getVirtualFile(); - if (vf == null) { - vf = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath()); - } - if (vf == null) return null; - - return new ConflictedDiffRequestPresentable(myProject, vf, ch); - } else { - if (forceText) { - if (ch.getBeforeRevision() != null && ch.getAfterRevision() != null) { - try { - if (StringUtil.isEmptyOrSpaces(ch.getBeforeRevision().getContent()) && - StringUtil.isEmptyOrSpaces(ch.getAfterRevision().getContent())) { - return null; - } - if (StringUtil.equals(ch.getBeforeRevision().getContent(), ch.getAfterRevision().getContent())) { - return null; - } - } - catch (VcsException e) { - // - } - } - } - final ChangeDiffRequestPresentable presentable = new ChangeDiffRequestPresentable(myProject, ch); - if (forceText) { - presentable.setIgnoreDirectoryFlag(true); - } - return presentable; - } - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java deleted file mode 100644 index 02cd56ed85a4..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2000-2012 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 com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.diff.DiffRequestFactory; -import com.intellij.openapi.diff.MergeRequest; -import com.intellij.openapi.diff.SimpleDiffRequest; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangesUtil; -import com.intellij.openapi.vcs.history.VcsRevisionNumber; -import com.intellij.openapi.vcs.merge.MergeData; -import com.intellij.openapi.vfs.CharsetToolkit; -import com.intellij.openapi.vfs.VirtualFile; - -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.List; - -/** - * Created with IntelliJ IDEA. - * User: Irina.Chernushina - * Date: 2/14/12 - * Time: 4:09 PM - */ -public class ConflictedDiffRequestPresentable implements DiffRequestPresentable { - private final static Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.actions.ConflictedDiffRequestPresentable"); - private final Project myProject; - private final VirtualFile myFile; - private final Change myChange; - - public ConflictedDiffRequestPresentable(final Project project, VirtualFile file, final Change change) { - myProject = project; - myFile = file; - myChange = change; - } - - @Override - public MyResult step(DiffChainContext context) { - if (myChange.getAfterRevision() == null) return createErrorResult(); - FileType type = myChange.getVirtualFile() != null ? myChange.getVirtualFile().getFileType() : null; - if (myFile.getFileType().isBinary()) { - final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, myFile.getName(), context); - if (! nowItIsText) { - return createErrorResult(); - } - } - final AbstractVcs vcs = ChangesUtil.getVcsForChange(myChange, myProject); - if (vcs == null || vcs.getMergeProvider() == null) { - return createErrorResult(); - } - try { - final MergeData mergeData = vcs.getMergeProvider().loadRevisions(myFile); - final Charset charset = myFile.getCharset(); - final MergeRequest request = DiffRequestFactory.getInstance() - .create3WayDiffRequest(CharsetToolkit.bytesToString(mergeData.CURRENT, charset), - CharsetToolkit.bytesToString(mergeData.LAST, charset), - CharsetToolkit.bytesToString(mergeData.ORIGINAL, charset), - type, myProject, null, null); - request.setWindowTitle(FileUtil.toSystemDependentName(myFile.getPresentableUrl())); - // todo titles? - VcsRevisionNumber lastRevisionNumber = mergeData.LAST_REVISION_NUMBER; - request.setVersionTitles(new String[]{myChange.getAfterRevision().getRevisionNumber().asString(), - "Base Version", lastRevisionNumber != null ? lastRevisionNumber.asString() : ""}); - return new MyResult(request, DiffPresentationReturnValue.useRequest); - } - catch (VcsException e) { - LOG.info(e); - return createErrorResult(); - } - } - - private MyResult createErrorResult() { - final SimpleDiffRequest request = new SimpleDiffRequest(myProject, null); - return new MyResult(request, DiffPresentationReturnValue.removeFromList); - } - - @Override - public void haveStuff() throws VcsException { - } - - @Override - public List createActions(DiffExtendUIFactory uiFactory) { - return Collections.emptyList(); - } - - @Override - public String getPathPresentation() { - return myFile.getPath(); - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentableProxy.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentableProxy.java deleted file mode 100644 index 5a53273465fb..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DiffRequestPresentableProxy.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 com.intellij.openapi.vcs.VcsException; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public abstract class DiffRequestPresentableProxy implements DiffRequestPresentable { - private DiffRequestPresentable myDelegate; - private List myCachedActions; - private MyResult myStepResult; - - @NotNull - public abstract DiffRequestPresentable init() throws VcsException; - - @NotNull - private DiffRequestPresentable initRequest() throws VcsException { - if (myDelegate == null) { - myDelegate = init(); - } - return myDelegate; - } - - public List createActions(DiffExtendUIFactory uiFactory) { - if (myCachedActions == null) { - try { - myCachedActions = initRequest().createActions(uiFactory); - } - catch (VcsException e) { - //should not occur - return Collections.emptyList(); - } - } - return myCachedActions; - } - - public MyResult step(DiffChainContext context) { - final DiffRequestPresentable request; - try { - request = initRequest(); - myStepResult = request.step(context); - } - catch (VcsException e) { - myStepResult = new MyResult(null, DiffPresentationReturnValue.quit, e.getMessage()); - } - return myStepResult; - } - - public void haveStuff() throws VcsException { - final DiffRequestPresentable request = initRequest(); - request.haveStuff(); - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/MultipleDiffRequestPresentable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/MultipleDiffRequestPresentable.java deleted file mode 100644 index cdad87ddfbee..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/MultipleDiffRequestPresentable.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2000-2014 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 com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.diff.SimpleDiffRequest; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangesUtil; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * Created with IntelliJ IDEA. - * User: Irina.Chernushina - * Date: 2/14/12 - * Time: 3:48 PM - */ -public class MultipleDiffRequestPresentable implements DiffRequestPresentable { - private final Project myProject; - private final Change myChange; - - public MultipleDiffRequestPresentable(Project project, Change change) { - myProject = project; - myChange = change; - } - - @Override - public MyResult step(DiffChainContext context) { - final ChangeForDiffConvertor convertor = new ChangeForDiffConvertor(myProject, false); - final List> list = new ArrayList<>(); - final DiffRequestPresentable requestPresentable = convertor.convert(myChange, false); - if (requestPresentable != null) { - list.add(Pair.create("", requestPresentable)); - } - final Map layers = myChange.getOtherLayers(); - for (Map.Entry entry : layers.entrySet()) { - final String key = entry.getKey(); - final Change value = entry.getValue(); - final DiffRequestPresentable additional = convertor.convert(value, true); - if (additional != null) { - list.add(Pair.create(key, additional)); - } - } - - if (list.isEmpty()) return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.removeFromList); - - DiffRequest request = null; - final StringBuilder err = new StringBuilder(); - for (Pair pair : list) { - final MyResult step = pair.getSecond().step(context); - if (step == null) continue; - final DiffPresentationReturnValue returnValue = step.getReturnValue(); - if (DiffPresentationReturnValue.quit.equals(returnValue)) { - final String error = step.getAsOneError(); - if (StringUtil.isEmptyOrSpaces(error)) { - return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.quit); - } else { - return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.quit, error); - } - } else if (! DiffPresentationReturnValue.removeFromList.equals(returnValue) && ! step.hasErrors()) { - // use contents - if (request == null) { - request = step.getRequest(); - if (! StringUtil.isEmptyOrSpaces(pair.getFirst())) { - request.setWindowTitle(pair.getFirst() + " " + request.getWindowTitle()); - } - } else { - request.addOtherLayer(pair.getFirst(), step.getRequest()); - } - } else { - final String error = step.getAsOneError(); - if (! StringUtil.isEmptyOrSpaces(error)) { - err.append(error); - } - } - } - if (request == null || err.length() > 0) { - return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.removeFromList, err.toString()); - } - return new MyResult(request, DiffPresentationReturnValue.useRequest, err.toString()); - } - - @Override - public void haveStuff() throws VcsException { - } - - @Override - public List createActions(DiffExtendUIFactory uiFactory) { - return Collections.emptyList(); - } - - @Override - public String getPathPresentation() { - return ChangesUtil.getFilePath(myChange).getPath(); - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowChangeAbstractAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowChangeAbstractAction.java deleted file mode 100644 index e197535cf0a9..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowChangeAbstractAction.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2000-2012 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.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.diff.DiffManager; -import com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.diff.DiffViewer; -import com.intellij.openapi.project.DumbAwareAction; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.VcsDataKeys; -import com.intellij.openapi.vcs.changes.ChangeRequestChain; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.awt.*; - -/** - * @author Kirill Likhodedov - */ -abstract class ShowChangeAbstractAction extends DumbAwareAction { - - ShowChangeAbstractAction() { - setEnabledInModalContext(true); - } - - public void update(AnActionEvent e) { - final ChangeRequestChain chain = e.getData(VcsDataKeys.DIFF_REQUEST_CHAIN); - e.getPresentation().setEnabled(chain != null && isEnabled(chain)); - } - - protected abstract boolean isEnabled(@NotNull ChangeRequestChain chain); - - public void actionPerformed(AnActionEvent e) { - final Project project = e.getData(CommonDataKeys.PROJECT); - final ChangeRequestChain chain = e.getData(VcsDataKeys.DIFF_REQUEST_CHAIN); - if (project == null || chain == null || !isEnabled(chain)) { - return; - } - - DiffViewer diffViewer = e.getData(PlatformDataKeys.COMPOSITE_DIFF_VIEWER); - if (diffViewer == null) { - diffViewer = e.getData(PlatformDataKeys.DIFF_VIEWER); - } - if (diffViewer == null) { - return; - } - - actionPerformed(e, project, chain, diffViewer); - } - - protected void openRequest(@NotNull DiffViewer diffViewer, @Nullable DiffRequest request) { - if (request != null) { - if (diffViewer.acceptsType(request.getType())) { - diffViewer.setDiffRequest(request); - } - else { - final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); - if (window != null) { - window.setVisible(false); - } - DiffManager.getInstance().getDiffTool().show(request); - } - } - } - - protected abstract void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain, - @NotNull DiffViewer diffViewer); -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowNextChangeAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowNextChangeAction.java deleted file mode 100644 index f73cdc20b50a..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowNextChangeAction.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2009 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.AnActionEvent; -import com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.diff.DiffViewer; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.changes.ChangeRequestChain; -import org.jetbrains.annotations.NotNull; - -/** - * @author yole -*/ -public class ShowNextChangeAction extends ShowChangeAbstractAction { - - @Override - protected boolean isEnabled(@NotNull ChangeRequestChain chain) { - return chain.canMoveForward(); - } - - @Override - protected void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain, - @NotNull DiffViewer diffViewer) { - DiffRequest request = chain.moveForward(); - openRequest(diffViewer, request); - } - -} \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowPrevChangeAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowPrevChangeAction.java deleted file mode 100644 index e2ef1f44003e..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowPrevChangeAction.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2009 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.AnActionEvent; -import com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.diff.DiffViewer; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.changes.ChangeRequestChain; -import org.jetbrains.annotations.NotNull; - -/** - * @author yole -*/ -public class ShowPrevChangeAction extends ShowChangeAbstractAction { - - @Override - protected boolean isEnabled(@NotNull ChangeRequestChain chain) { - return chain.canMoveBack(); - } - - @Override - protected void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain, - @NotNull DiffViewer diffViewer) { - DiffRequest request = chain.moveBack(); - openRequest(diffViewer, request); - } - -} \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowSelectedChangeAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowSelectedChangeAction.java deleted file mode 100644 index 66bb8e9fed2d..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ShowSelectedChangeAction.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2000-2012 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.AnActionEvent; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.diff.DiffRequest; -import com.intellij.openapi.diff.DiffViewer; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.JBPopup; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangeRequestChain; -import com.intellij.openapi.vcs.changes.ui.ChangesBrowser; -import com.intellij.ui.awt.RelativePoint; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.tree.TreeSelectionModel; -import java.awt.event.InputEvent; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Kirill Likhodedov - */ -public class ShowSelectedChangeAction extends ShowChangeAbstractAction { - - private static final Logger LOG = Logger.getInstance(ShowSelectedChangeAction.class); - - private JBPopup myPopup; - - @Override - protected boolean isEnabled(@NotNull ChangeRequestChain chain) { - return getChangesFromRequests(chain.getAllRequests()).size() > 1; - } - - @Override - protected void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain, - @NotNull DiffViewer diffViewer) { - List requests = chain.getAllRequests(); - List changes = getChangesFromRequests(requests); - - ChangesBrowser cb = new MyChangesBrowser(project, changes, requests, chain, diffViewer); - - myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent()) - .setResizable(true) - .setModalContext(false) - .setFocusable(true) - .setRequestFocus(true) - .setCancelOnWindowDeactivation(true) - .setCancelOnOtherWindowOpen(true) - .setMovable(true) - .setCancelKeyEnabled(true) - .setCancelOnClickOutside(true) - .createPopup(); - - InputEvent event = e.getInputEvent(); - if (event instanceof MouseEvent) { - myPopup.show(new RelativePoint((MouseEvent)event)); - } - else { - myPopup.showInBestPositionFor(e.getDataContext()); - } - } - - @NotNull - private static List getChangesFromRequests(@NotNull List requests) { - List changes = new ArrayList<>(); - for (DiffRequestPresentable step : requests) { - Change change = getChange(step); - if (change != null) { - changes.add(change); - } - } - return changes; - } - - @Nullable - private static Change getChange(@NotNull DiffRequestPresentable presentable) { - if (presentable instanceof DiffRequestPresentableProxy) { - try { - presentable = ((DiffRequestPresentableProxy)presentable).init(); - } - catch (VcsException e) { - LOG.info(e); - return null; - } - } - if (presentable instanceof ChangeDiffRequestPresentable) { - return ((ChangeDiffRequestPresentable)presentable).getChange(); - } - return null; - } - - private class MyChangesBrowser extends ChangesBrowser implements Runnable { - private final List myRequests; - private final ChangeRequestChain myChain; - private final DiffViewer myDiffViewer; - - public MyChangesBrowser(@NotNull Project project, @NotNull List changes, @NotNull List requests, - @NotNull ChangeRequestChain chain, @NotNull DiffViewer diffViewer) { - super(project, null, changes, null, false, false, null, MyUseCase.LOCAL_CHANGES, null); - myRequests = requests; - myChain = chain; - myDiffViewer = diffViewer; - - setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - setChangesToDisplay(changes); - } - - @Override - protected void buildToolBar(DefaultActionGroup toolBarGroup) { - // remove diff action - } - - @NotNull - @Override - protected Runnable getDoubleClickHandler() { - return this; - } - - @Override - public void run() { - Change change = getSelectedChanges().get(0); - DiffRequestPresentable selectedStep = findSelectedStep(change); - if (selectedStep != null) { - DiffRequest newRequest = myChain.moveTo(selectedStep); - openRequest(myDiffViewer, newRequest); - } - myPopup.cancel(); - } - - @Nullable - private DiffRequestPresentable findSelectedStep(@Nullable Change change) { - for (DiffRequestPresentable step : myRequests) { - Change c = getChange(step); - if (c != null && c.equals(change)) { - return step; - } - } - return null; - } - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/migrate/MigrateToNewDiffUtil.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/migrate/MigrateToNewDiffUtil.java index 1e215cdf710f..13c632da9294 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/migrate/MigrateToNewDiffUtil.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/migrate/MigrateToNewDiffUtil.java @@ -1,6 +1,5 @@ package com.intellij.openapi.vcs.changes.actions.migrate; -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; @@ -14,7 +13,6 @@ import com.intellij.diff.requests.ErrorDiffRequest; import com.intellij.diff.requests.SimpleDiffRequest; import com.intellij.diff.util.DiffUserDataKeysEx; import com.intellij.diff.util.LineCol; -import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.DiffNavigationContext; import com.intellij.openapi.diff.DiffTool; @@ -22,23 +20,9 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.UserDataHolder; -import com.intellij.openapi.util.UserDataHolderBase; -import com.intellij.openapi.vcs.VcsDataKeys; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangeRequestChain; -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.diff.ChangeGoToChangePopupAction; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.Navigatable; -import com.intellij.util.Consumer; -import com.intellij.util.Function; -import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,14 +40,8 @@ public class MigrateToNewDiffUtil { @NotNull public static DiffRequestChain convertRequestChain(@NotNull com.intellij.openapi.diff.DiffRequest oldRequest) { - ChangeRequestChain oldChain = (ChangeRequestChain)oldRequest.getGenericData().get(VcsDataKeys.DIFF_REQUEST_CHAIN.getName()); - if (oldChain == null || oldChain.getAllRequests().size() < 2) { - DiffRequest request = convertRequest(oldRequest); - return new SimpleDiffRequestChain(request); - } - else { - return new ChangeRequestChainWrapper(oldChain); - } + DiffRequest request = convertRequest(oldRequest); + return new SimpleDiffRequestChain(request); } @NotNull @@ -128,133 +106,6 @@ public class MigrateToNewDiffUtil { } } - private static class ChangeRequestChainWrapper extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain { - @NotNull private final ChangeRequestChain myChain; - @NotNull private final List myRequests; - - private int myIndex; - - public ChangeRequestChainWrapper(@NotNull ChangeRequestChain chain) { - myChain = chain; - myRequests = ContainerUtil.map(myChain.getAllRequests(), - new Function() { - @Override - public MyProducerWrapper fun(DiffRequestPresentable presentable) { - return new MyProducerWrapper(myChain, presentable); - } - }); - - myIndex = chain.getAllRequests().indexOf(chain.getCurrentRequest()); - } - - @NotNull - @Override - public List getRequests() { - return myRequests; - } - - @Override - public int getIndex() { - return myIndex; - } - - @Override - public void setIndex(int index) { - assert index >= 0 && index < myRequests.size(); - myIndex = index; - } - - @Nullable - private static Change getChange(@NotNull DiffRequestPresentable presentable) { - if (presentable instanceof DiffRequestPresentableProxy) { - try { - presentable = ((DiffRequestPresentableProxy)presentable).init(); - } - catch (VcsException e) { - LOG.info(e); - return null; - } - } - if (presentable instanceof ChangeDiffRequestPresentable) { - return ((ChangeDiffRequestPresentable)presentable).getChange(); - } - return null; - } - - @NotNull - @Override - public AnAction createGoToChangeAction(@NotNull Consumer onSelected) { - return new ChangeGoToChangePopupAction(this, onSelected) { - @NotNull - @Override - protected List getChanges() { - return ContainerUtil.mapNotNull(myChain.getRequests(), new Function() { - @Override - @Nullable - public Change fun(MyProducerWrapper wrapper) { - return getChange(wrapper.getPresentable()); - } - }); - } - - @Nullable - @Override - protected Change getCurrentSelection() { - return getChange(myChain.getRequests().get(myIndex).getPresentable()); - } - - @Override - protected int findSelectedStep(@Nullable Change change) { - if (change == null) return -1; - for (int i = 0; i < myRequests.size(); i++) { - Change c = getChange(myRequests.get(i).getPresentable()); - if (c != null && change.equals(c)) { - return i; - } - } - return -1; - } - }; - } - } - - private static class MyProducerWrapper implements DiffRequestProducer { - @NotNull private final DiffRequestPresentable myPresentable; - @NotNull private final ChangeRequestChain myChain; - - public MyProducerWrapper(@NotNull ChangeRequestChain chain, - @NotNull DiffRequestPresentable presentable) { - myPresentable = presentable; - myChain = chain; - } - - @NotNull - @Override - public String getName() { - return myPresentable.getPathPresentation(); - } - - @NotNull - public DiffRequestPresentable getPresentable() { - return myPresentable; - } - - @NotNull - @Override - public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) - throws DiffRequestProducerException, ProcessCanceledException { - com.intellij.openapi.diff.DiffRequest oldRequest = - UIUtil.invokeAndWaitIfNeeded(new Computable() { - @Override - public com.intellij.openapi.diff.DiffRequest compute() { - return myChain.moveTo(myPresentable); - } - }); - if (oldRequest == null) return new ErrorDiffRequest(this, "Can't build old-style request"); - return convertRequest(oldRequest); - } - } - private static class MyDiffRequestProducer implements DiffRequestProducer { @NotNull private final com.intellij.openapi.diff.DiffRequest myRequest; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java deleted file mode 100644 index 3bc8615d5f3f..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.patch; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.diff.*; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.impl.DocumentImpl; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.Getter; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.changes.actions.*; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -public class MergedDiffRequestPresentable implements DiffRequestPresentable { - private final Project myProject; - private final VirtualFile myFile; - private final String myAfterTitle; - private final Getter myTexts; - - public MergedDiffRequestPresentable(final Project project, - final Getter texts, - final VirtualFile file, - final String afterTitle) { - myTexts = texts; - myProject = project; - myFile = file; - myAfterTitle = afterTitle; - } - - public MyResult step(DiffChainContext context) { - if (myFile.getFileType().isBinary()) { - final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, myFile.getName(), context); - if (!nowItIsText) { - final SimpleDiffRequest request = new SimpleDiffRequest(myProject, null); - return new MyResult(request, DiffPresentationReturnValue.removeFromList); - } - } - final ApplyPatchForBaseRevisionTexts revisionTexts = myTexts.get(); - if (revisionTexts.getBase() == null) { - final SimpleDiffRequest badDiffRequest = createBadDiffRequest(myProject, myFile, revisionTexts, true); - return new MyResult(badDiffRequest, DiffPresentationReturnValue.useRequest); - } - final MergeRequest request = DiffRequestFactory.getInstance() - .create3WayDiffRequest(revisionTexts.getLocal().toString(), - revisionTexts.getPatched(), - revisionTexts.getBase().toString(), - myFile.getFileType(), myProject, null, null); - request.setWindowTitle(VcsBundle.message("patch.apply.conflict.title", FileUtil.toSystemDependentName(myFile.getPresentableUrl()))); - request.setVersionTitles(new String[]{"Current Version", "Base Version", FileUtil.toSystemDependentName(myAfterTitle)}); - return new MyResult(request, DiffPresentationReturnValue.useRequest); - } - - @Override - public String getPathPresentation() { - return myFile.getPath(); - } - - public void haveStuff() { - } - - public List createActions(DiffExtendUIFactory uiFactory) { - return Collections.emptyList(); - } - - @NotNull - public static SimpleDiffRequest createBadDiffRequest(@Nullable final Project project, - @NotNull final VirtualFile file, - @NotNull ApplyPatchForBaseRevisionTexts texts, - boolean readonly) { - final String fullPath = file.getParent() == null ? file.getPath() : file.getParent().getPath(); - final String title = "Result Of Patch Apply To " + file.getName() + " (" + fullPath + ")"; - - final SimpleDiffRequest simpleRequest = new SimpleDiffRequest(project, title); - final DocumentImpl patched = new DocumentImpl(texts.getPatched()); - patched.setReadOnly(false); - - final DocumentContent mergedContent = - new DocumentContent(project, patched, file.getFileType()); - mergedContent.getDocument().setReadOnly(readonly); - final SimpleContent originalContent = new SimpleContent(texts.getLocal().toString(), file.getFileType()); - - simpleRequest.setContents(originalContent, mergedContent); - simpleRequest.setContentTitles(VcsBundle.message("diff.title.local"), "Patched (with problems)"); - simpleRequest.addHint(DiffTool.HINT_SHOW_MODAL_DIALOG); - simpleRequest.addHint(DiffTool.HINT_DIFF_IS_APPROXIMATE); - - if (!readonly) { - simpleRequest.setOnOkRunnable(new Runnable() { - @Override - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - final String resultText = mergedContent.getDocument().getText(); - final Document document = FileDocumentManager.getInstance().getDocument(file); - if (document == null) { - try { - VfsUtil.saveText(file, resultText); - } - catch (IOException e) { - // todo bad: we had already returned success by now - showIOException(project, file.getName(), e); - } - } - else { - document.setText(resultText); - FileDocumentManager.getInstance().saveDocument(document); - } - } - }); - } - }); - } - return simpleRequest; - } - - private static void showIOException(@Nullable Project project, @NotNull String name, @NotNull IOException e) { - Messages.showErrorDialog(project, - VcsBundle.message("patch.apply.error", name, e.getMessage()), - VcsBundle.message("patch.apply.dialog.title")); - } -}