merge: abort patch applying in read-only documents

This commit is contained in:
Aleksey Pivovarov
2016-12-14 14:18:07 +03:00
committed by Aleksey Pivovarov
parent f277f6aafd
commit 6adf8509af
2 changed files with 11 additions and 2 deletions
@@ -35,7 +35,6 @@ public class SimpleDiffPanel extends DiffPanelBase {
JPanel centerPanel = JBUI.Panels.simplePanel(editorPanel).addToTop(myNotificationsPanel);
myContentPanel.add(centerPanel, GOOD_CONTENT);
myContentPanel.add(DiffUtil.createMessagePanel("Error"), ERROR_CONTENT);
setCurrentCard(GOOD_CONTENT, false);
}
@@ -49,6 +48,11 @@ public class SimpleDiffPanel extends DiffPanelBase {
}
public void setErrorContent() {
setErrorContent("Error");
}
public void setErrorContent(@NotNull String message) {
myContentPanel.add(DiffUtil.createMessagePanel(message), ERROR_CONTENT);
setCurrentCard(ERROR_CONTENT);
}
@@ -49,6 +49,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.BooleanGetter;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.patch.AppliedTextPatch;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.TIntArrayList;
@@ -285,10 +286,14 @@ class ApplyPatchViewer implements DataProvider, Disposable {
protected void initPatchViewer() {
final Document outputDocument = myResultEditor.getDocument();
DiffUtil.executeWriteCommand(outputDocument, myProject, "Init merge content", () -> {
boolean success = DiffUtil.executeWriteCommand(outputDocument, myProject, "Init merge content", () -> {
outputDocument.setText(myPatchRequest.getLocalContent());
if (!isReadOnly()) DiffUtil.putNonundoableOperation(myProject, outputDocument);
});
if (!success && !StringUtil.equals(outputDocument.getText(), myPatchRequest.getLocalContent())) {
myPanel.setErrorContent("Failed to display patch applier - local content was modified");
return;
}
PatchChangeBuilder builder = new PatchChangeBuilder();