diff: cleanup
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 27 Aug 2015 10:59:18 +0000 (13:59 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Mon, 31 Aug 2015 09:50:36 +0000 (12:50 +0300)
platform/diff-impl/src/com/intellij/diff/merge/BinaryMergeTool.java
platform/diff-impl/src/com/intellij/diff/merge/MergeUtil.java
platform/diff-impl/src/com/intellij/diff/merge/TextMergeTool.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchMergeTool.java

index 76df64d8e1b09711dc12e4fc808070917be84a0b..f9e11c87bc143ab8f9434ab996f304783203d446 100644 (file)
@@ -23,8 +23,6 @@ import com.intellij.diff.requests.DiffRequest;
 import com.intellij.diff.requests.SimpleDiffRequest;
 import com.intellij.diff.tools.binary.ThreesideBinaryDiffViewer;
 import com.intellij.diff.tools.holders.BinaryEditorHolder;
-import com.intellij.openapi.diff.DiffBundle;
-import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.BooleanGetter;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.util.containers.ContainerUtil;
@@ -116,9 +114,7 @@ public class BinaryMergeTool implements MergeTool {
       components.closeHandler = new BooleanGetter() {
         @Override
         public boolean get() {
-          return Messages.showYesNoDialog(getComponent().getRootPane(),
-                                          DiffBundle.message("merge.dialog.exit.without.applying.changes.confirmation.message"),
-                                          DiffBundle.message("cancel.visual.merge.dialog.title"), Messages.getQuestionIcon()) == Messages.YES;
+          return MergeUtil.showExitWithoutApplyingChangesDialog(getComponent(), myMergeRequest, myMergeContext);
         }
       };
 
@@ -134,14 +130,10 @@ public class BinaryMergeTool implements MergeTool {
       return new AbstractAction(caption) {
         @Override
         public void actionPerformed(ActionEvent e) {
-          if (result == MergeResult.CANCEL) {
-            if (Messages.showYesNoDialog(getComponent().getRootPane(),
-                                         DiffBundle.message("merge.dialog.exit.without.applying.changes.confirmation.message"),
-                                         DiffBundle.message("cancel.visual.merge.dialog.title"), Messages.getQuestionIcon()) != Messages.YES) {
-              return;
-            }
+          if (result == MergeResult.CANCEL &&
+              !MergeUtil.showExitWithoutApplyingChangesDialog(getComponent(), myMergeRequest, myMergeContext)) {
+            return;
           }
-
           myMergeContext.finishMerge(result);
         }
       };
index 36b5e6d480733071cd743cb8a36035d33675b4db..004915250a3505eca1d1c32bdc539b8054beb087 100644 (file)
@@ -17,13 +17,16 @@ package com.intellij.diff.merge;
 
 import com.intellij.diff.DiffContext;
 import com.intellij.diff.util.ThreeSide;
+import com.intellij.openapi.diff.DiffBundle;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import javax.swing.*;
 import java.util.List;
 
 public class MergeUtil {
@@ -90,4 +93,11 @@ public class MergeUtil {
       myMergeContext.putUserData(key, value);
     }
   }
+
+  public static boolean showExitWithoutApplyingChangesDialog(@NotNull JComponent component, @NotNull MergeRequest request, @NotNull MergeContext context) {
+    return Messages.showYesNoDialog(component.getRootPane(),
+                                    DiffBundle.message("merge.dialog.exit.without.applying.changes.confirmation.message"),
+                                    DiffBundle.message("cancel.visual.merge.dialog.title"), Messages.getQuestionIcon()) ==
+           Messages.YES;
+  }
 }
index 0b24f14f16331a9d38459293c2a0e4e081d4061e..eb775e9ceb6907bbbe43597e336a7a581462f9a1 100644 (file)
@@ -166,9 +166,7 @@ public class TextMergeTool implements MergeTool {
       components.closeHandler = new BooleanGetter() {
         @Override
         public boolean get() {
-          return Messages.showYesNoDialog(getComponent().getRootPane(),
-                                          DiffBundle.message("merge.dialog.exit.without.applying.changes.confirmation.message"),
-                                          DiffBundle.message("cancel.visual.merge.dialog.title"), Messages.getQuestionIcon()) == Messages.YES;
+          return MergeUtil.showExitWithoutApplyingChangesDialog(getComponent(), myMergeRequest, myMergeContext);
         }
       };
 
@@ -313,12 +311,9 @@ public class TextMergeTool implements MergeTool {
                 return;
               }
             }
-            if (result == MergeResult.CANCEL) {
-              if (Messages.showYesNoDialog(myPanel.getRootPane(),
-                                           DiffBundle.message("merge.dialog.exit.without.applying.changes.confirmation.message"),
-                                           DiffBundle.message("cancel.visual.merge.dialog.title"), Messages.getQuestionIcon()) != Messages.YES) {
-                return;
-              }
+            if (result == MergeResult.CANCEL &&
+                !MergeUtil.showExitWithoutApplyingChangesDialog(getComponent(), myMergeRequest, myMergeContext)) {
+              return;
             }
             destroyChangedBlocks();
             myMergeContext.finishMerge(result);
index 2e4e0ce44d1bbe7652c33bef5d8c4e07b7ab9b4b..5458ebafd5edd3efb9f34102979694e036da8f62 100644 (file)
@@ -25,11 +25,9 @@ import com.intellij.diff.util.DiffUtil;
 import com.intellij.openapi.command.undo.DocumentReference;
 import com.intellij.openapi.command.undo.DocumentReferenceManager;
 import com.intellij.openapi.command.undo.UndoManager;
-import com.intellij.openapi.diff.DiffBundle;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.BooleanGetter;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -115,10 +113,7 @@ public class ApplyPatchMergeTool implements MergeTool {
       components.closeHandler = new BooleanGetter() {
         @Override
         public boolean get() {
-          return Messages.showYesNoDialog(getComponent().getRootPane(),
-                                          DiffBundle.message("merge.dialog.exit.without.applying.changes.confirmation.message"),
-                                          DiffBundle.message("cancel.visual.merge.dialog.title"), Messages.getQuestionIcon()) ==
-                 Messages.YES;
+          return MergeUtil.showExitWithoutApplyingChangesDialog(getComponent(), myMergeRequest, myMergeContext);
         }
       };
       return components;
@@ -133,13 +128,9 @@ public class ApplyPatchMergeTool implements MergeTool {
       return new AbstractAction(caption) {
         @Override
         public void actionPerformed(ActionEvent e) {
-          if (result == MergeResult.CANCEL) {
-            if (Messages.showYesNoDialog(getComponent().getRootPane(),
-                                         DiffBundle.message("merge.dialog.exit.without.applying.changes.confirmation.message"),
-                                         DiffBundle.message("cancel.visual.merge.dialog.title"), Messages.getQuestionIcon()) !=
-                Messages.YES) {
-              return;
-            }
+          if (result == MergeResult.CANCEL &&
+              !MergeUtil.showExitWithoutApplyingChangesDialog(getComponent(), myMergeRequest, myMergeContext)) {
+            return;
           }
           myMergeContext.finishMerge(result);
         }