From d58c936fa4cc6e1d412a419aa9f931dbd645f7f2 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Tue, 24 May 2016 20:49:12 +0200 Subject: [PATCH] Create push wizards in CommitJob in UI thread The PushBranchWizard may have an AddRemotePage, which is a RepositorySelectionPage, which accesses the clipboard in its constructor. Let's create the wizard already in the UI thread, as it was before commit af5c88dc. Bug: 494469 Change-Id: Ifd7383a806becc7db20b2b44b6a67533394d91e5 Signed-off-by: Thomas Wolf --- .../eclipse/egit/ui/internal/commit/CommitJob.java | 63 ++++++++++++---------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java index c927ca8e6..64952bdbc 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012-2014 Red Hat, Inc. Distributed under license by Red Hat, Inc. + * Copyright (c) 2012-2016 Red Hat, Inc, and others. Distributed under license by Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -163,51 +163,58 @@ public class CommitJob extends Job { } private void pushUpstream(final RevCommit commit, final PushMode pushTo) { - RemoteConfig config = SimpleConfigurePushDialog + final RemoteConfig config = SimpleConfigurePushDialog .getConfiguredRemote(repository); - if (pushTo == PushMode.GERRIT) { - final Wizard pushWizard = new PushToGerritWizard(repository); - openPushWizard(pushWizard); - } else if (config == null) { + if (pushTo == PushMode.GERRIT || config == null) { + final Display display = PlatformUI.getWorkbench().getDisplay(); + display.asyncExec(new Runnable() { + + @Override + public void run() { + Wizard pushWizard = getPushWizard(commit, pushTo); + if (pushWizard != null) { + WizardDialog wizardDialog = new WizardDialog( + display.getActiveShell(), pushWizard); + wizardDialog.setHelpAvailable(true); + wizardDialog.open(); + } + } + }); + } else { + PushOperationUI op = new PushOperationUI(repository, + config.getName(), false); + op.start(); + } + } + + private Wizard getPushWizard(final RevCommit commit, + final PushMode pushTo) { + switch (pushTo) { + case GERRIT: + return new PushToGerritWizard(repository); + case UPSTREAM: try { - Wizard pushWizard = null; String fullBranch = repository.getFullBranch(); if (fullBranch != null && fullBranch.startsWith(Constants.R_HEADS)) { Ref ref = repository.exactRef(fullBranch); - pushWizard = new PushBranchWizard(repository, ref); + return new PushBranchWizard(repository, ref); } else { - pushWizard = new PushBranchWizard(repository, + return new PushBranchWizard(repository, commit.getId()); } - openPushWizard(pushWizard); } catch (IOException e) { Activator.handleError( NLS.bind(UIText.CommitUI_pushFailedMessage, e), e, true); + return null; } - } else { - PushOperationUI op = new PushOperationUI(repository, - config.getName(), false); - op.start(); + default: + return null; } } - private void openPushWizard(final Wizard pushWizard) { - final Display display = Display.getDefault(); - display.asyncExec(new Runnable() { - - @Override - public void run() { - WizardDialog wizardDialog = new WizardDialog(display - .getActiveShell(), pushWizard); - wizardDialog.setHelpAvailable(true); - wizardDialog.open(); - } - }); - } - @Override public boolean belongsTo(Object family) { if (JobFamilies.COMMIT.equals(family)) -- 2.11.4.GIT