diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index d57c32138bd1..8391d5b17503 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -2096,6 +2096,17 @@ public class UIUtil { } } + public static T invokeAndWaitIfNeeded(@NotNull final Computable computable) { + final Ref result = Ref.create(); + invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + result.set(computable.compute()); + } + }); + return result.get(); + } + public static void invokeAndWaitIfNeeded(@NotNull final ThrowableRunnable runnable) throws Throwable { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); diff --git a/plugins/git4idea/src/git4idea/branch/GitBranchUiHandlerImpl.java b/plugins/git4idea/src/git4idea/branch/GitBranchUiHandlerImpl.java index fd9cdf7a8473..b47c4c67325d 100644 --- a/plugins/git4idea/src/git4idea/branch/GitBranchUiHandlerImpl.java +++ b/plugins/git4idea/src/git4idea/branch/GitBranchUiHandlerImpl.java @@ -21,6 +21,7 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.VerticalFlowLayout; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsNotifier; import com.intellij.openapi.vcs.changes.Change; @@ -125,20 +126,21 @@ public class GitBranchUiHandlerImpl implements GitBranchUiHandler { } @Override - public boolean showUntrackedFilesDialogWithRollback(@NotNull String operationName, @NotNull String rollbackProposal, - @NotNull Collection untrackedFiles) { - String title = "Could not " + StringUtil.capitalize(operationName); - String description = UntrackedFilesNotifier.createUntrackedFilesOverwrittenDescription(operationName, false); + public boolean showUntrackedFilesDialogWithRollback(@NotNull String operationName, @NotNull final String rollbackProposal, + @NotNull final Collection untrackedFiles) { + final String title = "Could not " + StringUtil.capitalize(operationName); + final String description = UntrackedFilesNotifier.createUntrackedFilesOverwrittenDescription(operationName, false); - final SelectFilesDialog dialog = new UntrackedFilesDialog(myProject, untrackedFiles, StringUtil.stripHtml(description, true), rollbackProposal); - dialog.setTitle(title); - UIUtil.invokeAndWaitIfNeeded(new Runnable() { + return UIUtil.invokeAndWaitIfNeeded(new Computable() { @Override - public void run() { + public Boolean compute() { + SelectFilesDialog dialog = new UntrackedFilesDialog(myProject, untrackedFiles, + StringUtil.stripHtml(description, true), rollbackProposal); + dialog.setTitle(title); myFacade.showDialog(dialog); + return dialog.isOK(); } }); - return dialog.isOK(); } @NotNull diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java index 75a6df3e8f67..8bfc52ca261a 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java @@ -22,7 +22,9 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Couple; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.CheckinProjectPanel; import com.intellij.openapi.vcs.FilePath; @@ -131,14 +133,17 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory { } if (crlfHelper.get().shouldWarn()) { - final GitCrlfDialog dialog = new GitCrlfDialog(myProject); - UIUtil.invokeAndWaitIfNeeded(new Runnable() { + Pair codeAndDontWarn = UIUtil.invokeAndWaitIfNeeded(new Computable>() { @Override - public void run() { + public Pair compute() { + final GitCrlfDialog dialog = new GitCrlfDialog(myProject); dialog.show(); + return Pair.create(dialog.getExitCode(), dialog.dontWarnAgain()); } }); - int decision = dialog.getExitCode(); + int decision = codeAndDontWarn.first; + boolean dontWarnAgain = codeAndDontWarn.second; + if (decision == GitCrlfDialog.CANCEL) { return ReturnResult.CANCEL; } @@ -148,7 +153,7 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory { setCoreAutoCrlfAttribute(anyRoot); } else { - if (dialog.dontWarnAgain()) { + if (dontWarnAgain) { settings.setWarnAboutCrlf(false); } } diff --git a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java index 4815eb781fce..d04b8634fd3f 100644 --- a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java +++ b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java @@ -119,15 +119,15 @@ public class GitMergeUpdater extends GitUpdater { LOG.info("Local changes would be overwritten by merge"); final List paths = getFilesOverwrittenByMerge(mergeLineListener.getOutput()); final Collection changes = getLocalChangesFilteredByFiles(paths); - final ChangeListViewerDialog dialog = new ChangeListViewerDialog(myProject, changes, false) { - @Override protected String getDescription() { - return "Your local changes to the following files would be overwritten by merge.
" + - "Please, commit your changes or stash them before you can merge."; - } - }; UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { + ChangeListViewerDialog dialog = new ChangeListViewerDialog(myProject, changes, false) { + @Override protected String getDescription() { + return "Your local changes to the following files would be overwritten by merge.
" + + "Please, commit your changes or stash them before you can merge."; + } + }; dialog.show(); } });