From 27cc0eb31f92b603cb06ce03073e47d097c54876 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 14 Dec 2016 12:50:58 +0300 Subject: [PATCH] diff: notify caller that command was cancelled because document is ReadOnly --- .../intellij/diff/merge/MergeModelBase.java | 14 +++++----- .../intellij/diff/merge/TextMergeViewer.java | 18 ++++++------- .../src/com/intellij/diff/util/DiffUtil.java | 27 ++++++++++--------- .../changes/patch/tool/ApplyPatchViewer.java | 6 ++--- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/merge/MergeModelBase.java b/platform/diff-impl/src/com/intellij/diff/merge/MergeModelBase.java index c1acad670e27..9edcc7a25aaf 100644 --- a/platform/diff-impl/src/com/intellij/diff/merge/MergeModelBase.java +++ b/platform/diff-impl/src/com/intellij/diff/merge/MergeModelBase.java @@ -218,14 +218,14 @@ public abstract class MergeModelBase implements } } - public void executeMergeCommand(@Nullable String commandName, - @Nullable String commandGroupId, - @NotNull UndoConfirmationPolicy confirmationPolicy, - boolean underBulkUpdate, - @Nullable TIntArrayList affectedChanges, - @NotNull Runnable task) { + public boolean executeMergeCommand(@Nullable String commandName, + @Nullable String commandGroupId, + @NotNull UndoConfirmationPolicy confirmationPolicy, + boolean underBulkUpdate, + @Nullable TIntArrayList affectedChanges, + @NotNull Runnable task) { TIntArrayList allAffectedChanges = affectedChanges != null ? collectAffectedChanges(affectedChanges) : null; - DiffUtil.executeWriteCommand(myProject, myDocument, commandName, commandGroupId, confirmationPolicy, underBulkUpdate, () -> { + return DiffUtil.executeWriteCommand(myProject, myDocument, commandName, commandGroupId, confirmationPolicy, underBulkUpdate, () -> { LOG.assertTrue(!myInsideCommand); // We should restore states after changes in document (by DocumentUndoProvider) to avoid corruption by our onBeforeDocumentChange() diff --git a/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java b/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java index 1fa7c2a715ea..606475c5b745 100644 --- a/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java @@ -680,10 +680,10 @@ public class TextMergeViewer implements MergeTool.MergeViewer { /* * affected changes should be sorted */ - public void executeMergeCommand(@Nullable String commandName, - boolean underBulkUpdate, - @Nullable List affected, - @NotNull Runnable task) { + public boolean executeMergeCommand(@Nullable String commandName, + boolean underBulkUpdate, + @Nullable List affected, + @NotNull Runnable task) { myContentModified = true; TIntArrayList affectedIndexes = null; @@ -694,13 +694,13 @@ public class TextMergeViewer implements MergeTool.MergeViewer { } } - myModel.executeMergeCommand(commandName, null, UndoConfirmationPolicy.DEFAULT, underBulkUpdate, affectedIndexes, task); + return myModel.executeMergeCommand(commandName, null, UndoConfirmationPolicy.DEFAULT, underBulkUpdate, affectedIndexes, task); } - public void executeMergeCommand(@Nullable String commandName, - @Nullable List affected, - @NotNull Runnable task) { - executeMergeCommand(commandName, false, affected, task); + public boolean executeMergeCommand(@Nullable String commandName, + @Nullable List affected, + @NotNull Runnable task) { + return executeMergeCommand(commandName, false, affected, task); } @CalledInAwt diff --git a/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java b/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java index 4890efdf195b..eb7ccb1ed133 100644 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java +++ b/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java @@ -1105,17 +1105,17 @@ public class DiffUtil { // @CalledInAwt - public static void executeWriteCommand(@Nullable Project project, - @NotNull Document document, - @Nullable String commandName, - @Nullable String commandGroupId, - @NotNull UndoConfirmationPolicy confirmationPolicy, - boolean underBulkUpdate, - @NotNull Runnable task) { + public static boolean executeWriteCommand(@Nullable Project project, + @NotNull Document document, + @Nullable String commandName, + @Nullable String commandGroupId, + @NotNull UndoConfirmationPolicy confirmationPolicy, + boolean underBulkUpdate, + @NotNull Runnable task) { if (!makeWritable(project, document)) { VirtualFile file = FileDocumentManager.getInstance().getFile(document); LOG.warn("Document is read-only" + (file != null ? ": " + file.getPresentableName() : "")); - return; + return false; } ApplicationManager.getApplication().runWriteAction(() -> { @@ -1128,14 +1128,15 @@ public class DiffUtil { } }, commandName, commandGroupId, confirmationPolicy, document); }); + return true; } @CalledInAwt - public static void executeWriteCommand(@NotNull final Document document, - @Nullable final Project project, - @Nullable final String commandName, - @NotNull final Runnable task) { - executeWriteCommand(project, document, commandName, null, UndoConfirmationPolicy.DEFAULT, false, task); + public static boolean executeWriteCommand(@NotNull final Document document, + @Nullable final Project project, + @Nullable final String commandName, + @NotNull final Runnable task) { + return executeWriteCommand(project, document, commandName, null, UndoConfirmationPolicy.DEFAULT, false, task); } public static boolean isEditable(@NotNull Editor editor) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java index b62242491a49..4662d8985571 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java @@ -401,9 +401,9 @@ class ApplyPatchViewer implements DataProvider, Disposable { myContentPanel.repaintDivider(); } - public void executeCommand(@Nullable String commandName, - @NotNull final Runnable task) { - myModel.executeMergeCommand(commandName, null, UndoConfirmationPolicy.DEFAULT, false, null, task); + public boolean executeCommand(@Nullable String commandName, + @NotNull final Runnable task) { + return myModel.executeMergeCommand(commandName, null, UndoConfirmationPolicy.DEFAULT, false, null, task); } class MyModel extends MergeModelBase {