All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tor Arne Vestbø" <torarnv@gmail.com>
To: "Shawn O. Pearce" <spearce@spearce.org>,
	Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [EGIT PATCH v2 07/12] Add binding for name of the current branch
Date: Wed, 11 Feb 2009 19:40:09 +0100	[thread overview]
Message-ID: <1234377614-23798-8-git-send-email-torarnv@gmail.com> (raw)
In-Reply-To: <1234377614-23798-7-git-send-email-torarnv@gmail.com>

This is an example of how to add more bindings to the
decoration preferences, and how they are implemented in
the decorator.

Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
---
 .../src/org/spearce/egit/ui/UIText.java            |    3 ++
 .../decorators/GitLightweightDecorator.java        |   26 ++++++++++++++++---
 .../internal/decorators/IDecoratableResource.java  |    8 ++++++
 .../preferences/GitDecoratorPreferencePage.java    |   21 +++++++++++----
 .../src/org/spearce/egit/ui/uitext.properties      |    3 +-
 5 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java
index a7ef408..345c66b 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java
@@ -971,6 +971,9 @@
 	public static String DecoratorPreferencesPage_nameResourceVariable;
 
 	/** */
+	public static String DecoratorPreferencesPage_bindingBranchName;
+
+	/** */
 	public static String DecoratorPreferencesPage_selectFormats;
 
 	/** */
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java
index 85b9173..265d5a3 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java
@@ -13,6 +13,7 @@
 
 package org.spearce.egit.ui.internal.decorators;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -44,6 +45,7 @@
 import org.eclipse.team.ui.TeamUI;
 import org.eclipse.ui.IContributorResourceAdapter;
 import org.eclipse.ui.PlatformUI;
+import org.spearce.egit.core.GitException;
 import org.spearce.egit.core.internal.util.ExceptionCollector;
 import org.spearce.egit.core.project.GitProjectData;
 import org.spearce.egit.core.project.RepositoryChangeListener;
