merge: call onAssigned() for underlying DiffContents

This commit is contained in:
Aleksey Pivovarov
2016-06-29 13:44:33 +03:00
committed by Aleksey Pivovarov
parent c85610f9c5
commit db509daabd
2 changed files with 87 additions and 58 deletions
@@ -71,6 +71,8 @@ public class BinaryMergeRequestImpl extends BinaryMergeRequest {
myTitles = contentTitles;
myApplyCallback = applyCallback;
onAssigned(true);
}
@NotNull
@@ -105,41 +107,53 @@ public class BinaryMergeRequestImpl extends BinaryMergeRequest {
@Override
public void applyResult(@NotNull MergeResult result) {
final byte[] applyContent;
switch (result) {
case CANCEL:
applyContent = myOriginalContent;
break;
case LEFT:
applyContent = ThreeSide.LEFT.select(myByteContents);
break;
case RIGHT:
applyContent = ThreeSide.RIGHT.select(myByteContents);
break;
case RESOLVED:
applyContent = null;
break;
default:
throw new IllegalArgumentException(result.toString());
}
try {
final byte[] applyContent;
switch (result) {
case CANCEL:
applyContent = myOriginalContent;
break;
case LEFT:
applyContent = ThreeSide.LEFT.select(myByteContents);
break;
case RIGHT:
applyContent = ThreeSide.RIGHT.select(myByteContents);
break;
case RESOLVED:
applyContent = null;
break;
default:
throw new IllegalArgumentException(result.toString());
}
if (applyContent != null) {
new WriteCommandAction.Simple(null) {
@Override
protected void run() throws Throwable {
try {
VirtualFile file = myFile.getFile();
if (!DiffUtil.makeWritable(myProject, file)) throw new IOException("File is read-only: " + file.getPresentableName());
file.setBinaryContent(applyContent);
if (applyContent != null) {
new WriteCommandAction.Simple(null) {
@Override
protected void run() throws Throwable {
try {
VirtualFile file = myFile.getFile();
if (!DiffUtil.makeWritable(myProject, file)) throw new IOException("File is read-only: " + file.getPresentableName());
file.setBinaryContent(applyContent);
}
catch (IOException e) {
LOG.error(e);
Messages.showErrorDialog(myProject, "Can't apply result", CommonBundle.getErrorTitle());
}
}
catch (IOException e) {
LOG.error(e);
Messages.showErrorDialog(myProject, "Can't apply result", CommonBundle.getErrorTitle());
}
}
}.execute();
}
}.execute();
}
if (myApplyCallback != null) myApplyCallback.consume(result);
if (myApplyCallback != null) myApplyCallback.consume(result);
}
finally {
onAssigned(false);
}
}
private void onAssigned(boolean assigned) {
myFile.onAssigned(assigned);
for (DiffContent content : myContents) {
content.onAssigned(assigned);
}
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.diff.requests;
import com.intellij.diff.contents.DiffContent;
import com.intellij.diff.contents.DocumentContent;
import com.intellij.diff.merge.MergeResult;
import com.intellij.diff.merge.TextMergeRequest;
@@ -59,6 +60,8 @@ public class TextMergeRequestImpl extends TextMergeRequest {
myTitle = title;
myApplyCallback = applyCallback;
onAssigned(true);
}
@NotNull
@@ -87,32 +90,44 @@ public class TextMergeRequestImpl extends TextMergeRequest {
@Override
public void applyResult(@NotNull MergeResult result) {
final CharSequence applyContent;
switch (result) {
case CANCEL:
applyContent = myOriginalContent;
break;
case LEFT:
CharSequence leftContent = ThreeSide.LEFT.select(getContents()).getDocument().getImmutableCharSequence();
applyContent = StringUtil.convertLineSeparators(leftContent.toString());
break;
case RIGHT:
CharSequence rightContent = ThreeSide.RIGHT.select(getContents()).getDocument().getImmutableCharSequence();
applyContent = StringUtil.convertLineSeparators(rightContent.toString());
break;
case RESOLVED:
applyContent = null;
break;
default:
throw new IllegalArgumentException(result.toString());
}
try {
final CharSequence applyContent;
switch (result) {
case CANCEL:
applyContent = myOriginalContent;
break;
case LEFT:
CharSequence leftContent = ThreeSide.LEFT.select(getContents()).getDocument().getImmutableCharSequence();
applyContent = StringUtil.convertLineSeparators(leftContent.toString());
break;
case RIGHT:
CharSequence rightContent = ThreeSide.RIGHT.select(getContents()).getDocument().getImmutableCharSequence();
applyContent = StringUtil.convertLineSeparators(rightContent.toString());
break;
case RESOLVED:
applyContent = null;
break;
default:
throw new IllegalArgumentException(result.toString());
}
if (applyContent != null) {
DiffUtil.executeWriteCommand(myOutput.getDocument(), myProject, null, () -> {
myOutput.getDocument().setText(applyContent);
});
}
if (applyContent != null) {
DiffUtil.executeWriteCommand(myOutput.getDocument(), myProject, null, () -> {
myOutput.getDocument().setText(applyContent);
});
}
if (myApplyCallback != null) myApplyCallback.consume(result);
if (myApplyCallback != null) myApplyCallback.consume(result);
}
finally {
onAssigned(false);
}
}
private void onAssigned(boolean assigned) {
myOutput.onAssigned(assigned);
for (DocumentContent content : myContents) {
content.onAssigned(assigned);
}
}
}