Skip to content
Browse files

Add binding for name of the current branch

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>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
  • Loading branch information...
1 parent 6e2161e commit 58a6ba8aed8fc7e6200e4b230e8a766baf86ccd4 @torarnv torarnv committed with robinrosenberg Feb 11, 2009
View
3 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;
/** */
View
26 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);
}
View
8 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();
}
View
21 ...arce.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 {
View
3 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

0 comments on commit 58a6ba8

Please sign in to comment.
Something went wrong with that request. Please try again.