From edf8abccf7f4d355de3d3217bdfa7d3314142b4e Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 2 Mar 2016 15:56:40 +0300 Subject: [PATCH] [hg]: create branch on current thread and call this method from external task with userFriendly indicator * remove unncessary processHandler; --- .../HgCreateNewBranchFromLogAction.java | 3 +- .../hg4idea/branch/HgBranchPopupActions.java | 28 ++++++++++--------- .../command/HgBranchCreateCommand.java | 8 +++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateNewBranchFromLogAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateNewBranchFromLogAction.java index 4e3a7d827796..f281f5c82386 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateNewBranchFromLogAction.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateNewBranchFromLogAction.java @@ -42,7 +42,8 @@ public class HgCreateNewBranchFromLogAction extends HgLogSingleCommitAction { @Override public void run(@NotNull ProgressIndicator indicator) { if (HgUpdateCommand.updateRepoToInCurrentThread(project, repository.getRoot(), commit.asString(), false)) { - new HgBranchPopupActions.HgNewBranchAction(project, Collections.singletonList(repository), repository).createNewBranch(name); + new HgBranchPopupActions.HgNewBranchAction(project, Collections.singletonList(repository), repository) + .createNewBranchInCurrentThread(name); } } }.queue(); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java index 56681352ff3c..98504387d551 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java @@ -25,6 +25,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; @@ -47,7 +49,6 @@ import org.zmlx.hg4idea.command.HgBookmarkCommand; import org.zmlx.hg4idea.command.HgBranchCreateCommand; import org.zmlx.hg4idea.execution.HgCommandException; import org.zmlx.hg4idea.execution.HgCommandResult; -import org.zmlx.hg4idea.execution.HgCommandResultHandler; import org.zmlx.hg4idea.provider.commit.HgCloseBranchExecutor; import org.zmlx.hg4idea.repo.HgRepository; import org.zmlx.hg4idea.repo.HgRepositoryManager; @@ -116,22 +117,23 @@ public class HgBranchPopupActions { if (name == null) { return; } - createNewBranch(name); + new Task.Backgroundable(myProject, "Creating " + StringUtil.pluralize("Branch", myRepositories.size()) + "...") { + @Override + public void run(@NotNull ProgressIndicator indicator) { + createNewBranchInCurrentThread(name); + } + }.queue(); } - public void createNewBranch(@NotNull final String name) { + public void createNewBranchInCurrentThread(@NotNull final String name) { for (final HgRepository repository : myRepositories) { try { - new HgBranchCreateCommand(myProject, repository.getRoot(), name).execute(new HgCommandResultHandler() { - @Override - public void process(@Nullable HgCommandResult result) { - repository.update(); - if (HgErrorUtil.hasErrorsInCommandExecution(result)) { - new HgCommandResultNotifier(myProject) - .notifyError(result, "Creation failed", "Branch creation [" + name + "] failed"); - } - } - }); + HgCommandResult result = new HgBranchCreateCommand(myProject, repository.getRoot(), name).executeInCurrentThread(); + repository.update(); + if (HgErrorUtil.hasErrorsInCommandExecution(result)) { + new HgCommandResultNotifier(myProject) + .notifyError(result, "Creation failed", "Branch creation [" + name + "] failed"); + } } catch (HgCommandException exception) { HgErrorUtil.handleException(myProject, "Can't create new branch: ", exception); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBranchCreateCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBranchCreateCommand.java index 759c0613ac29..3eda92e1dc9d 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBranchCreateCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBranchCreateCommand.java @@ -22,9 +22,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.execution.HgCommandException; import org.zmlx.hg4idea.execution.HgCommandExecutor; -import org.zmlx.hg4idea.execution.HgCommandResultHandler; +import org.zmlx.hg4idea.execution.HgCommandResult; -import java.util.Arrays; +import java.util.Collections; /** * @author Nadya Zabrodina @@ -41,10 +41,10 @@ public class HgBranchCreateCommand { this.branchName = branchName; } - public void execute(@Nullable HgCommandResultHandler resultHandler) throws HgCommandException { + public HgCommandResult executeInCurrentThread() throws HgCommandException { if (StringUtil.isEmptyOrSpaces(branchName)) { throw new HgCommandException("branch name is empty"); } - new HgCommandExecutor(project).execute(repo, "branch", Arrays.asList(branchName), resultHandler); + return new HgCommandExecutor(project).executeInCurrentThread(repo, "branch", Collections.singletonList(branchName)); } }