From 617a563f9f1c264b123f8c1d01d7518d1f946799 Mon Sep 17 00:00:00 2001 From: Igor Fedorenko Date: Mon, 21 Dec 2009 09:36:18 -0500 Subject: [PATCH] Font and color decoration. 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 Signed-off-by: Matthias Sohn --- org.eclipse.egit.ui/plugin.properties | 6 ++ org.eclipse.egit.ui/plugin.xml | 28 +++++++- .../src/org/eclipse/egit/ui/UIPreferences.java | 6 ++ .../decorators/GitLightweightDecorator.java | 83 +++++++++++++++++++--- .../preferences/GitDecoratorPreferencePage.java | 33 +++++++-- 5 files changed, 142 insertions(+), 14 deletions(-) diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index ffca5686..3b22da0e 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 4f48e1c0..2c1cbbe2 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -200,7 +200,7 @@ - + + + + %Theme_UncommittedChangeForegroundColor_description + + + + + %Theme_UncommittedChangeBackgroundColor_description + + + + + %Theme_UncommittedChangeFont_description + + 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 1d874c42..62201da3 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 a966fe5c..8e9083c2 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 HEAD, 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 ec3aaa13..fb1462eb 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 *

@@ -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 iter = prefixes.iterator(); iter.hasNext();) { -- 2.11.4.GIT