Skip to content

Commit

Permalink
Fix for #666: Improved dark theme syntax coloring support (pt.2)
Browse files Browse the repository at this point in the history
- Fix copy of bold preference in Groovy Editor preference page
- Add stylesheets for light <--> dark theme transitions
  • Loading branch information
eric-milles committed Aug 6, 2018
1 parent 1388e61 commit 975e11f
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 70 deletions.
1 change: 1 addition & 0 deletions ide/org.codehaus.groovy.eclipse.ui/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source.. = jdt_src_patched/,\
output.. = bin/

bin.includes = .,\
*.css,\
icons/,\
schema/,\
META-INF/,\
Expand Down
13 changes: 13 additions & 0 deletions ide/org.codehaus.groovy.eclipse.ui/e4_dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IEclipsePreferences#org-codehaus-groovy-eclipse-ui:org-codehaus-groovy-eclipse-ui {
preferences:
'groovy.editor.highlight.gjdk.color=255,133,153'
'groovy.editor.highlight.gjdk.color_bold=false'
'groovy.editor.highlight.javakeywords.color=204,108,29'
'groovy.editor.highlight.javakeywords.color_bold=false'
'groovy.editor.highlight.javatypes.color=204,108,29'
'groovy.editor.highlight.javatypes.color_bold=false'
'groovy.editor.highlight.assert.color=204,108,29'
'groovy.editor.highlight.assert.color_bold=false'
'groovy.editor.highlight.return.color=204,108,29'
'groovy.editor.highlight.return.color_bold=false'
}
13 changes: 13 additions & 0 deletions ide/org.codehaus.groovy.eclipse.ui/e4_light.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IEclipsePreferences#org-codehaus-groovy-eclipse-ui:org-codehaus-groovy-eclipse-ui {
preferences:
'groovy.editor.highlight.gjdk.color=255,0,204'
'groovy.editor.highlight.gjdk.color_bold=false'
'groovy.editor.highlight.javakeywords.color=127,0,85'
'groovy.editor.highlight.javakeywords.color_bold=true'
'groovy.editor.highlight.javatypes.color=127,0,85'
'groovy.editor.highlight.javatypes.color_bold=true'
'groovy.editor.highlight.assert.color=127,0,85'
'groovy.editor.highlight.assert.color_bold=true'
'groovy.editor.highlight.return.color=127,0,85'
'groovy.editor.highlight.return.color_bold=true'
}
16 changes: 16 additions & 0 deletions ide/org.codehaus.groovy.eclipse.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1208,4 +1208,20 @@
</keyword>
</extension>

<extension
point="org.eclipse.e4.ui.css.swt.theme">
<stylesheet
uri="e4_dark.css">
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_dark">
</themeid>
</stylesheet>
<stylesheet
uri="e4_light.css">
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_default">
</themeid>
</stylesheet>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,10 @@
*/
package org.codehaus.groovy.eclipse.preferences;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.preference.IPreferenceNode;
Expand All @@ -42,55 +38,37 @@
import org.eclipse.ui.preferences.ScopedPreferenceStore;

