mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[hg]: create branch on current thread and call this method from external task with userFriendly indicator
* remove unncessary processHandler;
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user