diff --git a/platform/diff-impl/src/com/intellij/diff/requests/BinaryMergeRequestImpl.java b/platform/diff-impl/src/com/intellij/diff/requests/BinaryMergeRequestImpl.java index 3e0716f47750..aabec2fd8553 100644 --- a/platform/diff-impl/src/com/intellij/diff/requests/BinaryMergeRequestImpl.java +++ b/platform/diff-impl/src/com/intellij/diff/requests/BinaryMergeRequestImpl.java @@ -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); + } } } diff --git a/platform/diff-impl/src/com/intellij/diff/requests/TextMergeRequestImpl.java b/platform/diff-impl/src/com/intellij/diff/requests/TextMergeRequestImpl.java index f01b41e31879..5b6f8946232c 100644 --- a/platform/diff-impl/src/com/intellij/diff/requests/TextMergeRequestImpl.java +++ b/platform/diff-impl/src/com/intellij/diff/requests/TextMergeRequestImpl.java @@ -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); + } } }