git: do not create swing components on pooled thread

This commit is contained in:
Aleksey Pivovarov
2017-09-19 16:00:50 +03:00
parent ea7a991311
commit e7a59cb711
2 changed files with 21 additions and 24 deletions
@@ -35,13 +35,10 @@ import git4idea.GitUtil;
import git4idea.commands.Git;
import git4idea.merge.GitConflictResolver;
import git4idea.repo.GitRepository;
import git4idea.ui.ChangesBrowserWithRollback;
import git4idea.util.GitSimplePathsBrowser;
import git4idea.util.GitUntrackedFilesHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.util.Collection;
import java.util.List;
@@ -140,14 +137,11 @@ public class GitBranchUiHandlerImpl implements GitBranchUiHandler {
@NotNull Collection<String> paths,
@NotNull String operation,
@Nullable String forceButtonTitle) {
JComponent fileBrowser;
if (!changes.isEmpty()) {
fileBrowser = new ChangesBrowserWithRollback(project, changes);
}
else {
fileBrowser = new GitSimplePathsBrowser(project, paths);
}
return GitSmartOperationDialog.showAndGetAnswer(myProject, fileBrowser, operation, forceButtonTitle);
Ref<GitSmartOperationDialog.Choice> exitCode = Ref.create();
ApplicationManager.getApplication().invokeAndWait(() -> {
exitCode.set(GitSmartOperationDialog.show(project, changes, paths, operation, forceButtonTitle));
});
return exitCode.get();
}
@Override
@@ -15,20 +15,23 @@
*/
package git4idea.branch;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.JBUI;
import git4idea.DialogManager;
import git4idea.ui.ChangesBrowserWithRollback;
import git4idea.util.GitSimplePathsBrowser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.Collection;
import java.util.List;
import static com.intellij.openapi.util.text.StringUtil.capitalize;
@@ -66,17 +69,17 @@ public class GitSmartOperationDialog extends DialogWrapper {
* Shows the dialog with the list of local changes preventing merge/checkout and returns the user's choice.
*/
@NotNull
static Choice showAndGetAnswer(@NotNull Project project,
@NotNull JComponent fileBrowser,
@NotNull String operationTitle,
@Nullable String forceButtonTitle) {
Ref<Choice> exitCode = Ref.create();
ApplicationManager.getApplication().invokeAndWait(() -> {
GitSmartOperationDialog dialog = new GitSmartOperationDialog(project, fileBrowser, operationTitle, forceButtonTitle);
DialogManager.show(dialog);
exitCode.set(Choice.fromDialogExitCode(dialog.getExitCode()));
});
return exitCode.get();
static Choice show(@NotNull Project project,
@NotNull List<Change> changes,
@NotNull Collection<String> paths,
@NotNull String operationTitle,
@Nullable String forceButtonTitle) {
JComponent fileBrowser = !changes.isEmpty()
? new ChangesBrowserWithRollback(project, changes)
: new GitSimplePathsBrowser(project, paths);
GitSmartOperationDialog dialog = new GitSmartOperationDialog(project, fileBrowser, operationTitle, forceButtonTitle);
DialogManager.show(dialog);
return Choice.fromDialogExitCode(dialog.getExitCode());
}
private GitSmartOperationDialog(@NotNull Project project, @NotNull JComponent fileBrowser, @NotNull String operationTitle,