use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class GitUnstashDialog method doOKAction.
@Override
protected void doOKAction() {
VirtualFile root = getGitRoot();
final GitLineHandler h = handler();
final AtomicBoolean conflict = new AtomicBoolean();
h.addLineListener(new GitLineHandlerAdapter() {
public void onLineAvailable(String line, Key outputType) {
if (line.contains("Merge conflict")) {
conflict.set(true);
}
}
});
GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, MERGE);
h.addLineListener(untrackedFilesDetector);
h.addLineListener(localChangesDetector);
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
try {
final Ref<GitCommandResult> result = Ref.create();
final ProgressManager progressManager = ProgressManager.getInstance();
boolean completed = progressManager.runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
h.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(progressManager.getProgressIndicator(), h, "stash", false));
Git git = Git.getInstance();
result.set(git.runCommand(new Computable.PredefinedValueComputable<>(h)));
}
}, GitBundle.getString("unstash.unstashing"), true, myProject);
if (!completed)
return;
VfsUtil.markDirtyAndRefresh(false, true, false, root);
GitCommandResult res = result.get();
if (conflict.get()) {
boolean conflictsResolved = new UnstashConflictResolver(myProject, root, getSelectedStash()).merge();
LOG.info("loadRoot " + root + ", conflictsResolved: " + conflictsResolved);
} else if (untrackedFilesDetector.wasMessageDetected()) {
GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(myProject, root, untrackedFilesDetector.getRelativeFilePaths(), "unstash", null);
} else if (localChangesDetector.wasMessageDetected()) {
LocalChangesWouldBeOverwrittenHelper.showErrorDialog(myProject, root, "unstash", localChangesDetector.getRelativeFilePaths());
} else if (!res.success()) {
GitUIUtil.showOperationErrors(myProject, h.errors(), h.printableCommandLine());
}
} finally {
token.finish();
}
super.doOKAction();
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class GitAbstractRebaseAction method actionPerformed.
@Override
public final void actionPerformed(AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
ProgressManager progressManager = ProgressManager.getInstance();
String progressTitle = getProgressTitle();
if (getRepositoryManager(project).hasOngoingRebase()) {
progressManager.run(new Task.Backgroundable(project, progressTitle) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
performActionForProject(project, indicator);
}
});
} else {
final GitRepository repositoryToOperate = chooseRepository(project, GitRebaseUtils.getRebasingRepositories(project));
if (repositoryToOperate != null) {
progressManager.run(new Task.Backgroundable(project, progressTitle) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
performActionForRepository(project, repositoryToOperate, indicator);
}
});
}
}
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class GitVFSListener method executeAdd.
@Override
protected void executeAdd(final List<VirtualFile> addedFiles, final Map<VirtualFile, VirtualFile> copiedFiles) {
// Filter added files before further processing
Map<VirtualFile, List<VirtualFile>> sortedFiles;
try {
sortedFiles = GitUtil.sortFilesByGitRoot(addedFiles, true);
} catch (VcsException e) {
throw new RuntimeException("The exception is not expected here", e);
}
final HashSet<VirtualFile> retainedFiles = new HashSet<>();
final ProgressManager progressManager = ProgressManager.getInstance();
progressManager.run(new Task.Backgroundable(myProject, GitBundle.getString("vfs.listener.checking.ignored"), true) {
@Override
public void run(@NotNull ProgressIndicator pi) {
for (Map.Entry<VirtualFile, List<VirtualFile>> e : sortedFiles.entrySet()) {
VirtualFile root = e.getKey();
List<VirtualFile> files = e.getValue();
pi.setText(root.getPresentableUrl());
try {
retainedFiles.addAll(myGit.untrackedFiles(myProject, root, files));
} catch (VcsException ex) {
ApplicationManager.getApplication().invokeLater(() -> gitVcs().showMessages(ex.getMessage()));
}
}
addedFiles.retainAll(retainedFiles);
AppUIUtil.invokeLaterIfProjectAlive(myProject, () -> originalExecuteAdd(addedFiles, copiedFiles));
}
});
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class AbstractCreateVirtualEnvDialog method createVirtualEnv.
public void createVirtualEnv(final VirtualEnvCallback callback) {
final ProgressManager progman = ProgressManager.getInstance();
final Sdk basicSdk = getSdk();
final Task.Modal createTask = new Task.Modal(myProject, PyBundle.message("sdk.create.venv.dialog.creating.venv"), false) {
String myPath;
public void run(@NotNull final ProgressIndicator indicator) {
try {
indicator.setText(PyBundle.message("sdk.create.venv.dialog.creating.venv"));
myPath = createEnvironment(basicSdk);
} catch (final ExecutionException e) {
ApplicationManager.getApplication().invokeLater(() -> {
final PackageManagementService.ErrorDescription description = PyPackageManagementService.toErrorDescription(Collections.singletonList(e), basicSdk);
if (description != null) {
PackagesNotificationPanel.showError(PyBundle.message("sdk.create.venv.dialog.error.failed.to.create.venv"), description);
}
}, ModalityState.any());
}
}
@Override
public void onSuccess() {
if (myPath != null) {
ApplicationManager.getApplication().invokeLater(() -> setupVirtualEnvSdk(myPath, associateWithProject(), callback));
}
}
};
progman.run(createTask);
}
Aggregations