diff options
author | Dariusz Luksza | 2011-05-05 21:42:51 +0000 |
---|---|---|
committer | Chris Aniszczyk | 2011-05-12 18:32:34 +0000 |
commit | 84a461dee538cfd665160f72805ddf193e7ce49e (patch) | |
tree | 39d77d4b6d9d6dea4c603429244bd4849577a5f9 /org.eclipse.egit.ui | |
parent | 562ff7890f47f4be0cb9b6e76f8fc4d645374228 (diff) | |
download | egit-84a461dee538cfd665160f72805ddf193e7ce49e.tar.gz egit-84a461dee538cfd665160f72805ddf193e7ce49e.tar.xz egit-84a461dee538cfd665160f72805ddf193e7ce49e.zip |
[sync] Add 'Push' action into sync-view toolbar
Adds a 'Push' button into Synchronize view toolbar. This action is
enabled when only one repository is being synchronized and when one of
specified branch is remote branch.
Bug: 326635
Change-Id: Ib70cf7e177c35d511e9f91356065b49294826f52
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.egit.ui')
6 files changed, 122 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIIcons.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIIcons.java index 96d51a0adc..2a623a3084 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIIcons.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIIcons.java @@ -107,6 +107,9 @@ public class UIIcons { /** Import button */ public final static ImageDescriptor FETCH; + /** Import button */ + public final static ImageDescriptor PULL; + /** Export button */ public final static ImageDescriptor PUSH; @@ -202,6 +205,7 @@ public class UIIcons { FILTERFOLDER = map("elcl16/filterfolder.gif"); //$NON-NLS-1$ FETCH = map("obj16/fetch.gif"); //$NON-NLS-1$ PUSH = map("obj16/push.gif"); //$NON-NLS-1$ + PULL = map("obj16/pull.gif"); //$NON-NLS-1$ REPOSITORY = map("obj16/repository_rep.gif"); //$NON-NLS-1$ NEW_REPOSITORY = map("etool16/newlocation_wiz.gif"); //$NON-NLS-1$ REMOTE_REPOSITORY = map("obj16/remote_entry_tbl.gif"); //$NON-NLS-1$ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index 482e40fa50..d054252dab 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -3527,6 +3527,9 @@ public class UIText extends NLS { public static String GitActionContributor_ExpandAll; /** */ + public static String GitActionContributor_Push; + + /** */ public static String DecoratableResourceHelper_noHead; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java index a6389f2256..a87a1a9915 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java @@ -9,6 +9,7 @@ package org.eclipse.egit.ui.internal.synchronize; import static org.eclipse.egit.ui.UIIcons.EXPAND_ALL; +import static org.eclipse.egit.ui.UIIcons.PUSH; import static org.eclipse.egit.ui.UIText.GitActionContributor_ExpandAll; import static org.eclipse.egit.ui.internal.actions.ActionCommands.ADD_TO_INDEX; import static org.eclipse.egit.ui.internal.actions.ActionCommands.COMMIT_ACTION; @@ -17,12 +18,15 @@ import static org.eclipse.egit.ui.internal.actions.ActionCommands.PUSH_ACTION; import static org.eclipse.egit.ui.internal.synchronize.model.SupportedContextActionsHelper.canPush; import static org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration.NAVIGATE_GROUP; import static org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration.P_TOOLBAR_MENU; +import static org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration.SYNCHRONIZE_GROUP; import static org.eclipse.ui.ISources.ACTIVE_MENU_SELECTION_NAME; import static org.eclipse.ui.menus.CommandContributionItem.STYLE_PUSH; import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.internal.synchronize.action.ExpandAllModelAction; import org.eclipse.egit.ui.internal.synchronize.action.OpenWorkingFileAction; +import org.eclipse.egit.ui.internal.synchronize.action.PushAction; import org.eclipse.egit.ui.internal.synchronize.model.GitModelObject; import org.eclipse.egit.ui.internal.synchronize.model.SupportedContextActionsHelper; import org.eclipse.jface.action.IContributionItem; @@ -113,6 +117,12 @@ class GitActionContributor extends SynchronizePageActionGroup { expandAllAction.setImageDescriptor(EXPAND_ALL); appendToGroup(P_TOOLBAR_MENU, NAVIGATE_GROUP, expandAllAction); + PushAction pushAction = new PushAction( + UIText.GitActionContributor_Push, configuration); + pushAction.setImageDescriptor(PUSH); + + appendToGroup(P_TOOLBAR_MENU, SYNCHRONIZE_GROUP, pushAction); + ISynchronizePageSite site = configuration.getSite(); IWorkbenchSite ws = site.getWorkbenchSite(); openWorkingFileAction = new OpenWorkingFileAction(ws.getWorkbenchWindow() diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java index 4b9f88eed6..c3ff256958 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java @@ -41,6 +41,11 @@ import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant; public class GitModelSynchronizeParticipant extends ModelSynchronizeParticipant { /** + * Key value for obtaining {@link GitSynchronizeDataSet} from {@link ISynchronizePageConfiguration} + */ + public static final String SYNCHRONIZATION_DATA = "GIT_SYNCHRONIZE_DATA_SET"; //$NON-NLS-1$ + + /** * Id of model compare participant */ public static final String ID = "org.eclipse.egit.ui.modelCompareParticipant"; //$NON-NLS-1$ @@ -88,6 +93,9 @@ public class GitModelSynchronizeParticipant extends ModelSynchronizeParticipant configuration.setProperty( ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER, modelProvider); + + configuration.setProperty(SYNCHRONIZATION_DATA, gsds); + super.initializeConfiguration(configuration); configuration.addActionContribution(new GitActionContributor()); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/action/PushAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/action/PushAction.java new file mode 100644 index 0000000000..9bba857282 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/action/PushAction.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (C) 2011, Dariusz Luksza <dariusz@luksza.org> + * + * 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 + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.ui.internal.synchronize.action; + +import static org.eclipse.egit.ui.internal.synchronize.GitModelSynchronizeParticipant.SYNCHRONIZATION_DATA; + +import java.lang.reflect.InvocationTargetException; +import java.net.URISyntaxException; + +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData; +import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet; +import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.UIPreferences; +import org.eclipse.egit.ui.credentials.EGitCredentialsProvider; +import org.eclipse.egit.ui.internal.push.PushOperationUI; +import org.eclipse.jgit.transport.RemoteConfig; +import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; +import org.eclipse.team.ui.synchronize.SynchronizeModelAction; +import org.eclipse.team.ui.synchronize.SynchronizeModelOperation; + +/** + * Push action used in Synchronize view toolbar + */ +public class PushAction extends SynchronizeModelAction { + + /** + * Construct {@link PushAction} + * + * @param text the action's text + * @param configuration the actions synchronize page configuration + */ + public PushAction(String text, ISynchronizePageConfiguration configuration) { + super(text, configuration); + } + + @Override + protected SynchronizeModelOperation getSubscriberOperation( + ISynchronizePageConfiguration configuration, IDiffElement[] elements) { + final int timeout = Activator.getDefault().getPreferenceStore() + .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); + + return new SynchronizeModelOperation(configuration, elements) { + + public void run(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + GitSynchronizeDataSet gsds = (GitSynchronizeDataSet) getConfiguration() + .getProperty(SYNCHRONIZATION_DATA); + GitSynchronizeData gsd = gsds.iterator().next(); + + String remoteName = gsd.getSrcRemoteName(); + if (remoteName == null) + remoteName = gsd.getDstRemoteName(); + + RemoteConfig rc; + try { + rc = new RemoteConfig(gsd.getRepository() + .getConfig(), gsd.getDstRemoteName()); + PushOperationUI push = new PushOperationUI(gsd.getRepository(), + rc, timeout, false); + push.setCredentialsProvider(new EGitCredentialsProvider()); + push.execute(monitor); + } catch (URISyntaxException e) { + new InvocationTargetException(e); + } catch (CoreException e) { + new InvocationTargetException(e); + } + } + }; + } + + @Override + public boolean isEnabled() { + GitSynchronizeDataSet gsds = (GitSynchronizeDataSet) getConfiguration() + .getProperty(SYNCHRONIZATION_DATA); + + if (gsds == null || gsds.size() != 1) + return false; + + GitSynchronizeData gsd = gsds.iterator().next(); + String srcRemoteName = gsd.getSrcRemoteName(); + String dstRemoteName = gsd.getDstRemoteName(); + + return srcRemoteName != dstRemoteName + && (srcRemoteName != null || dstRemoteName != null); + } + +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 2ce768b7c1..49ee4afa42 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -1223,6 +1223,7 @@ SimplePushActionHandler_NothingToPushDialogTitle=Nothing to push SwitchToMenu_NewBranchMenuLabel=&New Branch... SwitchToMenu_OtherMenuLabel=&Other... GitActionContributor_ExpandAll=Expand All +GitActionContributor_Push=Push OpenWorkingFileAction_text=&Open OpenWorkingFileAction_tooltip=Open Working File |