mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 11:20:44 +07:00
A better way to provide backward compatibility with old color schemes
This commit is contained in:
@@ -32,6 +32,8 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
|
||||
|
||||
public static final TextAttributes ERASE_MARKER = new TextAttributes();
|
||||
|
||||
private boolean myEnforcedDefaults = false;
|
||||
|
||||
/**
|
||||
* Merges (layers) the two given text attributes.
|
||||
*
|
||||
@@ -175,6 +177,10 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
|
||||
return getForegroundColor() == null && getBackgroundColor() == null && getEffectColor() == null && getFontType() == Font.PLAIN;
|
||||
}
|
||||
|
||||
public boolean isFallbackEnabled() {
|
||||
return isEmpty() && !myEnforcedDefaults;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setForegroundColor(null);
|
||||
setBackgroundColor(null);
|
||||
@@ -251,6 +257,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
|
||||
public TextAttributes clone() {
|
||||
TextAttributes cloned = new TextAttributes();
|
||||
cloned.myAttrs = myAttrs;
|
||||
cloned.myEnforcedDefaults = myEnforcedDefaults;
|
||||
return cloned;
|
||||
}
|
||||
|
||||
@@ -276,6 +283,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
|
||||
ext.EFFECT_COLOR,
|
||||
ext.getEffectType(),
|
||||
ext.ERROR_STRIPE_COLOR);
|
||||
if (isEmpty()) myEnforcedDefaults = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class DefaultLanguageHighlighterColors {
|
||||
public final static TextAttributesKey TEMPLATE_LANGUAGE_COLOR =
|
||||
TextAttributesKey.createTextAttributesKey("DEFAULT_TEMPLATE_LANGUAGE_COLOR", HighlighterColors.TEXT);
|
||||
public final static TextAttributesKey IDENTIFIER =
|
||||
TextAttributesKey.createTextAttributesKey("DEFAULT_IDENTIFIER");
|
||||
TextAttributesKey.createTextAttributesKey("DEFAULT_IDENTIFIER", HighlighterColors.TEXT);
|
||||
public final static TextAttributesKey NUMBER =
|
||||
TextAttributesKey.createTextAttributesKey("DEFAULT_NUMBER");
|
||||
public final static TextAttributesKey KEYWORD =
|
||||
|
||||
+1
-1
@@ -815,7 +815,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
|
||||
|
||||
@Override
|
||||
public boolean isInherited() {
|
||||
return myFallbackAttributes != null && getTextAttributes().isEmpty();
|
||||
return myFallbackAttributes != null && getTextAttributes().isFallbackEnabled();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-2
@@ -442,7 +442,7 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme {
|
||||
}
|
||||
|
||||
private boolean haveToWrite(final TextAttributesKey key, final TextAttributes value, final TextAttributes defaultAttribute) {
|
||||
if (key.getFallbackAttributeKey() != null && value.isEmpty()) return false;
|
||||
if (key.getFallbackAttributeKey() != null && value.isFallbackEnabled()) return false;
|
||||
boolean hasDefaultValue = value.equals(defaultAttribute);
|
||||
if (myParentScheme == null) return !hasDefaultValue;
|
||||
return true;
|
||||
@@ -559,7 +559,7 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme {
|
||||
if (fallbackKey == null) return null;
|
||||
if (myAttributesMap.containsKey(fallbackKey)) {
|
||||
TextAttributes fallbackAttributes = myAttributesMap.get(fallbackKey);
|
||||
if (fallbackAttributes != null && (!fallbackAttributes.isEmpty() || fallbackKey.getFallbackAttributeKey() == null)) {
|
||||
if (fallbackAttributes != null && (!fallbackAttributes.isFallbackEnabled() || fallbackKey.getFallbackAttributeKey() == null)) {
|
||||
return fallbackAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -60,12 +60,9 @@ public class EditorColorsSchemeImpl extends AbstractColorsScheme implements Exte
|
||||
if (attributes != null) return attributes;
|
||||
}
|
||||
else {
|
||||
if (attributes != null && !attributes.isEmpty()) return attributes;
|
||||
if (attributes != null && !attributes.isFallbackEnabled()) return attributes;
|
||||
attributes = getFallbackAttributes(fallbackKey);
|
||||
if (attributes != null) return attributes;
|
||||
if (myParentScheme instanceof DefaultColorsScheme && !DEFAULT_SCHEME_NAME.equals(getName())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return myParentScheme.getAttributes(key);
|
||||
|
||||
Reference in New Issue
Block a user