diff options
| author | Remy Suen | 2010-04-17 01:11:56 +0000 |
|---|---|---|
| committer | Robin Rosenberg | 2010-04-17 11:29:14 +0000 |
| commit | 12ac70d514fa3282b73a51c31c63e079b0d59edf (patch) | |
| tree | efbf7ed9e4242b4da552347b9e8e59b0e1a8ada7 | |
| parent | d7a82f81e3d6d2a51a89a015cd9dea8137d8db1e (diff) | |
| download | egit-12ac70d514fa3282b73a51c31c63e079b0d59edf.tar.gz egit-12ac70d514fa3282b73a51c31c63e079b0d59edf.tar.xz egit-12ac70d514fa3282b73a51c31c63e079b0d59edf.zip | |
Prevent the user from selecting an invalid branch/reset target.
The branch selection dialog needs to enable/disable its buttons
based on what the user has selected. This will help provide a
better user experience as they will be less likely to get into a
state where an error dialog will popup on them.
Change-Id: Iec736b78204d4201a428bb2608e124d9d9e5cab1
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
3 files changed, 16 insertions, 16 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 432a777d38..cac5ca9e11 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 @@ -1297,9 +1297,6 @@ public class UIText extends NLS { public static String BranchSelectionDialog_LocalBranches; /** */ - public static String BranchSelectionDialog_NoBranchSeletectTitle; - - /** */ public static String BranchSelectionDialog_ReallyResetTitle; /** */ @@ -1336,9 +1333,6 @@ public class UIText extends NLS { public static String BranchSelectionDialog_OkCheckout; /** */ - public static String BranchSelectionDialog_NoBranchSeletectMessage; - - /** */ public static String BranchSelectionDialog_Refs; /** */ 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 b841b91cb2..802922c382 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 @@ -32,6 +32,7 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Font; @@ -86,6 +87,8 @@ public class BranchSelectionDialog extends Dialog { private Tree branchTree; + private Button confirmationBtn; + @Override protected Composite createDialogArea(Composite base) { parent = (Composite) super.createDialogArea(base); @@ -93,6 +96,15 @@ public class BranchSelectionDialog extends Dialog { new Label(parent, SWT.NONE).setText(UIText.BranchSelectionDialog_Refs); branchTree = new Tree(parent, SWT.BORDER); branchTree.setLayoutData(GridDataFactory.fillDefaults().grab(true,true).hint(500, 300).create()); + branchTree.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // calculate the user's selected ref + refNameFromDialog(); + // make sure it's a valid selection + confirmationBtn.setEnabled(refName != null); + } + }); if (showResetType) { buildResetGroup(); @@ -252,13 +264,6 @@ public class BranchSelectionDialog extends Dialog { @Override protected void okPressed() { refNameFromDialog(); - if (refName == null) { - MessageDialog.openWarning(getShell(), - UIText.BranchSelectionDialog_NoBranchSeletectTitle, - UIText.BranchSelectionDialog_NoBranchSeletectMessage); - return; - } - if (showResetType) { if (resetType == ResetType.HARD) { if (!MessageDialog.openQuestion(getShell(), @@ -414,10 +419,13 @@ public class BranchSelectionDialog extends Dialog { } }); } - createButton(parent, IDialogConstants.OK_ID, + confirmationBtn = createButton(parent, IDialogConstants.OK_ID, showResetType ? UIText.BranchSelectionDialog_OkReset : UIText.BranchSelectionDialog_OkCheckout, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + + // can't advance without a selection + confirmationBtn.setEnabled(branchTree.getSelectionCount() != 0); } @Override 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 732e609d25..1f48441561 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 @@ -467,8 +467,6 @@ BranchSelectionDialog_ErrorRenameFailed=Rename failed BranchSelectionDialog_LocalBranches=Local Branches BranchSelectionDialog_NewBranch=&New branch -BranchSelectionDialog_NoBranchSeletectMessage=You must select a valid ref. -BranchSelectionDialog_NoBranchSeletectTitle=No branch/tag selected BranchSelectionDialog_OkCheckout=&Checkout BranchSelectionDialog_OkReset=&Reset BranchSelectionDialog_QuestionNewBranchMessage=Enter name of new branch. It will branch from the selected branch. refs/heads/ will be prepended to the name you type |
