Skip to content

Commit de3c93e

Browse files
Reset in colors preference page now respects theme-specific defaults
1 parent c5928bb commit de3c93e

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandler.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515

1616
import java.util.regex.Matcher;
1717
import java.util.regex.Pattern;
18+
import org.eclipse.core.runtime.preferences.DefaultScope;
1819
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
1920
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
2021
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
2122
import org.eclipse.e4.ui.css.swt.dom.preference.EclipsePreferencesElement;
2223
import org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper;
24+
import org.eclipse.jface.resource.ColorRegistry;
25+
import org.eclipse.jface.resource.JFaceResources;
26+
import org.eclipse.swt.graphics.RGB;
2327
import org.w3c.dom.css.CSSValue;
2428
import org.w3c.dom.css.CSSValueList;
2529

@@ -61,5 +65,18 @@ protected void overrideProperty(IEclipsePreferences preferences, String name, St
6165
preferences.put(name, value);
6266
EclipsePreferencesHelper.appendOverriddenPropertyName(preferences, name);
6367
}
68+
ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
69+
if (colorRegistry != null) {
70+
RGB rgb = colorRegistry.getRGB(name);
71+
if (rgb != null) {
72+
IEclipsePreferences defaultPrefs = DefaultScope.INSTANCE.getNode(preferences.name());
73+
if (defaultPrefs != null) {
74+
String existing = defaultPrefs.get(name, null);
75+
if (existing != null && value != null && existing.equals(value) == false) {
76+
defaultPrefs.put(name, value);
77+
}
78+
}
79+
}
80+
}
6481
}
6582
}

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/ColorDefinition.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,13 @@ public void setValue(RGB data) {
155155
appendState(State.OVERRIDDEN);
156156
}
157157
}
158+
159+
void setRawValue(String v) {
160+
rawValue = v;
161+
parsedValue = null;
162+
}
163+
164+
String getRawValue() {
165+
return rawValue;
166+
}
158167
}

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.eclipse.core.runtime.IStatus;
3636
import org.eclipse.e4.core.services.events.IEventBroker;
3737
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
38+
import org.eclipse.jface.preference.IPreferenceStore;
3839
import org.eclipse.jface.preference.PreferenceConverter;
3940
import org.eclipse.jface.preference.PreferencePage;
4041
import org.eclipse.jface.resource.JFaceResources;
@@ -1270,6 +1271,21 @@ public void init(IWorkbench aWorkbench) {
12701271
eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_RESTYLED, themeRegistryRestyledHandler);
12711272
}
12721273

1274+
private void setOverriddenColorDefaultsFromCss(ColorDefinition[] colorDefinitions) {
1275+
if (colorDefinitions == null || colorDefinitions.length == 0) {
1276+
return;
1277+
}
1278+
for (ColorDefinition def : colorDefinitions) {
1279+
String defaultString = getPreferenceStore().getDefaultString(def.getId());
1280+
if (defaultString != null) {
1281+
String rawValue = def.getRawValue();
1282+
if (rawValue != null && rawValue.equals(defaultString) == false) {
1283+
def.setRawValue(defaultString);
1284+
}
1285+
}
1286+
}
1287+
}
1288+
12731289
private void updateThemeInfo(IThemeManager manager) {
12741290
clearPreviews();
12751291
categoryMap.clear();
@@ -1284,6 +1300,9 @@ private void updateThemeInfo(IThemeManager manager) {
12841300

12851301
currentTheme = manager.getCurrentTheme();
12861302

1303+
ColorDefinition[] colorDefinitions = themeRegistry.getColorsFor(currentTheme.getId());
1304+
setOverriddenColorDefaultsFromCss(colorDefinitions);
1305+
12871306
currentCSSTheme = getActiveTheme();
12881307

12891308
colorRegistry = new CascadingColorRegistry(currentTheme.getColorRegistry());
@@ -1330,7 +1349,12 @@ private boolean isDefault(ColorDefinition definition) {
13301349
return true;
13311350
}
13321351
} else if (definition.getValue() != null) { // value-based color
1333-
if (getPreferenceStore().isDefault(createPreferenceKey(definition)))
1352+
IPreferenceStore store = getPreferenceStore();
1353+
String defaultString = store.getDefaultString(id);
1354+
String string = store.getString(id);
1355+
if (defaultString != null && string != null && defaultString.equals(string))
1356+
return true;
1357+
if (store.isDefault(createPreferenceKey(definition)))
13341358
return true;
13351359
} else {
13361360
// a descendant is default if it's the same value as its ancestor

0 commit comments

Comments
 (0)