3535import org .eclipse .core .runtime .IStatus ;
3636import org .eclipse .e4 .core .services .events .IEventBroker ;
3737import org .eclipse .e4 .ui .css .swt .theme .IThemeEngine ;
38+ import org .eclipse .jface .preference .IPreferenceStore ;
3839import org .eclipse .jface .preference .PreferenceConverter ;
3940import org .eclipse .jface .preference .PreferencePage ;
41+ import org .eclipse .jface .resource .DataFormatException ;
4042import org .eclipse .jface .resource .JFaceResources ;
4143import org .eclipse .jface .resource .StringConverter ;
4244import org .eclipse .jface .util .IPropertyChangeListener ;
8789import org .eclipse .ui .internal .WorkbenchPlugin ;
8890import org .eclipse .ui .internal .misc .StatusUtil ;
8991import org .eclipse .ui .internal .util .PrefUtil ;
92+ import org .eclipse .ui .themes .ColorUtil ;
9093import org .eclipse .ui .themes .ITheme ;
9194import org .eclipse .ui .themes .IThemeManager ;
9295import org .eclipse .ui .themes .IThemePreview ;
@@ -331,9 +334,20 @@ private class PresentationLabelProvider extends LabelProvider implements IFontPr
331334
332335 private int usableImageSize = -1 ;
333336
337+ private static final int REFRESH_INTERVAL_IN_MS = 300 ;
338+
339+ private final Runnable updateControlsAndRefreshTreeRunnable = () -> {
340+ if (fontChangeButton == null || fontChangeButton .isDisposed ()) {
341+ return ;
342+ }
343+ updateControls ();
344+ tree .getViewer ().refresh ();
345+ };
346+
334347 private IPropertyChangeListener listener = event -> {
335348 if (event .getNewValue () != null ) {
336349 fireLabelProviderChanged (new LabelProviderChangedEvent (PresentationLabelProvider .this ));
350+ Display .getDefault ().timerExec (REFRESH_INTERVAL_IN_MS , updateControlsAndRefreshTreeRunnable );
337351 } else {
338352 // Some theme definition element has been modified and we
339353 // need to refresh the viewer
@@ -1304,6 +1318,30 @@ private void updateThemeInfo(IThemeManager manager) {
13041318 labelProvider .hookListeners (); // rehook the listeners
13051319 }
13061320
1321+ private RGB getColorTakingPreferenceDefaultValueIntoAccount (ColorDefinition definition ) {
1322+ final RGB valueFromExtension = definition .getValue ();
1323+ IPreferenceStore store = getPreferenceStore ();
1324+ if (store == null ) {
1325+ return valueFromExtension ;
1326+ }
1327+ String id = definition .getId ();
1328+ if (id == null || id .isBlank ()) {
1329+ return valueFromExtension ;
1330+ }
1331+ String storeDefault = store .getDefaultString (id );
1332+ if (storeDefault == null ) {
1333+ return valueFromExtension ;
1334+ }
1335+ try {
1336+ RGB defaultRGB = ColorUtil .getColorValue (storeDefault );
1337+ if (defaultRGB != null && !defaultRGB .equals (valueFromExtension )) {
1338+ return defaultRGB ;
1339+ }
1340+ } catch (DataFormatException e ) { // silently ignored
1341+ }
1342+ return valueFromExtension ;
1343+ }
1344+
13071345 /**
13081346 * Answers whether the definition is currently set to the default value.
13091347 *
@@ -1314,23 +1352,29 @@ private void updateThemeInfo(IThemeManager manager) {
13141352 */
13151353 private boolean isDefault (ColorDefinition definition ) {
13161354 String id = definition .getId ();
1317-
13181355 if (colorPreferencesToSet .containsKey (definition )) {
13191356 if (definition .getValue () != null ) { // value-based color
1320- if (colorPreferencesToSet .get (definition ).equals (definition .getValue ()))
1357+ if (colorPreferencesToSet .get (definition )
1358+ .equals (getColorTakingPreferenceDefaultValueIntoAccount (definition )))
13211359 return true ;
13221360 } else if (colorPreferencesToSet .get (definition ).equals (getColorAncestorValue (definition )))
13231361 return true ;
13241362 } else if (colorValuesToSet .containsKey (id )) {
13251363 if (definition .getValue () != null ) { // value-based color
1326- if (colorValuesToSet .get (id ).equals (definition . getValue ( )))
1364+ if (colorValuesToSet .get (id ).equals (getColorTakingPreferenceDefaultValueIntoAccount ( definition )))
13271365 return true ;
13281366 } else {
13291367 if (colorValuesToSet .get (id ).equals (getColorAncestorValue (definition )))
13301368 return true ;
13311369 }
13321370 } else if (definition .getValue () != null ) { // value-based color
1333- if (getPreferenceStore ().isDefault (createPreferenceKey (definition )))
1371+ IPreferenceStore store = getPreferenceStore ();
1372+ String defaultString = store .getDefaultString (id );
1373+ String string = store .getString (id );
1374+ if (defaultString != null && string != null && defaultString .equals (string )) {
1375+ return true ;
1376+ }
1377+ if (store .isDefault (createPreferenceKey (definition )))
13341378 return true ;
13351379 } else {
13361380 // a descendant is default if it's the same value as its ancestor
@@ -1516,8 +1560,9 @@ private void refreshCategory() {
15161560 private boolean resetColor (ColorDefinition definition , boolean force ) {
15171561 if (force || !isDefault (definition )) {
15181562 RGB newRGB ;
1519- if (definition .getValue () != null )
1520- newRGB = definition .getValue ();
1563+ if (definition .getValue () != null ) {
1564+ newRGB = getColorTakingPreferenceDefaultValueIntoAccount (definition );
1565+ }
15211566 else
15221567 newRGB = getColorAncestorValue (definition );
15231568
0 commit comments