From 071186a88d24c41373353530d3037937be64c6ee Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 3 Aug 2011 12:26:15 +0400 Subject: [PATCH] GitPushActiveBranches: backgroundable task on initialization. --- .../checkin/GitPushActiveBranchesDialog.java | 79 ++++++++++++------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java b/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java index e62bc11d2ae7..7b6b0686f3f7 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java +++ b/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java @@ -212,38 +212,56 @@ public class GitPushActiveBranchesDialog extends DialogWrapper { * @param exceptions the collected exceptions */ public static void showDialog(final Project project, final List vcsRoots, final Collection exceptions) { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - public void run() { - final List emptyRoots = - loadRoots(project, vcsRoots, exceptions, false); // collect roots without fetching - just to show dialog - if (!exceptions.isEmpty()) { - exceptions.addAll(exceptions); - return; - } - final GitPushActiveBranchesDialog dialog = new GitPushActiveBranchesDialog(project, vcsRoots, emptyRoots); - dialog.refreshTree(true, null, false); // start initial fetch - - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - dialog.show(); - if (dialog.isOK()) { - dialog.rebaseAndPush(); - } - - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - public void run() { - for (VirtualFile root : vcsRoots) { - GitRepositoryManager.getInstance(project).updateRepository(root, GitRepository.TrackedTopic.ALL); - } - } - }); - } - }); - } - }); + new DialogInitTask(project, vcsRoots, exceptions).queue(); } + private static class DialogInitTask extends Task.Backgroundable { + private final Project myProject; + private final List myVcsRoots; + private final Collection myExceptions; + private GitPushActiveBranchesDialog myDialog; + + public DialogInitTask(Project project, List vcsRoots, Collection exceptions) { + super(project, "Collection information for push", false); + myProject = project; + myVcsRoots = vcsRoots; + myExceptions = exceptions; + } + + @Override public void run(@NotNull ProgressIndicator indicator) { + final List emptyRoots = + loadRoots(myProject, myVcsRoots, myExceptions, false); // collect roots without fetching - just to show dialog + if (!myExceptions.isEmpty()) { + myExceptions.addAll(myExceptions); + return; + } + myDialog = new GitPushActiveBranchesDialog(myProject, myVcsRoots, emptyRoots); + myDialog.refreshTree(true, null, false); // start initial fetch + + indicator.stop(); // if indicator is not stopped, the progress would be displayed all the time the dialog is displayed. + } + + @Override + public void onSuccess() { + if (myDialog != null) { + myDialog.show(); + if (myDialog.isOK()) { + myDialog.rebaseAndPush(); + } + } + + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + for (VirtualFile root : myVcsRoots) { + GitRepositoryManager.getInstance(myProject).updateRepository(root, GitRepository.TrackedTopic.ALL); + } + } + }); + } + } + + /** * This is called when "Rebase and Push" button (default button) is pressed. * 1. Closes the dialog. @@ -1074,4 +1092,5 @@ public class GitPushActiveBranchesDialog extends DialogWrapper { return string.toString(); } } + }