public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage {
// Stores all created field editors
private final List<FieldEditor> editors = new ArrayList<>();
// Cache for page id
private String pageID;

// Stores owning element of properties
private IAdaptable element;

// Additional buttons for property pages
// private Button useWorkspaceSettingsButton, useProjectSettingsButton,
// configureButton;
// Overlay preference store for property pages
private IPreferenceStore overlayStore;

// The image descriptor of this pages title image
private ImageDescriptor image;

// Cache for page id
private String pageID;
// Overlay preference store for property pages
private IPreferenceStore overlayStore;

public FieldEditorOverlayPage(final int style) {
public FieldEditorOverlayPage(int style) {
super(style);
}

public FieldEditorOverlayPage(final String title, final int style) {
public FieldEditorOverlayPage(String title, int style) {
super(title, style);
}

public FieldEditorOverlayPage(final String title, final ImageDescriptor image, final int style) {
public FieldEditorOverlayPage(String title, ImageDescriptor image, int style) {
super(title, image, style);
this.image = image;
}

/**
* Returns the id of the current preference page as defined in plugin.xml.
* Subclasses must implement.
*
* @return the qualifier
*/
protected abstract String getPageId();

/**
* Receives the object that owns the properties shown in this property page.
*
* @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
*/
@Override
public void setElement(final IAdaptable element) {
this.element = element;
}

/**
* Delivers the object that owns the properties shown in this property page.
*
Expand All @@ -102,24 +80,22 @@ public IAdaptable getElement() {
}

/**
* Returns true if this instance represents a property page.
* Receives the object that owns the properties shown in this property page.
*
* @return true for property pages, false for preference pages
* @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
*/
public boolean isPropertyPage() {
return getElement() != null;
@Override
public void setElement(IAdaptable element) {
this.element = element;
}

/**
* We override the addField method. This allows us to store each field
* editor added by subclasses in a list for later processing.
* Returns true if this instance represents a property page.
*
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse.jface.preference.FieldEditor)
* @return true for property pages, false for preference pages
*/
@Override
protected void addField(final FieldEditor editor) {
editors.add(editor);
super.addField(editor);
public boolean isPropertyPage() {
return (getElement() != null);
}

/**
Expand All @@ -143,8 +119,7 @@ public void createControl(final Composite parent) {
}

private IPreferenceStore createPreferenceStore() {
IProject proj = Adapters.adapt(getElement(), IProject.class);
return preferenceStore(proj);
return preferenceStore(Adapters.adapt(getElement(), IProject.class));
}

protected IPersistentPreferenceStore preferenceStore(IProject proj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

import java.util.Arrays;

import groovy.lang.Tuple2;

import org.codehaus.groovy.eclipse.GroovyPlugin;
import org.codehaus.groovy.eclipse.editor.GroovyColorManager;
import org.eclipse.debug.internal.ui.preferences.BooleanFieldEditor2;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.ui.text.IJavaColorConstants;
import org.eclipse.jface.preference.BooleanFieldEditor;
Expand Down Expand Up @@ -63,29 +66,24 @@ public GroovyEditorPreferencesPage() {
@Override
public void createFieldEditors() {
// Category Methods
ColorFieldEditor gdkMethodEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_GJDK_COLOR,
"GroovyEditorPreferencesPage.GJDK_method_color");
/*Tuple2<ColorFieldEditor, BooleanFieldEditor2> categoryMethodEditor =*/ createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_GJDK_COLOR, "GroovyEditorPreferencesPage.GJDK_method_color");

// Primitive Types
ColorFieldEditor primitivesEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_PRIMITIVES_COLOR,
"GroovyEditorPreferencesPage.Primitives_color");
// Primitive Types (includes def, var, and void)
Tuple2<ColorFieldEditor, BooleanFieldEditor2> primitivesEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_PRIMITIVES_COLOR, "GroovyEditorPreferencesPage.Primitives_color");

// Other Keywords
ColorFieldEditor keywordEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_KEYWORDS_COLOR,
"GroovyEditorPreferencesPage.Keywords_color");
// Other Keywords (excludes assert and return)
Tuple2<ColorFieldEditor, BooleanFieldEditor2> keywordEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_KEYWORDS_COLOR, "GroovyEditorPreferencesPage.Keywords_color");

// Assert Keyword
ColorFieldEditor assertEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_ASSERT_COLOR,
"GroovyEditorPreferencesPage.Assert_color");
Tuple2<ColorFieldEditor, BooleanFieldEditor2> assertEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_ASSERT_COLOR, "GroovyEditorPreferencesPage.Assert_color");

// Return Keyword
ColorFieldEditor returnEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_RETURN_COLOR,
"GroovyEditorPreferencesPage.Return_color");
Tuple2<ColorFieldEditor, BooleanFieldEditor2> returnEditor = createColorEditor(
PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_RETURN_COLOR, "GroovyEditorPreferencesPage.Return_color");

// Semantic highlighting
Label l = new Label(getFieldEditorParent(), SWT.NONE);
Expand Down Expand Up @@ -118,22 +116,33 @@ public void createFieldEditors() {
IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();

Arrays.asList(primitivesEditor, keywordEditor, assertEditor).forEach(
editor -> editor.getColorSelector().setColorValue(PreferenceConverter.getColor(store, IJavaColorConstants.JAVA_KEYWORD)));
tuple -> copyColorAndStyle(tuple, store, IJavaColorConstants.JAVA_KEYWORD));

returnEditor.getColorSelector().setColorValue(PreferenceConverter.getColor(store, IJavaColorConstants.JAVA_KEYWORD_RETURN));
copyColorAndStyle(returnEditor, store, IJavaColorConstants.JAVA_KEYWORD_RETURN);
}));
}

private ColorFieldEditor createColorEditor(String preference, String nls) {
private Tuple2<ColorFieldEditor, BooleanFieldEditor2> createColorEditor(String preference, String nls) {
Composite parent = getFieldEditorParent();

Tuple2<ColorFieldEditor, BooleanFieldEditor2> editors = new Tuple2<>(
new ColorFieldEditor(preference, Messages.getString(nls), parent),
new BooleanFieldEditor2(
preference + PreferenceConstants.GROOVY_EDITOR_BOLD_SUFFIX,
" " + Messages.getString("GroovyEditorPreferencesPage.BoldToggle"),
BooleanFieldEditor.SEPARATE_LABEL, getFieldEditorParent())
);

addField(new SpacerFieldEditor(parent));
ColorFieldEditor colorFieldEditor = new ColorFieldEditor(preference, Messages.getString(nls), parent);
addField(colorFieldEditor);
addField(new BooleanFieldEditor(
preference + PreferenceConstants.GROOVY_EDITOR_BOLD_SUFFIX,
" " + Messages.getString("GroovyEditorPreferencesPage.BoldToggle"),
BooleanFieldEditor.SEPARATE_LABEL, getFieldEditorParent()));
return colorFieldEditor;
addField(editors.getFirst());
addField(editors.getSecond());

return editors;
}

private void copyColorAndStyle(Tuple2<ColorFieldEditor, BooleanFieldEditor2> tuple, IPreferenceStore store, String pref) {
tuple.getFirst().getColorSelector().setColorValue(PreferenceConverter.getColor(store, pref));
tuple.getSecond().getChangeControl(null).setSelection(store.getBoolean(pref + PreferenceConstants.GROOVY_EDITOR_BOLD_SUFFIX));
}

@Override
Expand Down

0 comments on commit 975e11f

Please sign in to comment.