Uncheck color selection boxes if colors are equal to base (fallback) attributes, reset the attributes to restore color inheritance.

This commit is contained in:
Rustam Vishnyakov
2012-12-26 18:27:27 +04:00
parent b7f872a4a6
commit 944eef001b
2 changed files with 42 additions and 1 deletions
@@ -162,6 +162,13 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
return getForegroundColor() == null && getBackgroundColor() == null && getEffectColor() == null && getFontType() == Font.PLAIN;
}
public void reset() {
setForegroundColor(null);
setBackgroundColor(null);
setEffectColor(null);
setFontType(Font.PLAIN);
}
@NotNull
public AttributesFlyweight getFlyweight() {
return myAttrs;
@@ -790,10 +790,44 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
return attributes;
}
private boolean equalToFallbackAttributes() {
if (myFallbackAttributes != null) {
return myFallbackAttributes.equals(getTextAttributes());
}
return false;
}
@Override
public boolean isBackgroundChecked() {
if (equalToFallbackAttributes()) return false;
return super.isBackgroundChecked();
}
@Override
public boolean isForegroundChecked() {
if (equalToFallbackAttributes()) return false;
return super.isForegroundChecked();
}
@Override
public boolean isErrorStripeChecked() {
if (equalToFallbackAttributes()) return false;
return super.isErrorStripeChecked();
}
@Override
public boolean isEffectsColorChecked() {
if (equalToFallbackAttributes()) return false;
return super.isEffectsColorChecked();
}
@Override
public void apply(EditorColorsScheme scheme) {
if (scheme == null) scheme = getScheme();
if (myAttributesToApply != null && !getTextAttributes().equals(myFallbackAttributes)) {
if (myAttributesToApply != null) {
if (equalToFallbackAttributes()) {
getTextAttributes().reset();
}
scheme.setAttributes(key, getTextAttributes());
}
}