From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 3/3] Tell the branch dialog how to create a new branch.
Date: Wed, 24 Sep 2008 23:56:23 +0200 [thread overview]
Message-ID: <1222293383-26016-3-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1222293383-26016-2-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../ui/internal/dialogs/BranchSelectionDialog.java | 98 ++++++++++++++++++--
1 files changed, 88 insertions(+), 10 deletions(-)
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java
index 158738c..26d423a 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java
@@ -17,14 +17,21 @@
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+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;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
@@ -35,6 +42,10 @@
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.spearce.egit.core.op.ResetOperation.ResetType;
+import org.spearce.egit.ui.Activator;
+import org.spearce.jgit.lib.Constants;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.RefUpdate;
import org.spearce.jgit.lib.Repository;
/**
@@ -81,9 +92,9 @@ protected Composite createDialogArea(Composite base) {
}
try {
- fillTreeWithBranches();
+ fillTreeWithBranches(null);
} catch (IOException e) {
- e.printStackTrace();
+ Activator.logError("Could not refresh list of branches", e);
}
return parent;
@@ -121,7 +132,7 @@ public void handleEvent(Event event) {
});
}
- private void fillTreeWithBranches() throws IOException {
+ private void fillTreeWithBranches(String select) throws IOException {
String branch = repo.getFullBranch();
List<String> branches = new ArrayList<String>(repo.getAllRefs()
.keySet());
@@ -197,6 +208,8 @@ public void widgetDisposed(DisposeEvent e) {
branchTree.showItem(item);
}
else item.setText(shortName);
+ if (ref.equals(select))
+ branchTree.select(item);
}
}
@@ -220,12 +233,7 @@ public ResetType getResetType() {
@Override
protected void okPressed() {
- TreeItem[] selection = branchTree.getSelection();
- refName = null;
- if (selection != null && selection.length > 0) {
- TreeItem item = selection[0];
- refName = (String) item.getData();
- }
+ refNameFromDialog();
if (refName == null) {
MessageDialog.openWarning(getShell(), "No branch/tag selected", "You must select a valid ref.");
return;
@@ -244,9 +252,79 @@ protected void okPressed() {
super.okPressed();
}
+ private void refNameFromDialog() {
+ TreeItem[] selection = branchTree.getSelection();
+ refName = null;
+ if (selection != null && selection.length > 0) {
+ TreeItem item = selection[0];
+ refName = (String) item.getData();
+ }
+ }
+
@Override
protected void createButtonsForButtonBar(Composite parent) {
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ if (!showResetType) {
+ Button newButton = new Button(parent, SWT.PUSH);
+ newButton.setFont(JFaceResources.getDialogFont());
+ newButton.setText("New branch");
+ ((GridLayout)parent.getLayout()).numColumns++;
+ newButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ // check what ref name the user selected, if any.
+ refNameFromDialog();
+
+ InputDialog labelDialog = new InputDialog(
+ getShell(),
+ "New branch",
+ "Enter name of new branch. It will branch from the selected branch. refs/heads/ will be prepended to the name you type",
+ null, new IInputValidator() {
+ public String isValid(String newText) {
+ String testFor = Constants.R_HEADS + newText;
+ try {
+ if (repo.resolve(testFor) != null)
+ return "Already exists";
+ } catch (IOException e1) {
+ Activator.logError(String.format(
+ "Could not attempt to resolve %s", testFor), e1);
+ }
+ if (!Repository.isValidRefName(testFor))
+ return "Invalid ref name";
+ return null;
+ }
+ });
+ labelDialog.setBlockOnOpen(true);
+ if (labelDialog.open() == Window.OK) {
+ String newRefName = Constants.R_HEADS + labelDialog.getValue();
+ RefUpdate updateRef;
+ try {
+ updateRef = repo.updateRef(newRefName);
+ ObjectId startAt;
+ if (refName == null)
+ startAt = repo.resolve(Constants.HEAD);
+ else
+ startAt = repo.resolve(refName);
+ updateRef.setNewObjectId(startAt);
+ updateRef.update();
+ } catch (IOException e1) {
+ Activator.logError(String.format(
+ "Could not create new ref %s", newRefName), e1);
+ }
+ try {
+ branchTree.removeAll();
+ fillTreeWithBranches(newRefName);
+ } catch (IOException e1) {
+ Activator.logError("Could not refresh list of branches",e1);
+ }
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+ }
+ createButton(parent, IDialogConstants.OK_ID, showResetType ? "Reset" : "Checkout", true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
--
1.6.0.1.310.gf789d0.dirty
prev parent reply other threads:[~2008-09-24 21:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-24 21:56 [EGIT PATCH 1/3] Include a print command line usage string utility Robin Rosenberg
2008-09-24 21:56 ` [EGIT PATCH 2/3] Add create support to the branch command Robin Rosenberg
2008-09-24 21:56 ` Robin Rosenberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1222293383-26016-3-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).