aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2009-12-21 09:36:18 (EST)
committerMatthias Sohn2010-02-01 17:00:15 (EST)
commit617a563f9f1c264b123f8c1d01d7518d1f946799 (patch)
tree76fc567d8e6e72aa8abf848ab4a7d1e32ccc25d0
parent8482faf44b571d44bafb314419d127f46a5d2257 (diff)
downloadegit-617a563f9f1c264b123f8c1d01d7518d1f946799.zip
egit-617a563f9f1c264b123f8c1d01d7518d1f946799.tar.gz
egit-617a563f9f1c264b123f8c1d01d7518d1f946799.tar.bz2
Font and color decoration.refs/changes/60/160/3
Implemented font and colour decoration. The same font and colour is used for all uncommitted changes, i.e. resources that have differencies from their corresponding index files and resources that are not tracked by git (and are not ignored). Most of the plumbing code was shamelessly copied from CVSLightweightDecorator. Change-Id: I2089e9fcc557aa50553d4b4458234e56531fea1f Signed-off-by: Igor Fedorenko <igor@ifedorenko.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/plugin.properties6
-rw-r--r--org.eclipse.egit.ui/plugin.xml28
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java83
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java33
5 files changed, 142 insertions, 14 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index ffca568..3b22da0 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -78,6 +78,12 @@ Theme_CommitGraphHighlightFont_label=Commit graph highlight font
Theme_CommitGraphHighlightFont_description=This font is used to highlight matching commits in the revision history.
Theme_CommitMessageFont_label=Commit message font
Theme_CommitMessageFont_description=This font is used to show a commit message.
+Theme_UncommittedChangeForegroundColor_label=Uncommitted Change (Foreground)
+Theme_UncommittedChangeForegroundColor_description=This color is used for the foreground color for resources that have outgoing changes.
+Theme_UncommittedChangeBackgroundColor_label=Uncommitted Change (Background)
+Theme_UncommittedChangeBackgroundColor_description=This color is used for the background color for resources that have outgoing changes.
+Theme_UncommittedChangeFont_label=Uncommitted Change Font
+Theme_UncommittedChangeFont_description=The font used to display outgoing changes.
GitPreferences_name=Git
GitPreferences_HistoryPreferencePage_name=History
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 4f48e1c..2c1cbbe 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -200,7 +200,7 @@
</adapter>
</factory>
</extension>
-
+
<extension point="org.eclipse.ui.preferencePages">
<page name="%GitPreferences_name"
category="org.eclipse.team.ui.TeamPreferences"
@@ -305,6 +305,32 @@
%Theme_CommitMessageFont_description
</description>
</fontDefinition>
+ <colorDefinition
+ id="org.eclipse.egit.ui.UncommittedChangeForegroundColor"
+ categoryId="org.eclipse.egit.ui.GitTheme"
+ label="%Theme_UncommittedChangeForegroundColor_label"
+ value="COLOR_LIST_FOREGROUND">
+ <description>
+ %Theme_UncommittedChangeForegroundColor_description
+ </description>
+ </colorDefinition>
+ <colorDefinition
+ id="org.eclipse.egit.ui.UncommittedChangeBackgroundColor"
+ categoryId="org.eclipse.egit.ui.GitTheme"
+ label="%Theme_UncommittedChangeBackgroundColor_label"
+ value="COLOR_LIST_BACKGROUND">
+ <description>
+ %Theme_UncommittedChangeBackgroundColor_description
+ </description>
+ </colorDefinition>
+ <fontDefinition
+ id="org.eclipse.egit.ui.UncommittedChangeFont"
+ categoryId="org.eclipse.egit.ui.GitTheme"
+ label="%Theme_UncommittedChangeFont_label">
+ <description>
+ %Theme_UncommittedChangeFont_description
+ </description>
+ </fontDefinition>
</extension>
<!-- ********** QuickDiff text editor support ************** -->
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
index 1d874c4..62201da 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
@@ -52,6 +52,12 @@ public class UIPreferences {
public final static String THEME_CommitGraphHighlightFont = "org.eclipse.egit.ui.CommitGraphHighlightFont"; //$NON-NLS-1$
/** */
public final static String THEME_CommitMessageFont = "org.eclipse.egit.ui.CommitMessageFont"; //$NON-NLS-1$
+ /** */
+ public final static String THEME_UncommittedChangeForegroundColor = "org.eclipse.egit.ui.UncommittedChangeForegroundColor"; //$NON-NLS-1$
+ /** */
+ public final static String THEME_UncommittedChangeBackgroundColor = "org.eclipse.egit.ui.UncommittedChangeBackgroundColor"; //$NON-NLS-1$
+ /** */
+ public final static String THEME_UncommittedChangeFont = "org.eclipse.egit.ui.UncommittedChangeFont"; //$NON-NLS-1$
/** */
public final static String DECORATOR_RECOMPUTE_ANCESTORS = "decorator_recompute_ancestors"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
index a966fe5..8e9083c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
@@ -15,6 +15,7 @@
package org.eclipse.egit.ui.internal.decorators;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -49,7 +50,15 @@ import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.IndexChangedEvent;
+import org.eclipse.jgit.lib.RefsChangedEvent;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryChangedEvent;
+import org.eclipse.jgit.lib.RepositoryListener;
import org.eclipse.osgi.util.TextProcessor;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.ui.ISharedImages;
@@ -57,11 +66,7 @@ import org.eclipse.team.ui.TeamImages;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.ui.IContributorResourceAdapter;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.jgit.lib.IndexChangedEvent;
-import org.eclipse.jgit.lib.RefsChangedEvent;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.RepositoryChangedEvent;
-import org.eclipse.jgit.lib.RepositoryListener;
+import org.eclipse.ui.themes.ITheme;
/**
* Supplies annotations for displayed resources
@@ -69,8 +74,6 @@ import org.eclipse.jgit.lib.RepositoryListener;
* This decorator provides annotations to indicate the status of each resource
* when compared to <code>HEAD</code>, as well as the index in the relevant
* repository.
- *
- * TODO: Add support for colors and font decoration
*/
public class GitLightweightDecorator extends LabelProvider implements
ILightweightLabelDecorator, IPropertyChangeListener,
@@ -98,6 +101,13 @@ public class GitLightweightDecorator extends LabelProvider implements
UIText.Decorator_exceptionMessage, Activator.getPluginId(),
IStatus.ERROR, Activator.getDefault().getLog());
+ private static String[] fonts = new String[] {
+ UIPreferences.THEME_UncommittedChangeFont};
+
+ private static String[] colors = new String[] {
+ UIPreferences.THEME_UncommittedChangeBackgroundColor,
+ UIPreferences.THEME_UncommittedChangeForegroundColor};
+
/**
* Constructs a new Git resource decorator
*/
@@ -110,6 +120,33 @@ public class GitLightweightDecorator extends LabelProvider implements
GitProjectData.addRepositoryChangeListener(this);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this,
IResourceChangeEvent.POST_CHANGE);
+
+ // This is an optimization to ensure that while decorating our fonts and colors are
+ // pre-created and decoration can occur without having to syncExec.
+ ensureFontAndColorsCreated(fonts, colors);
+ }
+
+ /**
+ * This method will ensure that the fonts and colors used by the decorator
+ * are cached in the registries. This avoids having to syncExec when
+ * decorating since we ensure that the fonts and colors are pre-created.
+ *
+ * @param fonts fonts ids to cache
+ * @param colors color ids to cache
+ */
+ private void ensureFontAndColorsCreated(final String[] fonts, final String[] colors) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ ITheme theme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
+ for (int i = 0; i < colors.length; i++) {
+ theme.getColorRegistry().get(colors[i]);
+
+ }
+ for (int i = 0; i < fonts.length; i++) {
+ theme.getFontRegistry().get(fonts[i]);
+ }
+ }
+ });
}
/*
@@ -276,6 +313,26 @@ public class GitLightweightDecorator extends LabelProvider implements
decorateText(decoration, resource);
decorateIcons(decoration, resource);
+ decorateFontAndColour(decoration, resource);
+ }
+
+ private void decorateFontAndColour(IDecoration decoration,
+ IDecoratableResource resource) {
+ ITheme current = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
+ if (resource.isIgnored()) {
+ return;
+ }
+ if (!resource.isTracked()
+ || resource.isDirty()
+ || resource.staged() != Staged.NOT_STAGED) {
+ Color bc = current.getColorRegistry().get(UIPreferences.THEME_UncommittedChangeBackgroundColor);
+ Color fc = current.getColorRegistry().get(UIPreferences.THEME_UncommittedChangeForegroundColor);
+ Font f = current.getFontRegistry().get(UIPreferences.THEME_UncommittedChangeFont);
+
+ decoration.setBackgroundColor(bc);
+ decoration.setForegroundColor(fc);
+ decoration.setFont(f);
+ }
}
private void decorateText(IDecoration decoration,
@@ -459,6 +516,11 @@ public class GitLightweightDecorator extends LabelProvider implements
|| prop.equals(TeamUI.GLOBAL_FILE_TYPES_CHANGED)
|| prop.equals(Activator.DECORATORS_CHANGED)) {
postLabelEvent(new LabelProviderChangedEvent(this));
+ } else if (prop.equals(UIPreferences.THEME_UncommittedChangeBackgroundColor)
+ || prop.equals(UIPreferences.THEME_UncommittedChangeFont)
+ || prop.equals(UIPreferences.THEME_UncommittedChangeForegroundColor)) {
+ ensureFontAndColorsCreated(fonts, colors);
+ postLabelEvent(new LabelProviderChangedEvent(this)); // TODO do I really need this?
}
}
@@ -509,7 +571,12 @@ public class GitLightweightDecorator extends LabelProvider implements
}
// All seems good, schedule the resource for update
- resourcesToUpdate.add(resource);
+ if (Constants.GITIGNORE_FILENAME.equals(resource.getName())) {
+ // re-decorate all container members when .gitignore changes
+ resourcesToUpdate.addAll(Arrays.asList(resource.getParent().members()));
+ } else {
+ resourcesToUpdate.add(resource);
+ }
if (delta.getKind() == IResourceDelta.CHANGED
&& (delta.getFlags() & IResourceDelta.OPEN) > 1)
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
index ec3aaa1..fb1462e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
@@ -711,9 +711,14 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
setColorsAndFonts(fViewer.getTree().getItems());
}
- @SuppressWarnings("unused")
private void setColorsAndFonts(TreeItem[] items) {
- // TODO: Implement colors and fonts
+ for (int i = 0; i < items.length; i++) {
+ PreviewDecoration decoration = getDecoration(items[i].getData());
+ items[i].setBackground(decoration.getBackgroundColor());
+ items[i].setForeground(decoration.getForegroundColor());
+ items[i].setFont(decoration.getFont());
+ setColorsAndFonts(items[i].getItems());
+ }
}
public void update(Observable o, Object arg) {
@@ -874,6 +879,12 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
private ImageDescriptor overlay = null;
+ private Color backgroundColor = null;
+
+ private Font font = null;
+
+ private Color foregroundColor = null;
+
/**
* Adds an icon overlay to the decoration
* <p>
@@ -902,21 +913,33 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
}
public void setBackgroundColor(Color color) {
- // TODO: Add support for color
+ backgroundColor = color;
}
public void setForegroundColor(Color color) {
- // TODO: Add support for color
+ foregroundColor = color;
}
public void setFont(Font font) {
- // TODO: Add support for fonts
+ this.font = font;
}
public ImageDescriptor getOverlay() {
return overlay;
}
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public Color getForegroundColor() {
+ return foregroundColor;
+ }
+
+ public Font getFont() {
+ return font;
+ }
+
public String getPrefix() {
StringBuffer sb = new StringBuffer();
for (Iterator<String> iter = prefixes.iterator(); iter.hasNext();) {