diff options
| author | Robin Stocker | 2011-12-02 16:37:37 +0000 |
|---|---|---|
| committer | Robin Stocker | 2011-12-02 16:37:37 +0000 |
| commit | 7ecf0866a5b4157070364a359fb7aefd9dc541f7 (patch) | |
| tree | 9a249247d6092a360fae760fea3a9fb0e08161f1 | |
| parent | 733368509e0e5112408ecdff8378b6bac897d24f (diff) | |
| download | egit-7ecf0866a5b4157070364a359fb7aefd9dc541f7.tar.gz egit-7ecf0866a5b4157070364a359fb7aefd9dc541f7.tar.xz egit-7ecf0866a5b4157070364a359fb7aefd9dc541f7.zip | |
Suggest name when source ref is selected in new branch dialog
When using Team > Switch To > New Branch..., the user can select a
remote-tracking branch to create a local branch based on it. Before this
change, the user had to manually enter the name of the branch (which is
error-prone). With this change, the name is automatically suggested
based on the remote name.
So when "refs/remotes/origin/stable-1.0" is selected, we pre-fill the
text with a suggestion of "stable-1.0", which is usually what is wanted
anyway.
We keep updating the suggested branch name in case the user chooses a
different source ref, but stop doing that when the name is changed
manually.
Change-Id: I061d33dad289d93d6be41e1e902ed373168b1e2c
Signed-off-by: Robin Stocker <robin@nibor.org>
| -rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java | 34 |
1 files changed, 25 insertions, 9 deletions
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 3a05cea40b..afb4728285 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 @@ -101,6 +101,11 @@ class CreateBranchPage extends WizardPage { private Text nameText; + /** + * Whether the contents of {@code nameText} is a suggestion or was entered by the user. + */ + private boolean nameIsSuggestion; + private Button checkout; private Combo branchCombo; @@ -213,8 +218,9 @@ class CreateBranchPage extends WizardPage { this.branchCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - upstreamConfig = getDefaultUpstreamConfig(myRepository, - branchCombo.getText()); + String ref = branchCombo.getText(); + suggestBranchName(ref); + upstreamConfig = getDefaultUpstreamConfig(myRepository, ref); checkPage(); } }); @@ -238,6 +244,11 @@ class CreateBranchPage extends WizardPage { nameText.setFocus(); } }); + nameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + nameIsSuggestion = false; + } + }); // enable testing with SWTBot nameText.setData("org.eclipse.swtbot.widget.key", "BranchName"); //$NON-NLS-1$ //$NON-NLS-2$ GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText); @@ -322,13 +333,7 @@ class CreateBranchPage extends WizardPage { Dialog.applyDialogFont(main); setControl(main); nameText.setFocus(); - String targetName = getProposedTargetName(myBaseRef); - if (targetName != null) { - nameText.setText(targetName); - nameText.selectAll(); - } else - // in any case, we will have to enter the name - setPageComplete(false); + suggestBranchName(myBaseRef); checkPage(); // add the listener just now to avoid unneeded checkPage() nameText.addModifyListener(new ModifyListener() { @@ -453,4 +458,15 @@ class CreateBranchPage extends WizardPage { return UpstreamConfig.REBASE; return UpstreamConfig.MERGE; } + + private void suggestBranchName(String ref) { + if (nameText.getText().length() == 0 || nameIsSuggestion) { + String branchNameSuggestion = getProposedTargetName(ref); + if (branchNameSuggestion != null) { + nameText.setText(branchNameSuggestion); + nameText.selectAll(); + nameIsSuggestion = true; + } + } + } } |
