Make Darcula one of default schemes, do not write attributes which are not different from default (parent) scheme

This commit is contained in:
Rustam Vishnyakov
2015-01-28 12:53:44 +03:00
parent e53f617c96
commit d3c0acfb73
5 changed files with 1689 additions and 1660 deletions
File diff suppressed because it is too large Load Diff
@@ -520,8 +520,12 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme {
writeColors(colorElements);
writeAttributes(attrElements);
parentNode.addContent(colorElements);
parentNode.addContent(attrElements);
if (colorElements.getChildren().size() > 0) {
parentNode.addContent(colorElements);
}
if (attrElements.getChildren().size() > 0) {
parentNode.addContent(attrElements);
}
}
private static void writeFontPreferences(@NotNull String key, @NotNull Element parent, @NotNull FontPreferences preferences) {
@@ -543,17 +547,15 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme {
private boolean haveToWrite(final TextAttributesKey key, final TextAttributes value, final TextAttributes defaultAttribute) {
if (key.getFallbackAttributeKey() != null && value.isFallbackEnabled()) return false;
boolean hasDefaultValue = value.equals(defaultAttribute);
if (myParentScheme == null) return !hasDefaultValue;
return true;
return !value.equals(defaultAttribute);
}
private void writeAttributes(Element attrElements) throws WriteExternalException {
List<TextAttributesKey> list = new ArrayList<TextAttributesKey>(myAttributesMap.keySet());
Collections.sort(list);
TextAttributes defaultAttr = new TextAttributes();
for (TextAttributesKey key: list) {
TextAttributes defaultAttr = myParentScheme != null ? myParentScheme.getAttributes(key) : new TextAttributes();
TextAttributes value = myAttributesMap.get(key);
if (!haveToWrite(key,value,defaultAttr)) continue;
Element element = new Element(OPTION_ELEMENT);
File diff suppressed because it is too large Load Diff
@@ -15,9 +15,16 @@
*/
package com.intellij.openapi.editor.colors.impl;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.FontPreferences;
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections;
@@ -160,4 +167,33 @@ public class EditorColorsSchemeImplTest extends LightPlatformCodeInsightTestCase
assertEquals(fontName2, myScheme.getConsoleFontName());
assertEquals(21, myScheme.getConsoleFontSize());
}
public void testWriteInheritedFromDefault() throws Exception {
EditorColorsScheme defaultScheme = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME);
EditorColorsScheme editorColorsScheme = (EditorColorsScheme)defaultScheme.clone();
editorColorsScheme.setName("test");
Element root = new Element("scheme");
editorColorsScheme.writeExternal(root);
root.removeChildren("option"); // Remove font options
assertXmlOutputEquals("<scheme name=\"test\" version=\"124\" parent_scheme=\"Default\" />", root);
}
public void testWriteInheritedFromDarcula() throws Exception {
EditorColorsScheme darculaScheme = EditorColorsManager.getInstance().getScheme("Darcula");
EditorColorsScheme editorColorsScheme = (EditorColorsScheme)darculaScheme.clone();
editorColorsScheme.setName("test");
Element root = new Element("scheme");
editorColorsScheme.writeExternal(root);
root.removeChildren("option"); // Remove font options
assertXmlOutputEquals("<scheme name=\"test\" version=\"124\" parent_scheme=\"Darcula\" />", root);
}
private static void assertXmlOutputEquals(String expected, Element root) throws IOException {
StringWriter writer = new StringWriter();
Format format = Format.getPrettyFormat();
format.setLineSeparator("\n");
new XMLOutputter(format).output(root, writer);
String actual = writer.toString();
assertEquals(expected, actual);
}
}
-2
View File
@@ -1196,8 +1196,6 @@
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.GroovyScriptMacro"/>
<bundledColorScheme path="/colorSchemes/Darcula"/>
<copyPastePreProcessor implementation="com.intellij.codeInsight.editorActions.StringLiteralCopyPasteProcessor"/>
<copyPastePostProcessor implementation="com.intellij.codeInsight.editorActions.JavaCopyPasteReferenceProcessor"/>