A better way to provide backward compatibility with old color schemes

This commit is contained in:
Rustam Vishnyakov
2013-01-18 12:03:16 +04:00
parent f8ee2439a8
commit 74e96aebef
5 changed files with 13 additions and 8 deletions
@@ -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
@@ -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 =
@@ -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
@@ -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;
}
}
@@ -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);