Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-03-09 06:06:03 -0500
committerAlexander Kurtakov2017-03-09 06:34:16 -0500
commitbf4d309cd282cc0dc05d4ee8f23f823e29e3e403 (patch)
tree006039a9ba37874b02ab2e98b1bd2e796584bf1c /changelog
parent99e218ef0c352772755b817684a6247c3c10dc49 (diff)
downloadorg.eclipse.linuxtools-bf4d309cd282cc0dc05d4ee8f23f823e29e3e403.tar.gz
org.eclipse.linuxtools-bf4d309cd282cc0dc05d4ee8f23f823e29e3e403.tar.xz
org.eclipse.linuxtools-bf4d309cd282cc0dc05d4ee8f23f823e29e3e403.zip
changelog: Editor highlighting in themes.
Less coupling and prep for dark theme support. Change-Id: I65c2458c8b4f735367e4189198f43224e7c14567 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com> Reviewed-on: https://git.eclipse.org/r/92684 Tested-by: Hudson CI
Diffstat (limited to 'changelog')
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/plugin.xml32
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ColorManager.java45
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java30
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUElementScanner.java117
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java12
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkScanner.java60
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/IChangeLogColorConstants.java18
7 files changed, 151 insertions, 163 deletions
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml b/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml
index 19b5f89419..f7fe6abb00 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml
+++ b/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml
@@ -300,4 +300,36 @@
</command>
</menuContribution>
</extension>
+ <extension
+ point="org.eclipse.ui.themes">
+ <themeElementCategory
+ id="org.eclipse.linuxtools.changelog.editor.presentation"
+ label="Changelog files editor">
+ </themeElementCategory>
+ <colorDefinition
+ categoryId="org.eclipse.linuxtools.changelog.editor.presentation"
+ id="org.eclipse.linuxtools.changelog.ediotr.color.file_name"
+ label="File name"
+ value="128,0,0">
+ </colorDefinition>
+ <colorDefinition
+ categoryId="org.eclipse.linuxtools.changelog.editor.presentation"
+ id="org.eclipse.linuxtools.changelog.editor.color.func_name"
+ label="Function name"
+ value="0,128,0">
+ </colorDefinition>
+ <colorDefinition
+ categoryId="org.eclipse.linuxtools.changelog.editor.presentation"
+ id="org.eclipse.linuxtools.changelog.editor.color.text"
+ label="Text"
+ value="0,0,0">
+ </colorDefinition>
+ <colorDefinition
+ categoryId="org.eclipse.linuxtools.changelog.editor.presentation"
+ id="org.eclipse.linuxtools.changelog.editor.color.email"
+ label="Email"
+ value="0,0,128">
+ </colorDefinition>
+ </extension>
+
</plugin>
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ColorManager.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ColorManager.java
deleted file mode 100644
index c00e41cc56..0000000000
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ColorManager.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 Red Hat 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Kyu Lee <klee@redhat.com> - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.changelog.core.editors;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Manages color schemes. Actual color value is stored in
- * IChangeLogColorConstants.
- *
- * @author klee (Kyu Lee)
- *
- */
-public class ColorManager {
-
- protected Map<RGB, Color> fColorTable = new HashMap<>(10);
-
- public void dispose() {
- for (Color color: fColorTable.values()){
- color.dispose();
- }
- }
-
- public Color getColor(RGB rgb) {
- Color color = fColorTable.get(rgb);
- if (color == null) {
- color = new Color(Display.getCurrent(), rgb);
- fColorTable.put(rgb, color);
- }
- return color;
- }
-}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java
index be7369e4aa..42510e9a23 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.changelog.core.editors;
import java.util.Map;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.TextAttribute;
@@ -26,6 +27,7 @@ import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.linuxtools.changelog.core.IEditorChangeLogContrib;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
@@ -40,19 +42,13 @@ public class GNUEditorConfiguration extends TextSourceViewerConfiguration implem
public static final String CHANGELOG_PARTITIONING= "gnu_changelog_partitioning"; //$NON-NLS-1$
- private GNUElementScanner scanner;
-
- private ColorManager colorManager;
-
private TextEditor parentEditor;
/**
* Prepares configuration.
*/
public GNUEditorConfiguration() {
- this.colorManager = new ColorManager();
-
- }
+ }
/**
* Sets TextEditor that this configuration is going to be applied.
@@ -74,15 +70,6 @@ public class GNUEditorConfiguration extends TextSourceViewerConfiguration implem
GNUPartitionScanner.CHANGELOG_SRC_ENTRY};
}
- private GNUElementScanner getChangeLogFileScanner() {
- if (scanner == null) {
- scanner = new GNUElementScanner(colorManager);
- scanner.setDefaultReturnToken(new Token(new TextAttribute(
- colorManager.getColor(IChangeLogColorConstants.TEXT))));
- }
- return scanner;
- }
-
/**
* Detects hyperlinks in GNU formatted changelogs.
*
@@ -130,16 +117,19 @@ public class GNUEditorConfiguration extends TextSourceViewerConfiguration implem
public IPresentationReconciler getPresentationReconciler(
ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
-
- DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getChangeLogFileScanner());
+ ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
+ GNUElementScanner scanner = new GNUElementScanner();
+ scanner.setDefaultReturnToken(new Token(new TextAttribute(
+ colorRegistry.get(IChangeLogColorConstants.TEXT))));
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
reconciler.setDamager(dr, GNUPartitionScanner.CHANGELOG_EMAIL);
reconciler.setRepairer(dr, GNUPartitionScanner.CHANGELOG_EMAIL);
- dr= new GNUFileEntryDamagerRepairer(getChangeLogFileScanner());
+ dr= new GNUFileEntryDamagerRepairer(scanner);
reconciler.setDamager(dr, GNUPartitionScanner.CHANGELOG_SRC_ENTRY);
reconciler.setRepairer(dr, GNUPartitionScanner.CHANGELOG_SRC_ENTRY);
- dr= new MultilineRuleDamagerRepairer(getChangeLogFileScanner());
+ dr= new MultilineRuleDamagerRepairer(scanner);
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUElementScanner.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUElementScanner.java
index 1707f941d8..dc5cd4a5c7 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUElementScanner.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUElementScanner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Red Hat Inc. and others.
+ * Copyright (c) 2006, 2017 Red Hat 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
@@ -10,8 +10,14 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.changelog.core.editors;
-import org.eclipse.jface.text.*;
-import org.eclipse.jface.text.rules.*;
+import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.ui.PlatformUI;
/**
* Recognizes GNU format changelog. Can be configured to return different types
@@ -21,89 +27,44 @@ import org.eclipse.jface.text.rules.*;
*/
public class GNUElementScanner extends RuleBasedScanner {
- public static final String FILE_NAME = "_file_name"; // $NON-NLS-1$
- public static final String TEXT = "_text_content"; // $NON-NLS-1$
- public static final String EMAIL = "_author_email"; // $NON-NLS-1$
- public static final String DATE = "_entry_date"; // $NON-NLS-1$
- public static final String AUTHOR = "_author_name"; // $NON-NLS-1$
- public static final String FUNC_NAME = "_function_name"; // $NON-NLS-1$
- public static final String OTHER = "_other"; // $NON-NLS-1$
- /**
- * Build a scanner for syntax highlighting.
- *
- * @param manager Color scheme to use.
- */
- public GNUElementScanner(ColorManager manager) {
- IToken file = new Token(new TextAttribute(manager
- .getColor(IChangeLogColorConstants.FILE_NAME)));
+ /**
+ * Build a scanner for syntax highlighting.
+ *
+ */
+ public GNUElementScanner() {
+ ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
+ IToken file = new Token(new TextAttribute(colorRegistry.get(IChangeLogColorConstants.FILE_NAME)));
- IToken func = new Token(new TextAttribute(manager
- .getColor(IChangeLogColorConstants.FUNC_NAME)));
+ IToken func = new Token(new TextAttribute(colorRegistry.get(IChangeLogColorConstants.FUNC_NAME)));
- IToken email = new Token(new TextAttribute(manager
- .getColor(IChangeLogColorConstants.EMAIL)));
+ IToken email = new Token(new TextAttribute(colorRegistry.get(IChangeLogColorConstants.EMAIL)));
- IToken other = new Token(new TextAttribute(manager
- .getColor(IChangeLogColorConstants.TEXT)));
+ IToken other = new Token(new TextAttribute(colorRegistry.get(IChangeLogColorConstants.TEXT)));
- IRule[] rules = new IRule[3];
+ IRule[] rules = new IRule[3];
- // Add rule for file path
- rules[0] = new GNUFileEntryRule(file);
+ // Add rule for file path
+ rules[0] = new GNUFileEntryRule(file);
- // function
- rules[1] = new SingleLineRule("(", ")", func); // $NON-NLS-1$ // $NON-NLS-2$
- // email
- rules[2] = new SingleLineRule("<", ">\n", email); // $NON-NLS-1$ // $NON-NLS-2$
+ // function
+ rules[1] = new SingleLineRule("(", ")", func); // $NON-NLS-1$ //
+ // $NON-NLS-2$
+ // email
+ rules[2] = new SingleLineRule("<", ">\n", email); // $NON-NLS-1$ //
+ // $NON-NLS-2$
- setDefaultReturnToken(other);
+ setDefaultReturnToken(other);
- setRules(rules);
- }
+ setRules(rules);
+ }
- /**
- * Build a scanner for hyperlink.
- *
- */
- public GNUElementScanner() {
- IToken file = new Token(FILE_NAME);
- IToken func = new Token(FUNC_NAME);
-
- IToken email = new Token(EMAIL);
-
- IToken other = new Token(OTHER);
-
- IRule[] rules = new IRule[3];
-
- // Add rule for file path
- rules[0] = new GNUFileEntryRule(file);
-
- // function
- rules[1] = new SingleLineRule("(", "):", func); // $NON-NLS-1$ // $NON-NLS-2$
- // email
- rules[2]= new SingleLineRule("<", ">", email); // $NON-NLS-1$ // $NON-NLS-2$
-
- setDefaultReturnToken(other);
-
- setRules(rules);
- }
-
- /**
- * Get the file offset.
- *
- * @return the file offset.
- */
- public int getOffset() {
- return fOffset;
- }
-
- /**
- * Get the default token.
- *
- * @return the default token.
- */
- public IToken getDefaultToken() {
- return fDefaultReturnToken;
- }
+ /**
+ * Get the default token.
+ *
+ * @return the default token.
+ */
+ public IToken getDefaultToken() {
+ return fDefaultReturnToken;
+ }
}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java
index a3b96befb6..a1d8d26f0b 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Red Hat Inc. and others.
+ * Copyright (c) 2006, 2017 Red Hat 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
@@ -79,9 +79,7 @@ public class GNUHyperlinkDetector extends AbstractHyperlinkDetector {
IDocument thisDoc = textViewer.getDocument();
- GNUElementScanner scanner = new GNUElementScanner();
-
- scanner.setDefaultReturnToken(new Token("default"));
+ GNUHyperlinkScanner scanner = new GNUHyperlinkScanner();
ITypedRegion partitionInfo = null;
@@ -96,7 +94,7 @@ public class GNUHyperlinkDetector extends AbstractHyperlinkDetector {
Token tmpToken = (Token) scanner.nextToken();
- String tokenStr = (String) tmpToken.getData();
+ String tokenStr = (String) tmpToken.getData();
if (tokenStr == null) {
return null;
@@ -105,7 +103,7 @@ public class GNUHyperlinkDetector extends AbstractHyperlinkDetector {
// try to find non-default token containing region..if none, return null.
while (region.getOffset() < scanner.getTokenOffset() ||
region.getOffset() > scanner.getOffset() ||
- tokenStr.equals("default")) {
+ tokenStr.equals("_other")) {
tmpToken = (Token) scanner.nextToken();
tokenStr = (String) tmpToken.getData();
if (tokenStr == null)
@@ -125,7 +123,7 @@ public class GNUHyperlinkDetector extends AbstractHyperlinkDetector {
}
// process file link
- if (tokenStr.equals(GNUElementScanner.FILE_NAME)) {
+ if (tokenStr.equals(GNUHyperlinkScanner.FILE_NAME)) {
Region pathRegion = null;
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkScanner.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkScanner.java
new file mode 100644
index 0000000000..5da2c445be
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkScanner.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.changelog.core.editors;
+
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.Token;
+
+public class GNUHyperlinkScanner extends RuleBasedScanner {
+
+ public static final String FILE_NAME = "_file_name"; // $NON-NLS-1$
+ public static final String OTHER = "_other"; // $NON-NLS-1$
+
+ /**
+ * Build a scanner for hyperlink.
+ *
+ */
+ public GNUHyperlinkScanner() {
+ IToken file = new Token(FILE_NAME);
+
+ IToken other = new Token(OTHER);
+
+ IRule[] rules = new IRule[1];
+
+ // Add rule for file path
+ rules[0] = new GNUFileEntryRule(file);
+
+ setDefaultReturnToken(other);
+
+ setRules(rules);
+ }
+
+ /**
+ * Get the file offset.
+ *
+ * @return the file offset.
+ */
+ public int getOffset() {
+ return fOffset;
+ }
+
+ /**
+ * Get the default token.
+ *
+ * @return the default token.
+ */
+ public IToken getDefaultToken() {
+ return fDefaultReturnToken;
+ }
+
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/IChangeLogColorConstants.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/IChangeLogColorConstants.java
index 10eae4e6c4..c3b0388bd7 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/IChangeLogColorConstants.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/IChangeLogColorConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Red Hat Inc. and others.
+ * Copyright (c) 2006, 2017 Red Hat 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
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.changelog.core.editors;
-import org.eclipse.swt.graphics.RGB;
-
/**
* Color scheme to use for syntax highlighting.
*
@@ -19,15 +17,9 @@ import org.eclipse.swt.graphics.RGB;
*
*/
public interface IChangeLogColorConstants {
- RGB FILE_NAME = new RGB(128, 0, 0);
-
- RGB FUNC_NAME = new RGB(0, 128, 0);
-
- RGB TEXT = new RGB(0, 0, 0);
-
- RGB EMAIL = new RGB(0, 0, 128);
-
- RGB DATE = new RGB(64, 64, 0);
+ String FILE_NAME = "org.eclipse.linuxtools.changelog.ediotr.color.file_name";
+ String FUNC_NAME = "org.eclipse.linuxtools.changelog.editor.color.func_name";
+ String TEXT = "org.eclipse.linuxtools.changelog.editor.color.text";
+ String EMAIL = "org.eclipse.linuxtools.changelog.editor.color.email";
- RGB AUTHOR = new RGB(0, 64, 64);
}

Back to the top