@@ -157,17 +159,26 @@ public void decorate(Object element, IDecoration decoration) {
 		if (activator == null)
 			return;
 
-		DecorationHelper helper = new DecorationHelper(activator
-				.getPreferenceStore());
-		helper.decorate(decoration, new DecoratableResourceAdapter(resource));
+		try {
+			DecorationHelper helper = new DecorationHelper(activator
+					.getPreferenceStore());
+			helper.decorate(decoration,
+					new DecoratableResourceAdapter(resource));
+		} catch (IOException e) {
+			handleException(resource, GitException.wrapException(e));
+		}
 	}
 
 	private class DecoratableResourceAdapter implements IDecoratableResource {
 
 		private IResource resource;
+		private String branch;
 
-		public DecoratableResourceAdapter(IResource resourceToWrap) {
+		public DecoratableResourceAdapter(IResource resourceToWrap) throws IOException {
 			resource = resourceToWrap;
+			RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
+			Repository repository = mapping.getRepository();
+			branch = repository.getBranch();
 		}
 
 		public String getName() {
@@ -177,6 +188,10 @@ public String getName() {
 		public int getType() {
 			return resource.getType();
 		}
+
+		public String getBranch() {
+			return branch;
+		}
 	}
 
 	/**
@@ -192,6 +207,8 @@ public int getType() {
 
 		/** */
 		public static final String BINDING_RESOURCE_NAME = "name"; //$NON-NLS-1$
+		/** */
+		public static final String BINDING_BRANCH_NAME = "branch"; //$NON-NLS-1$
 
 		/**
 		 * Constructs a decorator using the rules from the given
@@ -234,6 +251,7 @@ public void decorate(IDecoration decoration,
 
 			Map<String, String> bindings = new HashMap<String, String>();
 			bindings.put(BINDING_RESOURCE_NAME, resource.getName());
+			bindings.put(BINDING_BRANCH_NAME, resource.getBranch());
 
 			decorate(decoration, format, bindings);
 		}
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java
index 8d6c741..6b36e0e 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java
@@ -28,4 +28,12 @@
 	 * @return the name of the resource
 	 */
 	String getName();
+
+	/**
+	 * Gets the current branch of the resource if applicable
+	 * 
+	 * @return the name of the current branch, or <code>null</code> if not
+	 *         applicable
+	 */
+	String getBranch();
 }
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
index 84203b7..b7d737c 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
@@ -93,10 +93,10 @@
 
 	static {
 		final PreviewResource project = new PreviewResource(
-				"Project", IResource.PROJECT); //$NON-NLS-1$1
+				"Project", IResource.PROJECT, "master"); //$NON-NLS-1$1
 		final ArrayList<PreviewResource> children = new ArrayList<PreviewResource>();
-		children.add(new PreviewResource("folder", IResource.FOLDER)); //$NON-NLS-1$
-		children.add(new PreviewResource("file.txt", IResource.FILE)); //$NON-NLS-1$
+		children.add(new PreviewResource("folder", IResource.FOLDER, null)); //$NON-NLS-1$
+		children.add(new PreviewResource("file.txt", IResource.FILE, null)); //$NON-NLS-1$
 		project.children = children;
 		PREVIEW_FILESYSTEM_ROOT = Collections.singleton(project);
 	}
@@ -456,6 +456,8 @@ private Map getProjectBindingDescriptions() {
 		Map<String, String> bindings = new HashMap<String, String>();
 		bindings.put(DecorationHelper.BINDING_RESOURCE_NAME,
 				UIText.DecoratorPreferencesPage_nameResourceVariable);
+		bindings.put(DecorationHelper.BINDING_BRANCH_NAME,
+				UIText.DecoratorPreferencesPage_bindingBranchName);
 		return bindings;
 	}
 
@@ -478,8 +480,8 @@ private void updatePreview() {
 		private DecorationHelper fHelper;
 
 		public Preview(Composite composite) {
-			reloadDecorationHelper(); // Has to happen before the tree control
-										// is constructed
+			// Has to happen before the tree control is constructed
+			reloadDecorationHelper();
 			SWTUtils.createLabel(composite,
 					UIText.DecoratorPreferencesPage_preview);
 			fImageCache = new LocalResourceManager(JFaceResources
@@ -602,12 +604,15 @@ private PreviewDecoration getDecoration(Object element) {
 	private static class PreviewResource implements IDecoratableResource {
 		public final String name;
 
+		public final String branch;
+
 		public final int type;
 
 		public Collection children;
 
-		public PreviewResource(String name, int type) {
+		public PreviewResource(String name, int type, String branch) {
 			this.name = name;
+			this.branch = branch;
 			this.type = type;
 			this.children = Collections.EMPTY_LIST;
 		}
@@ -619,6 +624,10 @@ public String getName() {
 		public int getType() {
 			return type;
 		}
+
+		public String getBranch() {
+			return branch;
+		}
 	}
 
 	private class PreviewDecoration implements IDecoration {
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties
index 4660983..d050be9 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties
@@ -360,10 +360,11 @@ DecoratorPreferencesPage_folderFormatLabel=F&olders:
 DecoratorPreferencesPage_projectFormatLabel=&Projects:
 DecoratorPreferencesPage_fileFormatDefault={name}
 DecoratorPreferencesPage_folderFormatDefault={name}
-DecoratorPreferencesPage_projectFormatDefault={name}
+DecoratorPreferencesPage_projectFormatDefault={name} [{branch}]
 DecoratorPreferencesPage_labelDecorationsLink=See <a>''{0}''</a> to enable or disable Git decorations.
 DecoratorPreferencesPage_generalTabFolder=&General
 DecoratorPreferencesPage_nameResourceVariable=name of the resource being decorated
+DecoratorPreferencesPage_bindingBranchName=current branch of the project
 DecoratorPreferencesPage_selectFormats=Select the format for file, folders, and project text labels:
 DecoratorPreferencesPage_selectVariablesToAdd=Select the &variables to add to the decoration format:
 DecoratorPreferencesPage_textLabel=T&ext Decorations
-- 
1.6.1.2.309.g2ea3

  reply	other threads:[~2009-02-11 18:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-11 18:40 [EGIT PATCH v2 00/12] Support customizable label decorations Tor Arne Vestbø
2009-02-11 18:40 ` [EGIT PATCH v2 01/12] Add support code to handle plugin property changes Tor Arne Vestbø
2009-02-11 18:40   ` [EGIT PATCH v2 02/12] Use Set instead of array to keep track of change listeners Tor Arne Vestbø
2009-02-11 18:40     ` [EGIT PATCH v2 03/12] Add a specialized team exception for Git Tor Arne Vestbø
2009-02-11 18:40       ` [EGIT PATCH v2 04/12] Add new class ExceptionCollector for grouping exceptions Tor Arne Vestbø
2009-02-11 18:40         ` [EGIT PATCH v2 05/12] Add new class SWTUtils with helper-methods for creating controls Tor Arne Vestbø
2009-02-11 18:40           ` [EGIT PATCH v2 06/12] Implement basic customizable label decorations with preferences Tor Arne Vestbø
2009-02-11 18:40             ` Tor Arne Vestbø [this message]
2009-02-11 18:40               ` [EGIT PATCH v2 08/12] Add icon decoration for tracked and untracked resources Tor Arne Vestbø
2009-02-11 18:40                 ` [EGIT PATCH v2 09/12] Implement icon and text decorations of various resource states Tor Arne Vestbø
2009-02-11 18:40                   ` [EGIT PATCH v2 10/12] Don't decorate every single resource on repository change Tor Arne Vestbø
2009-02-11 18:40                     ` [EGIT PATCH v2 11/12] Expose the underlying resource entries in ContainerTreeIterator Tor Arne Vestbø
2009-02-11 18:40                       ` [EGIT PATCH v2 12/12] Implement label decorations for folders and projects Tor Arne Vestbø
2009-02-12  0:02                         ` Robin Rosenberg
2009-02-11 22:16                 ` [EGIT PATCH v2 08/12] Add icon decoration for tracked and untracked resources Robin Rosenberg
2009-02-11 22:46                   ` [EGIT PATCH 08/12 v3] " Tor Arne Vestbø
2009-02-16 20:57 ` [EGIT PATCH v2 00/12] Support customizable label decorations Robin Rosenberg
2009-02-16 22:49   ` Tor Arne Vestbø
2009-02-17  5:52     ` Robin Rosenberg
2009-02-17 17:51       ` [EGIT PATCH 13/12] Add new file tree iterator that can adapt into a ContainerTreeIterator Tor Arne Vestbø
2009-02-17 17:52         ` [EGIT PATCH 14/12] Allow project decorations regardless of repository root location Tor Arne Vestbø

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=1234377614-23798-8-git-send-email-torarnv@gmail.com \
    --to=torarnv@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.