diff options
Diffstat (limited to 'org.eclipse.egit.ui/src')
8 files changed, 469 insertions, 174 deletions
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 0f2c47eafd..572989811c 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 @@ -1854,6 +1854,42 @@ public class UIText extends NLS { /** */ public static String GitShareProjectsPage_RepositoryLabel; + /** */ + public static String MergeAction_CannotMerge; + + /** */ + public static String MergeAction_ChangedFiles; + + /** */ + public static String MergeAction_ErrorMergeEnabling; + + /** */ + public static String MergeAction_HeadIsNoBranch; + + /** */ + public static String MergeAction_JobNameMerge; + + /** */ + public static String MergeAction_ProblemMerge; + + /** */ + public static String MergeAction_UnableMerge; + + /** */ + public static String MergeAction_WrongRepositoryState; + + /** */ + public static String MergeTargetSelectionDialog_ButtonMerge; + + /** */ + public static String MergeTargetSelectionDialog_OnlyFastForward; + + /** */ + public static String MergeTargetSelectionDialog_SelectRef; + + /** */ + public static String MergeTargetSelectionDialog_TitleMerge; + /** */ public static String MixedResetToRevisionAction_mixedReset; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java index 6e603d13c0..9c78831f57 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java @@ -48,7 +48,7 @@ public class BranchAction extends RepositoryAction { return; } - BranchSelectionDialog dialog = new BranchSelectionDialog(getShell(), repository, false); + BranchSelectionDialog dialog = new BranchSelectionDialog(getShell(), repository); if (dialog.open() != Window.OK) { return; } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java new file mode 100644 index 0000000000..9a90c125eb --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2010 SAP AG. + * 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 + * + * Contributors: + * Stefan Lay (SAP AG) - initial implementation + *******************************************************************************/ + +package org.eclipse.egit.ui.internal.actions; + +import java.io.IOException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.egit.core.op.MergeOperation; +import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.UIText; +import org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.RepositoryState; +import org.eclipse.osgi.util.NLS; +import org.eclipse.team.internal.ui.Utils; + +/** + * Action for selecting a commit and merging it with the current branch. + */ +public class MergeAction extends RepositoryAction { + + @Override + public void execute(IAction action) { + final Repository repository = getRepository(true); + if (repository == null) + return; + + if (!canMerge(repository)) + return; + + MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog( + getShell(), repository); + if (mergeTargetSelectionDialog.open() == IDialogConstants.OK_ID) { + + final String refName = mergeTargetSelectionDialog.getRefName(); + + String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName); + Job job = new Job(jobname) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + new MergeOperation(repository, refName).execute(monitor); + } catch (final CoreException e) { + getShell().getDisplay().asyncExec(new Runnable(){ + public void run() { + Utils.handleError(getShell(), e, "Merge impossible", "Unsupported Operation"); //$NON-NLS-1$ //$NON-NLS-2$ + }}); + } + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + + } + + } + + private boolean canMerge(final Repository repository) { + String message = null; + try { + Ref head = repository.getRef(Constants.HEAD); + if (head == null || !head.isSymbolic()) + message = UIText.MergeAction_HeadIsNoBranch; + else if (!repository.getRepositoryState().equals( + RepositoryState.SAFE)) + message = NLS.bind( + UIText.MergeAction_WrongRepositoryState, + repository.getRepositoryState()); + } catch (IOException e) { + Activator.logError(e.getMessage(), e); + message = e.getMessage(); + } + + if (message != null) { + MessageDialog.openError(getShell(), + UIText.MergeAction_CannotMerge, message); + } + return (message == null); + } + + @Override + public boolean isEnabled() { + boolean enabled = true; + Repository repository = getRepository(false); + if (repository == null) + enabled = false; + return enabled; + } + +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java index be5955ea94..809e670f13 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java @@ -20,7 +20,7 @@ import org.eclipse.egit.core.op.ResetOperation.ResetType; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator; -import org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog; +import org.eclipse.egit.ui.internal.dialogs.ResetTargetSelectionDialog; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -44,7 +44,7 @@ public class ResetAction extends RepositoryAction { NLS.bind(UIText.ResetAction_repositoryState, repository.getRepositoryState().getDescription())); return; } - BranchSelectionDialog branchSelectionDialog = new BranchSelectionDialog(getShell(), repository, true); + ResetTargetSelectionDialog branchSelectionDialog = new ResetTargetSelectionDialog(getShell(), repository); if (branchSelectionDialog.open() == IDialogConstants.OK_ID) { final String refName = branchSelectionDialog.getRefName(); final ResetType type = branchSelectionDialog.getResetType(); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java index a987115527..032cc3b707 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java @@ -15,18 +15,16 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.eclipse.egit.core.op.ResetOperation.ResetType; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIText; +import org.eclipse.egit.ui.internal.ValidationUtils; import org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider; import org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider; import org.eclipse.egit.ui.internal.repository.RepositoryTreeNode; import org.eclipse.egit.ui.internal.repository.RepositoryTreeNode.RepositoryTreeNodeType; -import org.eclipse.egit.ui.internal.ValidationUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.JFaceResources; @@ -50,13 +48,9 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; /** @@ -67,11 +61,12 @@ public class BranchSelectionDialog extends Dialog { private final Repository repo; - private final boolean showResetType; - private TreeViewer branchTree; - private Button confirmationBtn; + /** + * button which finally triggers the action + */ + protected Button confirmationBtn; private Button renameButton; @@ -79,8 +74,6 @@ public class BranchSelectionDialog extends Dialog { private String selectedBranch; - private ResetType resetType = ResetType.MIXED; - private final RepositoryTreeNode<Repository> localBranches; private final RepositoryTreeNode<Repository> remoteBranches; @@ -91,12 +84,10 @@ public class BranchSelectionDialog extends Dialog { * Construct a dialog to select a branch to reset to or check out * @param parentShell * @param repo - * @param showReset true if the "reset" part should be shown */ - public BranchSelectionDialog(Shell parentShell, Repository repo, boolean showReset) { + public BranchSelectionDialog(Shell parentShell, Repository repo) { super(parentShell); this.repo = repo; - this.showResetType = showReset; localBranches = new RepositoryTreeNode<Repository>(null, RepositoryTreeNodeType.LOCALBRANCHES, this.repo, this.repo); remoteBranches = new RepositoryTreeNode<Repository>(null, @@ -109,7 +100,7 @@ public class BranchSelectionDialog extends Dialog { protected Composite createDialogArea(Composite base) { Composite parent = (Composite) super.createDialogArea(base); parent.setLayout(GridLayoutFactory.swtDefaults().create()); - new Label(parent, SWT.NONE).setText(UIText.BranchSelectionDialog_Refs); + new Label(parent, SWT.NONE).setText(getRefsLabel()); branchTree = new TreeViewer(parent, SWT.SINGLE | SWT.BORDER); new RepositoriesViewLabelProvider(branchTree); @@ -132,16 +123,19 @@ public class BranchSelectionDialog extends Dialog { .startsWith(Constants.R_REMOTES)); // we don't allow reset on tags, but checkout - if (showResetType) + if (!canConfirmOnTag()) confirmationBtn.setEnabled(branchSelected); else confirmationBtn.setEnabled(branchSelected || tagSelected); - if (!showResetType) { - // we don't support rename on tags - renameButton.setEnabled(branchSelected && !tagSelected); + // we don't support rename on tags + if (renameButton != null) { + renameButton.setEnabled(branchSelected && !tagSelected + && !tagSelected); + } - // new branch can not be based on a tag + // new branch can not be based on a tag + if (newButton != null) { newButton.setEnabled(branchSelected && !tagSelected); } } @@ -162,12 +156,10 @@ public class BranchSelectionDialog extends Dialog { } }); - if (showResetType) { - buildResetGroup(parent); - } + createCustomArea(parent); + + String rawTitle = getTitle(); - String rawTitle = showResetType ? UIText.BranchSelectionDialog_TitleReset - : UIText.BranchSelectionDialog_TitleCheckout; getShell().setText( NLS.bind(rawTitle, new Object[] { repo.getDirectory() })); @@ -230,38 +222,6 @@ public class BranchSelectionDialog extends Dialog { return true; } - private void buildResetGroup(Composite parent) { - Group g = new Group(parent, SWT.NONE); - g.setText(UIText.BranchSelectionDialog_ResetType); - g.setLayoutData(GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).create()); - g.setLayout(new RowLayout(SWT.VERTICAL)); - - Button soft = new Button(g, SWT.RADIO); - soft.setText(UIText.BranchSelectionDialog_ResetTypeSoft); - soft.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - resetType = ResetType.SOFT; - } - }); - - Button medium = new Button(g, SWT.RADIO); - medium.setSelection(true); - medium.setText(UIText.BranchSelectionDialog_ResetTypeMixed); - medium.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - resetType = ResetType.MIXED; - } - }); - - Button hard = new Button(g, SWT.RADIO); - hard.setText(UIText.BranchSelectionDialog_ResetTypeHard); - hard.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - resetType = ResetType.HARD; - } - }); - } - /** * @return the selected refName */ @@ -269,26 +229,9 @@ public class BranchSelectionDialog extends Dialog { return this.selectedBranch; } - /** - * @return Type of Reset - */ - public ResetType getResetType() { - return resetType; - } - @Override protected void okPressed() { this.selectedBranch = refNameFromDialog(); - if (showResetType) { - if (resetType == ResetType.HARD) { - if (!MessageDialog.openQuestion(getShell(), - UIText.BranchSelectionDialog_ReallyResetTitle, - UIText.BranchSelectionDialog_ReallyResetMessage)) { - return; - } - } - } - super.okPressed(); } @@ -317,125 +260,153 @@ public class BranchSelectionDialog extends Dialog { @Override protected void createButtonsForButtonBar(Composite parent) { - if (!showResetType) { - newButton = new Button(parent, SWT.PUSH); - newButton.setFont(JFaceResources.getDialogFont()); - newButton.setText(UIText.BranchSelectionDialog_NewBranch); - setButtonLayoutData(newButton); - ((GridLayout)parent.getLayout()).numColumns++; + newButton = new Button(parent, SWT.PUSH); + newButton.setFont(JFaceResources.getDialogFont()); + newButton.setText(UIText.BranchSelectionDialog_NewBranch); + setButtonLayoutData(newButton); + ((GridLayout)parent.getLayout()).numColumns++; - renameButton = new Button(parent, SWT.PUSH); - renameButton.setFont(JFaceResources.getDialogFont()); - renameButton.setText(UIText.BranchSelectionDialog_Rename); - setButtonLayoutData(renameButton); - ((GridLayout)parent.getLayout()).numColumns++; + renameButton = new Button(parent, SWT.PUSH); + renameButton.setFont(JFaceResources.getDialogFont()); + renameButton.setText(UIText.BranchSelectionDialog_Rename); + setButtonLayoutData(renameButton); + ((GridLayout)parent.getLayout()).numColumns++; - renameButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { + renameButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { - String refName = refNameFromDialog(); - String refPrefix; + String refName = refNameFromDialog(); + String refPrefix; + // the button should be disabled anyway, but we check again + if (refName.equals(Constants.HEAD)) + return; + + if (refName.startsWith(Constants.R_HEADS)) + refPrefix = Constants.R_HEADS; + else if (refName.startsWith(Constants.R_REMOTES)) + refPrefix = Constants.R_REMOTES; + else if (refName.startsWith(Constants.R_TAGS)) + refPrefix = Constants.R_TAGS; + else { // the button should be disabled anyway, but we check again - if (refName.equals(Constants.HEAD)) - return; - - if (refName.startsWith(Constants.R_HEADS)) - refPrefix = Constants.R_HEADS; - else if (refName.startsWith(Constants.R_REMOTES)) - refPrefix = Constants.R_REMOTES; - else if (refName.startsWith(Constants.R_TAGS)) - refPrefix = Constants.R_TAGS; - else { - // the button should be disabled anyway, but we check again - return; - } + return; + } - String branchName = refName.substring(refPrefix.length()); - - InputDialog labelDialog = getRefNameInputDialog(NLS - .bind( - UIText.BranchSelectionDialog_QuestionNewBranchNameMessage, - branchName, refPrefix), refPrefix); - if (labelDialog.open() == Window.OK) { - String newRefName = refPrefix + labelDialog.getValue(); - try { - RefRename renameRef = repo.renameRef(refName, newRefName); - if (renameRef.rename() != Result.RENAMED) { - reportError( - null, - UIText.BranchSelectionDialog_ErrorCouldNotRenameRef, - refName, newRefName, renameRef - .getResult()); - } - branchTree.refresh(); - markRef(newRefName); - } catch (Throwable e1) { + String branchName = refName.substring(refPrefix.length()); + + InputDialog labelDialog = getRefNameInputDialog(NLS + .bind( + UIText.BranchSelectionDialog_QuestionNewBranchNameMessage, + branchName, refPrefix), refPrefix); + if (labelDialog.open() == Window.OK) { + String newRefName = refPrefix + labelDialog.getValue(); + try { + RefRename renameRef = repo.renameRef(refName, newRefName); + if (renameRef.rename() != Result.RENAMED) { reportError( - e1, + null, UIText.BranchSelectionDialog_ErrorCouldNotRenameRef, - refName, newRefName, e1.getMessage()); + refName, newRefName, renameRef + .getResult()); } + branchTree.refresh(); + markRef(newRefName); + } catch (Throwable e1) { + reportError( + e1, + UIText.BranchSelectionDialog_ErrorCouldNotRenameRef, + refName, newRefName, e1.getMessage()); } } - }); - newButton.addSelectionListener(new SelectionAdapter() { + } + }); + newButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - // check what ref name the user selected, if any. - String refName = refNameFromDialog(); + public void widgetSelected(SelectionEvent e) { + // check what ref name the user selected, if any. + String refName = refNameFromDialog(); + // the button should be disabled anyway, but we check again + if (refName.equals(Constants.HEAD)) + return; + if (refName.startsWith(Constants.R_TAGS)) // the button should be disabled anyway, but we check again - if (refName.equals(Constants.HEAD)) - return; - if (refName.startsWith(Constants.R_TAGS)) - // the button should be disabled anyway, but we check again - return; - - InputDialog labelDialog = getRefNameInputDialog( - NLS - .bind( - UIText.BranchSelectionDialog_QuestionNewBranchMessage, - refName, Constants.R_HEADS), - Constants.R_HEADS); - - if (labelDialog.open() == Window.OK) { - String newRefName = Constants.R_HEADS + labelDialog.getValue(); - RefUpdate updateRef; - try { - updateRef = repo.updateRef(newRefName); - Ref startRef = repo.getRef(refName); - ObjectId startAt = repo.resolve(refName); - String startBranch; - if (startRef != null) - startBranch = refName; - else - startBranch = startAt.name(); - startBranch = repo.shortenRefName(startBranch); - updateRef.setNewObjectId(startAt); - updateRef.setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$ - updateRef.update(); - branchTree.refresh(); - markRef(newRefName); - } catch (Throwable e1) { - reportError( - e1, - UIText.BranchSelectionDialog_ErrorCouldNotCreateNewRef, - newRefName); - } + return; + + InputDialog labelDialog = getRefNameInputDialog( + NLS + .bind( + UIText.BranchSelectionDialog_QuestionNewBranchMessage, + refName, Constants.R_HEADS), + Constants.R_HEADS); + + if (labelDialog.open() == Window.OK) { + String newRefName = Constants.R_HEADS + labelDialog.getValue(); + RefUpdate updateRef; + try { + updateRef = repo.updateRef(newRefName); + Ref startRef = repo.getRef(refName); + ObjectId startAt = repo.resolve(refName); + String startBranch; + if (startRef != null) + startBranch = refName; + else + startBranch = startAt.name(); + startBranch = repo.shortenRefName(startBranch); + updateRef.setNewObjectId(startAt); + updateRef.setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$ + updateRef.update(); + branchTree.refresh(); + markRef(newRefName); + } catch (Throwable e1) { + reportError( + e1, + UIText.BranchSelectionDialog_ErrorCouldNotCreateNewRef, + newRefName); } } - }); - } + } + }); confirmationBtn = createButton(parent, IDialogConstants.OK_ID, - showResetType ? UIText.BranchSelectionDialog_OkReset - : UIText.BranchSelectionDialog_OkCheckout, true); + UIText.BranchSelectionDialog_OkCheckout, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); // can't advance without a selection confirmationBtn.setEnabled(!branchTree.getSelection().isEmpty()); } + /** + * @return the label shown above the refs tree + */ + protected String getRefsLabel() { + return UIText.BranchSelectionDialog_Refs; + } + + /** + * Subclasses may add UI elements + * @param parent + */ + protected void createCustomArea(Composite parent) { + // do nothing + } + + /** + * Subclasses may change the title of the dialog + * @return the title of the dialog + */ + protected String getTitle() { + return UIText.BranchSelectionDialog_TitleCheckout; + } + + /** + * + * @return if the confirmation button is enabled when a tag is selected + */ + protected boolean canConfirmOnTag() { + return true; + } + @Override protected int getShellStyle() { return super.getShellStyle() | SWT.RESIZE; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java new file mode 100644 index 0000000000..0c9fcd4d94 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2010 SAP AG. + * 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 + * + * Contributors: + * Stefan Lay (SAP AG) - initial implementation + *******************************************************************************/ +package org.eclipse.egit.ui.internal.dialogs; + +import org.eclipse.egit.ui.UIText; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; + +/** + * Dialog for selecting a merge target. + * + */ +public class MergeTargetSelectionDialog extends BranchSelectionDialog { + + /** + * Construct a dialog to select a branch to reset to or check out + * + * @param parentShell + * @param repo + */ + public MergeTargetSelectionDialog(Shell parentShell, Repository repo) { + super(parentShell, repo); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + confirmationBtn = createButton(parent, IDialogConstants.OK_ID, + UIText.MergeTargetSelectionDialog_ButtonMerge, true); + createButton(parent, IDialogConstants.CANCEL_ID, + IDialogConstants.CANCEL_LABEL, false); + } + + @Override + protected String getRefsLabel() { + return UIText.MergeTargetSelectionDialog_SelectRef + + " " + UIText.MergeTargetSelectionDialog_OnlyFastForward; //$NON-NLS-1$ + } + + @Override + protected String getTitle() { + return UIText.MergeTargetSelectionDialog_TitleMerge; + } + +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java new file mode 100644 index 0000000000..f469daeeaa --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2010 SAP AG. + * 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 + * + * Contributors: + * Stefan Lay (SAP AG) - initial implementation + *******************************************************************************/ +package org.eclipse.egit.ui.internal.dialogs; + +import org.eclipse.egit.core.op.ResetOperation.ResetType; +import org.eclipse.egit.ui.UIText; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + +/** + * Dialog for selecting a reset target. + */ +public class ResetTargetSelectionDialog extends BranchSelectionDialog { + + private ResetType resetType = ResetType.MIXED; + + /** + * Construct a dialog to select a branch to reset to + * @param parentShell + * @param repo + */ + public ResetTargetSelectionDialog(Shell parentShell, Repository repo) { + super(parentShell, repo); + } + + @Override + protected void createCustomArea(Composite parent) { + Group g = new Group(parent, SWT.NONE); + g.setText(UIText.BranchSelectionDialog_ResetType); + g.setLayoutData(GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).create()); + g.setLayout(new RowLayout(SWT.VERTICAL)); + + Button soft = new Button(g, SWT.RADIO); + soft.setText(UIText.BranchSelectionDialog_ResetTypeSoft); + soft.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + resetType = ResetType.SOFT; + } + }); + + Button medium = new Button(g, SWT.RADIO); + medium.setSelection(true); + medium.setText(UIText.BranchSelectionDialog_ResetTypeMixed); + medium.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + resetType = ResetType.MIXED; + } + }); + + Button hard = new Button(g, SWT.RADIO); + hard.setText(UIText.BranchSelectionDialog_ResetTypeHard); + hard.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + resetType = ResetType.HARD; + } + }); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + confirmationBtn = createButton(parent, IDialogConstants.OK_ID, + UIText.BranchSelectionDialog_OkReset, true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + + @Override + protected String getTitle() { + return UIText.BranchSelectionDialog_TitleReset; + } + + @Override + protected boolean canConfirmOnTag() { + return false; + } + + /** + * @return Type of Reset + */ + public ResetType getResetType() { + return resetType; + } + + @Override + protected void okPressed() { + if (resetType == ResetType.HARD) { + if (!MessageDialog.openQuestion(getShell(), + UIText.BranchSelectionDialog_ReallyResetTitle, + UIText.BranchSelectionDialog_ReallyResetMessage)) { + return; + } + } + super.okPressed(); + } +}
\ No newline at end of file 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 852500d207..92a05ac153 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 @@ -503,6 +503,19 @@ BranchSelectionDialog_ResetTypeSoft=&Soft (Index and working directory unmodifie BranchSelectionDialog_Refs=Re&fs BranchSelectionDialog_Rename=&Rename +MergeAction_CannotMerge=Cannot merge now +MergeAction_ChangedFiles=There are changed files. Merging is currently not supported in this case. +MergeAction_ErrorMergeEnabling=Error during Action enabling +MergeAction_HeadIsNoBranch=HEAD is not pointing to a branch +MergeAction_JobNameMerge=Merging with {0} +MergeAction_ProblemMerge=Problem during merge +MergeAction_UnableMerge=Unable to merge. +MergeAction_WrongRepositoryState=The Repository State {0} does not allow to merge +MergeTargetSelectionDialog_ButtonMerge=&Merge +MergeTargetSelectionDialog_OnlyFastForward=Only fast-forward merges are currently possible. +MergeTargetSelectionDialog_SelectRef=Select a branch or a tag. +MergeTargetSelectionDialog_TitleMerge=Merge: {0} + DecoratorPreferencesPage_addVariablesTitle=Add Variables DecoratorPreferencesPage_addVariablesAction=Add &Variables... DecoratorPreferencesPage_recomputeAncestorDecorations=Re-decorate &ancestors when decorating changed resources |