diff options
5 files changed, 112 insertions, 11 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index 1f75a27aa2..3f21551327 100644 --- a/org.eclipse.egit.ui/plugin.properties +++ b/org.eclipse.egit.ui/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2005, 2012 Shawn Pearce and others. +# Copyright (c) 2005, 2012, 2013 Shawn Pearce and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -97,6 +97,12 @@ Theme_DiffRemoveBackgroundColor_label=Diff Removed (Background) Theme_DiffRemoveBackgroundColor_description=This color is used for the background color for removed diff lines displayed in the commit viewer. Theme_DiffRemoveForegroundColor_label=Diff Removed (Foreground) Theme_DiffRemoveForegroundColor_description=This color is used for the foreground color for removed diff lines displayed in the commit viewer. +Theme_DiffHeadlineForegroundColor_label=Diff Headline (Foreground) +Theme_DiffHeadlineForegroundColor_description=This color is used for the foreground color for the first line of a file (headline) in the commit viewer. +Theme_DiffHeadlineBackgroundColor_label=Diff Headline (Background) +Theme_DiffHeadlineBackgroundColor_description=This color is used for the background color for the first line of a file (headline) in the commit viewer. +Theme_DiffHeadlineFont_label=Diff Headline (Font) +Theme_DiffHeadlineFont_description=This font is used for the the first line of a file (headline) in the commit viewer. GitPreferences_name=Git GitPreferences_WindowCachePreferencePage_name=Window Cache diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index 906cc25329..c5dc4448ce 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -661,6 +661,35 @@ %Theme_DiffRemoveForegroundColor_description </description> </colorDefinition> + <colorDefinition + categoryId="org.eclipse.egit.ui.GitTheme" + id="org.eclipse.egit.ui.DiffHeadlineForegroundColor" + isEditable="true" + label="%Theme_DiffHeadlineForegroundColor_label" + value="COLOR_BLACK"> + <description> + %Theme_DiffHeadlineForegroundColor_description + </description> + </colorDefinition> + <colorDefinition + categoryId="org.eclipse.egit.ui.GitTheme" + id="org.eclipse.egit.ui.DiffHeadlineBackgroundColor" + isEditable="true" + label="%Theme_DiffHeadlineBackgroundColor_label" + value="170,170,170"> + <description> + %Theme_DiffHeadlineBackgroundColor_description + </description> + </colorDefinition> + <fontDefinition + categoryId="org.eclipse.egit.ui.GitTheme" + defaultsTo="org.eclipse.jface.textfont" + id="org.eclipse.egit.ui.DiffHeadlineFont" + label="%Theme_DiffHeadlineFont_label"> + <description> + %Theme_DiffHeadlineFont_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 dbed5321fa..89db482574 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 @@ -4,6 +4,7 @@ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com> * Copyright (C) 2012, Daniel Megert <daniel_megert@ch.ibm.com> + * Copyright (C) 2013, Tobias Pfeifer <to.pfeifer@sap.com> * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -93,6 +94,12 @@ public class UIPreferences { /** */ public final static String THEME_DiffHunkForegroundColor = "org.eclipse.egit.ui.DiffHunkForegroundColor"; //$NON-NLS-1$ /** */ + public final static String THEME_DiffHeadlineBackgroundColor = "org.eclipse.egit.ui.DiffHeadlineBackgroundColor"; //$NON-NLS-1$ + /** */ + public final static String THEME_DiffHeadlineForegroundColor = "org.eclipse.egit.ui.DiffHeadlineForegroundColor"; //$NON-NLS-1$ + /** */ + public final static String THEME_DiffHeadlineFont = "org.eclipse.egit.ui.DiffHeadlineFont"; //$NON-NLS-1$ + /** */ public final static String THEME_DiffAddBackgroundColor = "org.eclipse.egit.ui.DiffAddBackgroundColor"; //$NON-NLS-1$ /** */ public final static String THEME_DiffAddForegroundColor = "org.eclipse.egit.ui.DiffAddForegroundColor"; //$NON-NLS-1$ @@ -100,7 +107,6 @@ public class UIPreferences { public final static String THEME_DiffRemoveBackgroundColor = "org.eclipse.egit.ui.DiffRemoveBackgroundColor"; //$NON-NLS-1$ /** */ public final static String THEME_DiffRemoveForegroundColor = "org.eclipse.egit.ui.DiffRemoveForegroundColor"; //$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/commit/DiffStyleRangeFormatter.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java index 8e266dd8e4..dedc020976 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 GitHub Inc. + * Copyright (c) 2011, 2013 GitHub Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,9 +7,11 @@ * * Contributors: * Kevin Sawicki (GitHub Inc.) - initial API and implementation + * Tobias Pfeifer (SAP AG) - customizable font and color for the first header line - https://bugs.eclipse.org/397723 *******************************************************************************/ package org.eclipse.egit.ui.internal.commit; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; @@ -23,6 +25,7 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.EditList; import org.eclipse.jgit.diff.RawText; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.lib.Repository; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.graphics.Color; @@ -60,6 +63,11 @@ public class DiffStyleRangeFormatter extends DiffFormatter { HUNK, /** + * Headline + */ + HEADLINE, + + /** * Other line */ OTHER, @@ -189,12 +197,18 @@ public class DiffStyleRangeFormatter extends DiffFormatter { * Create and add diff style range * * @param type + * the {@link Type} + * @param start + * start offset + * @param end + * end offset * @return added range */ - protected DiffStyleRange addRange(Type type) { + protected DiffStyleRange addRange(Type type, int start, int end) { DiffStyleRange range = new DiffStyleRange(); - range.start = stream.offset; + range.start = start; range.diffType = type; + range.length = end - start; ranges.add(range); return range; } @@ -205,10 +219,10 @@ public class DiffStyleRangeFormatter extends DiffFormatter { */ protected void writeHunkHeader(int aStartLine, int aEndLine, int bStartLine, int bEndLine) throws IOException { - DiffStyleRange range = addRange(Type.HUNK); + int start = stream.offset; super.writeHunkHeader(aStartLine, aEndLine, bStartLine, bEndLine); stream.flushLine(); - range.length = stream.offset - range.start; + addRange(Type.HUNK, start, stream.offset); } /** @@ -221,14 +235,30 @@ public class DiffStyleRangeFormatter extends DiffFormatter { super.writeLine(prefix, text, cur); stream.flushLine(); } else { - DiffStyleRange range = addRange(prefix == '+' ? Type.ADD - : Type.REMOVE); + Type type = prefix == '+' ? Type.ADD : Type.REMOVE; + int start = stream.offset; super.writeLine(prefix, text, cur); stream.flushLine(); - range.length = stream.offset - range.start; + addRange(type, start, stream.offset); } } + /** + * @see org.eclipse.jgit.diff.DiffFormatter#formatGitDiffFirstHeaderLine(ByteArrayOutputStream + * o, ChangeType type, String oldPath, String newPath) + */ + @Override + protected void formatGitDiffFirstHeaderLine(ByteArrayOutputStream o, + final ChangeType type, final String oldPath, final String newPath) + throws IOException { + stream.flushLine(); + int offset = stream.offset; + int start = o.size(); + super.formatGitDiffFirstHeaderLine(o, type, oldPath, newPath); + int end = o.size(); + addRange(Type.HEADLINE, offset + start, offset + end); + } + @Override public void format(final EditList edits, final RawText a, final RawText b) throws IOException { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java index f2e00b5f43..7b0a95eae6 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 GitHub Inc. + * Copyright (c) 2011, 2013 GitHub Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Kevin Sawicki (GitHub Inc.) - initial API and implementation + * Tobias Pfeifer (SAP AG) - customizable font and color for the first header line - https://bugs.eclipse.org/397723 *******************************************************************************/ package org.eclipse.egit.ui.internal.commit; @@ -16,6 +17,9 @@ import static org.eclipse.egit.ui.UIPreferences.THEME_DiffHunkBackgroundColor; import static org.eclipse.egit.ui.UIPreferences.THEME_DiffHunkForegroundColor; import static org.eclipse.egit.ui.UIPreferences.THEME_DiffRemoveBackgroundColor; import static org.eclipse.egit.ui.UIPreferences.THEME_DiffRemoveForegroundColor; +import static org.eclipse.egit.ui.UIPreferences.THEME_DiffHeadlineBackgroundColor; +import static org.eclipse.egit.ui.UIPreferences.THEME_DiffHeadlineForegroundColor; +import static org.eclipse.egit.ui.UIPreferences.THEME_DiffHeadlineFont; import org.eclipse.egit.ui.internal.commit.DiffStyleRangeFormatter.DiffStyleRange; import org.eclipse.jface.preference.IPreferenceStore; @@ -23,6 +27,7 @@ import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.ColorDescriptor; import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.jface.resource.DeviceResourceManager; +import org.eclipse.jface.resource.FontRegistry; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.source.CompositeRuler; @@ -38,6 +43,7 @@ import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.editors.text.EditorsUI; @@ -71,6 +77,12 @@ public class DiffViewer extends SourceViewer { private Color removeForegroundColor; + private Color headlineBackgroundColor; + + private Color headlineForegroundColor; + + private Font headlineFont; + private IPropertyChangeListener themeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { @@ -80,9 +92,13 @@ public class DiffViewer extends SourceViewer { || THEME_DiffAddForegroundColor.equals(property) || THEME_DiffHunkBackgroundColor.equals(property) || THEME_DiffHunkForegroundColor.equals(property) + || THEME_DiffHeadlineBackgroundColor.equals(property) + || THEME_DiffHeadlineForegroundColor.equals(property) + || THEME_DiffHeadlineFont.equals(property) || THEME_DiffRemoveBackgroundColor.equals(property) || THEME_DiffRemoveForegroundColor.equals(property)) { refreshDiffColors(); + refreshDiffFonts(); refreshStyleRanges(); } } @@ -125,9 +141,16 @@ public class DiffViewer extends SourceViewer { } }); refreshDiffColors(); + refreshDiffFonts(); styleViewer(); } + private void refreshDiffFonts() { + FontRegistry reg = PlatformUI.getWorkbench().getThemeManager() + .getCurrentTheme().getFontRegistry(); + this.headlineFont = reg.get(THEME_DiffHeadlineFont); + } + private void refreshDiffColors() { ColorRegistry reg = PlatformUI.getWorkbench().getThemeManager() .getCurrentTheme().getColorRegistry(); @@ -137,6 +160,8 @@ public class DiffViewer extends SourceViewer { this.removeForegroundColor = reg.get(THEME_DiffRemoveForegroundColor); this.hunkBackgroundColor = reg.get(THEME_DiffHunkBackgroundColor); this.hunkForegroundColor = reg.get(THEME_DiffHunkForegroundColor); + this.headlineBackgroundColor = reg.get(THEME_DiffHeadlineBackgroundColor); + this.headlineForegroundColor = reg.get(THEME_DiffHeadlineForegroundColor); } private void initListeners() { @@ -220,6 +245,11 @@ public class DiffViewer extends SourceViewer { range.foreground = hunkForegroundColor; range.lineBackground = hunkBackgroundColor; break; + case HEADLINE: + range.font = headlineFont; + range.foreground = headlineForegroundColor; + range.lineBackground = headlineBackgroundColor; + break; default: break; } |