From 1a79075decfcd6c6a0658eac4ed56f312472d7f6 Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Tue, 18 May 2010 08:31:00 +0200 Subject: [PATCH] Git Repositories View: fix Branch Creation page Only local branches can be created directly. This fix adjusts the BranchCreation page accordingly which wrongly suggest to the end user they can create remote branches. Change-Id: I7cfc69d9fbae9299c7c2f5f3e86f4ae587503340 Signed-off-by: Mathias Kinzler Signed-off-by: Matthias Sohn --- .../src/org/eclipse/egit/ui/UIText.java | 25 ++------- .../ui/internal/repository/CreateBranchPage.java | 64 ++++++++-------------- .../ui/internal/repository/RepositoriesView.java | 29 +++------- .../src/org/eclipse/egit/ui/uitext.properties | 10 +--- 4 files changed, 37 insertions(+), 91 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 be7917c4..0be04401 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 @@ -1150,9 +1150,6 @@ public class UIText extends NLS { public static String CreateBranchPage_BranchNameLabel; /** */ - public static String CreateBranchPage_BranchNameTooltip; - - /** */ public static String CreateBranchPage_CheckingOutMessage; /** */ @@ -1165,18 +1162,6 @@ public class UIText extends NLS { public static String CreateBranchPage_ChosseNameMessage; /** */ - public static String CreateBranchPage_CreateLocalBasedTitle; - - /** */ - public static String CreateBranchPage_CreateLocalTitle; - - /** */ - public static String CreateBranchPage_CreateRemoteBaseOnTitle; - - /** */ - public static String CreateBranchPage_CreateRemoteTitle; - - /** */ public static String CreateBranchPage_CreatingBranchMessage; /** */ @@ -1192,6 +1177,9 @@ public class UIText extends NLS { public static String CreateBranchPage_SourceBranchTooltip; /** */ + public static String CreateBranchPage_Title; + + /** */ public static String PushResultTable_columnStatusRepo; /** */ @@ -1702,13 +1690,10 @@ public class UIText extends NLS { public static String RepositoriesView_LinkWithSelection_action; /** */ - public static String RepositoriesView_NewBranchTitle; - - /** */ - public static String RepositoriesView_NewLocalBranchMenu; + public static String RepositoriesView_NewBranchMenu; /** */ - public static String RepositoriesView_NewRemoteBranchMenu; + public static String RepositoriesView_NewBranchTitle; /** */ public static String RepositoriesView_NewRemoteMenu; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java index d932e6fa..6c0975b0 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java @@ -38,8 +38,8 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** - * Allows to create a branch based on another branch or with a selection of - * another branch + * Allows to create a new local branch based on another branch. The source + * branch can be selected using a drop down. */ public class CreateBranchPage extends WizardPage { @@ -47,8 +47,6 @@ public class CreateBranchPage extends WizardPage { private final Ref myBaseBranch; - private final boolean remoteMode; - private Text nameText; private Button checkout; @@ -56,45 +54,32 @@ public class CreateBranchPage extends WizardPage { private Combo branchCombo; /** - * Create a branch + * Constructs this page. + *

+ * If a base branch is provided, the drop down will be selected accordingly * * @param repo * the repository * @param baseBranch * the branch to base the new branch on, may be null - * @param remote - * true if remote branch is to be created */ - public CreateBranchPage(Repository repo, Ref baseBranch, boolean remote) { + public CreateBranchPage(Repository repo, Ref baseBranch) { super(CreateBranchPage.class.getName()); this.myRepository = repo; this.myBaseBranch = baseBranch; - this.remoteMode = remote; - if (this.remoteMode) - if (baseBranch != null) - setTitle(NLS.bind( - UIText.CreateBranchPage_CreateRemoteBaseOnTitle, - myBaseBranch.getName())); - else - setTitle(UIText.CreateBranchPage_CreateRemoteTitle); - else if (baseBranch != null) - setTitle(NLS.bind(UIText.CreateBranchPage_CreateLocalBasedTitle, - myBaseBranch.getName())); - else - setTitle(UIText.CreateBranchPage_CreateLocalTitle); + setTitle(UIText.CreateBranchPage_Title); } public void createControl(Composite parent) { - Composite main = new Composite(parent, SWT.NONE); - main.setLayout(new GridLayout(2, false)); + main.setLayout(new GridLayout(3, false)); Label sourceLabel = new Label(main, SWT.NONE); sourceLabel.setText(UIText.CreateBranchPage_SourceBranchLabel); sourceLabel.setToolTipText(UIText.CreateBranchPage_SourceBranchTooltip); this.branchCombo = new Combo(main, SWT.READ_ONLY | SWT.DROP_DOWN); - GridDataFactory.fillDefaults().grab(true, false).applyTo( + GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo( this.branchCombo); try { @@ -114,17 +99,19 @@ public class CreateBranchPage extends WizardPage { } this.branchCombo.addSelectionListener(new SelectionAdapter() { - @Override public void widgetSelected(SelectionEvent e) { checkPage(); } - }); + // select the current branch in the drop down if (myBaseBranch != null) { this.branchCombo.setText(myBaseBranch.getName()); - this.branchCombo.setEnabled(false); } else { + // TODO this only works for local branches; once we have a solution + // for accessing the correct information (we need this for the + // project label decoration, too), we should figure out if a remote + // branch is checked-out and set the text accordingly String fullBranch; try { fullBranch = myRepository.getFullBranch(); @@ -136,19 +123,16 @@ public class CreateBranchPage extends WizardPage { Label nameLabel = new Label(main, SWT.NONE); nameLabel.setText(UIText.CreateBranchPage_BranchNameLabel); - if (remoteMode) - nameLabel.setToolTipText(NLS.bind( - UIText.CreateBranchPage_BranchNameTooltip, - Constants.R_REMOTES)); - else - nameLabel.setToolTipText(NLS.bind( - UIText.CreateBranchPage_BranchNameTooltip, - Constants.R_HEADS)); + + // we visualize the prefix here + Text prefix = new Text(main, SWT.NONE); + prefix.setText(Constants.R_HEADS); + prefix.setEnabled(false); nameText = new Text(main, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText); - nameText.addModifyListener(new ModifyListener() { + nameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { checkPage(); } @@ -164,7 +148,7 @@ public class CreateBranchPage extends WizardPage { checkout.setSelection(!isBare); checkout.setEnabled(!isBare); checkout.setVisible(!isBare); - GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo( + GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo( checkout); checkout.addSelectionListener(new SelectionAdapter() { @@ -216,10 +200,7 @@ public class CreateBranchPage extends WizardPage { } private String getBranchName() { - if (remoteMode) - return Constants.R_REMOTES + nameText.getText(); - else - return Constants.R_HEADS + nameText.getText(); + return Constants.R_HEADS + nameText.getText(); } private String getSourceBranchName() { @@ -238,7 +219,6 @@ public class CreateBranchPage extends WizardPage { */ public void createBranch(IProgressMonitor monitor) throws CoreException, IOException { - String newRefName = getBranchName(); RefUpdate updateRef; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java index 8133d829..1a1be450 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java @@ -547,11 +547,12 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, checkoutBranch(node, ref.getLeaf().getName()); } }); - } - if (node.getType() == RepositoryTreeNodeType.LOCALBRANCHES - || node.getType() == RepositoryTreeNodeType.REMOTEBRANCHES) + if (node.getType() == RepositoryTreeNodeType.BRANCHES + || node.getType() == RepositoryTreeNodeType.LOCALBRANCHES) + // offering this on the "Remote Branches" node would probably be + // confusing createCreateBranchItem(men, node); // for Repository: import existing projects, remove, (delete), open @@ -1025,26 +1026,14 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, } private void createCreateBranchItem(Menu men, final RepositoryTreeNode node) { - - final boolean remoteMode; final Ref ref; - if (node.getType() == RepositoryTreeNodeType.REF) { - remoteMode = node.getParent().getType() == RepositoryTreeNodeType.REMOTEBRANCHES; + if (node.getType() == RepositoryTreeNodeType.REF) ref = (Ref) node.getObject(); - } else if (node.getType() == RepositoryTreeNodeType.LOCALBRANCHES) { - remoteMode = false; - ref = null; - } else if (node.getType() == RepositoryTreeNodeType.REMOTEBRANCHES) { - remoteMode = true; + else ref = null; - } else - return; MenuItem createLocal = new MenuItem(men, SWT.PUSH); - if (remoteMode) - createLocal.setText(UIText.RepositoriesView_NewRemoteBranchMenu); - else - createLocal.setText(UIText.RepositoriesView_NewLocalBranchMenu); + createLocal.setText(UIText.RepositoriesView_NewBranchMenu); createLocal.addSelectionListener(new SelectionAdapter() { @@ -1055,8 +1044,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, @Override public void addPages() { - addPage(new CreateBranchPage(node.getRepository(), ref, - remoteMode)); + addPage(new CreateBranchPage(node.getRepository(), ref)); setWindowTitle(UIText.RepositoriesView_NewBranchTitle); } @@ -1100,7 +1088,6 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, } }); - } private void createDeleteBranchItem(Menu men, final RepositoryTreeNode node) { 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 12ed2fc0..3cd5337a 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 @@ -413,21 +413,16 @@ ConfirmationPage_showOnlyIfChanged=Show final report dialog only when it differs ConfirmationPage_title=Push Confirmation CreateBranchPage_BranchAlreadyExistsMessage=Branch {0} already exists CreateBranchPage_BranchNameLabel=Branch name -CreateBranchPage_BranchNameTooltip=The name will be prepended with {0} CreateBranchPage_CheckingOutMessage=Checking out new branch... CreateBranchPage_CheckoutButton=Checkout new branch CreateBranchPage_ChooseBranchAndNameMessage=Please choose a source branch and a name for the new branch CreateBranchPage_ChosseNameMessage=Please choose a name for the new branch -CreateBranchPage_CreateLocalBasedTitle=Create a local branch based on {0} -CreateBranchPage_CreateLocalTitle=Create a local branch -CreateBranchPage_CreateRemoteBaseOnTitle=Create a remote branch based on {0} -CreateBranchPage_CreateRemoteTitle=Create a remote branch CreateBranchPage_CreatingBranchMessage=Creating branch... CreateBranchPage_MissingNameMessage=Please enter a name for the new branch CreateBranchPage_MissingSourceMessage=Please select a source branch CreateBranchPage_SourceBranchLabel=Source branch CreateBranchPage_SourceBranchTooltip=The new branch will be created from this branch - +CreateBranchPage_Title=Create a new branch PushResultTable_columnStatusRepo=Status: Repo #{0} PushResultTable_columnDst=Destination Ref PushResultTable_columnSrc=Source Ref @@ -611,9 +606,8 @@ RepositoriesView_ImportProject_MenuItem=Import RepositoriesView_ImportProjectsMenu=Import projects... RepositoriesView_ImportRepository_MenuItem=Import Git Repository... RepositoriesView_LinkWithSelection_action=Link with selection +RepositoriesView_NewBranchMenu=Create a new local branch... RepositoriesView_NewBranchTitle=Create Branch -RepositoriesView_NewLocalBranchMenu=Create a new local branch... -RepositoriesView_NewRemoteBranchMenu=Create a new remote branch... RepositoriesView_NewRemoteMenu=New remote... RepositoriesView_NothingToPasteMessage=Clipboard contains no data to paste RepositoriesView_OpenInTextEditor_menu=Open in text editor -- 2.11.4.GIT