35
35
import org .eclipse .core .runtime .IStatus ;
36
36
import org .eclipse .e4 .core .services .events .IEventBroker ;
37
37
import org .eclipse .e4 .ui .css .swt .theme .IThemeEngine ;
38
+ import org .eclipse .jface .preference .IPreferenceStore ;
38
39
import org .eclipse .jface .preference .PreferenceConverter ;
39
40
import org .eclipse .jface .preference .PreferencePage ;
41
+ import org .eclipse .jface .resource .DataFormatException ;
40
42
import org .eclipse .jface .resource .JFaceResources ;
41
43
import org .eclipse .jface .resource .StringConverter ;
42
44
import org .eclipse .jface .util .IPropertyChangeListener ;
87
89
import org .eclipse .ui .internal .WorkbenchPlugin ;
88
90
import org .eclipse .ui .internal .misc .StatusUtil ;
89
91
import org .eclipse .ui .internal .util .PrefUtil ;
92
+ import org .eclipse .ui .themes .ColorUtil ;
90
93
import org .eclipse .ui .themes .ITheme ;
91
94
import org .eclipse .ui .themes .IThemeManager ;
92
95
import org .eclipse .ui .themes .IThemePreview ;
@@ -331,9 +334,20 @@ private class PresentationLabelProvider extends LabelProvider implements IFontPr
331
334
332
335
private int usableImageSize = -1 ;
333
336
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
+
334
347
private IPropertyChangeListener listener = event -> {
335
348
if (event .getNewValue () != null ) {
336
349
fireLabelProviderChanged (new LabelProviderChangedEvent (PresentationLabelProvider .this ));
350
+ Display .getDefault ().timerExec (REFRESH_INTERVAL_IN_MS , updateControlsAndRefreshTreeRunnable );
337
351
} else {
338
352
// Some theme definition element has been modified and we
339
353
// need to refresh the viewer
@@ -1304,6 +1318,30 @@ private void updateThemeInfo(IThemeManager manager) {
1304
1318
labelProvider .hookListeners (); // rehook the listeners
1305
1319
}
1306
1320
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
+
1307
1345
/**
1308
1346
* Answers whether the definition is currently set to the default value.
1309
1347
*
@@ -1314,23 +1352,29 @@ private void updateThemeInfo(IThemeManager manager) {
1314
1352
*/
1315
1353
private boolean isDefault (ColorDefinition definition ) {
1316
1354
String id = definition .getId ();
1317
-
1318
1355
if (colorPreferencesToSet .containsKey (definition )) {
1319
1356
if (definition .getValue () != null ) { // value-based color
1320
- if (colorPreferencesToSet .get (definition ).equals (definition .getValue ()))
1357
+ if (colorPreferencesToSet .get (definition )
1358
+ .equals (getColorTakingPreferenceDefaultValueIntoAccount (definition )))
1321
1359
return true ;
1322
1360
} else if (colorPreferencesToSet .get (definition ).equals (getColorAncestorValue (definition )))
1323
1361
return true ;
1324
1362
} else if (colorValuesToSet .containsKey (id )) {
1325
1363
if (definition .getValue () != null ) { // value-based color
1326
- if (colorValuesToSet .get (id ).equals (definition . getValue ( )))
1364
+ if (colorValuesToSet .get (id ).equals (getColorTakingPreferenceDefaultValueIntoAccount ( definition )))
1327
1365
return true ;
1328
1366
} else {
1329
1367
if (colorValuesToSet .get (id ).equals (getColorAncestorValue (definition )))
1330
1368
return true ;
1331
1369
}
1332
1370
} 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 )))
1334
1378
return true ;
1335
1379
} else {
1336
1380
// a descendant is default if it's the same value as its ancestor
@@ -1516,8 +1560,9 @@ private void refreshCategory() {
1516
1560
private boolean resetColor (ColorDefinition definition , boolean force ) {
1517
1561
if (force || !isDefault (definition )) {
1518
1562
RGB newRGB ;
1519
- if (definition .getValue () != null )
1520
- newRGB = definition .getValue ();
1563
+ if (definition .getValue () != null ) {
1564
+ newRGB = getColorTakingPreferenceDefaultValueIntoAccount (definition );
1565
+ }
1521
1566
else
1522
1567
newRGB = getColorAncestorValue (definition );
1523
1568
0 commit comments