From d3c0acfb734068e32da0161b0353fd988c32990e Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Tue, 27 Jan 2015 18:00:36 +0300 Subject: [PATCH] Make Darcula one of default schemes, do not write attributes which are not different from default (parent) scheme --- colorSchemes/src/colorSchemes/Darcula.xml | 1652 ----------------- .../colors/impl/AbstractColorsScheme.java | 14 +- .../src/DefaultColorSchemesManager.xml | 1645 ++++++++++++++++ .../impl/EditorColorsSchemeImplTest.java | 36 + resources/src/META-INF/IdeaPlugin.xml | 2 - 5 files changed, 1689 insertions(+), 1660 deletions(-) delete mode 100644 colorSchemes/src/colorSchemes/Darcula.xml diff --git a/colorSchemes/src/colorSchemes/Darcula.xml b/colorSchemes/src/colorSchemes/Darcula.xml deleted file mode 100644 index 236f01df78dc..000000000000 --- a/colorSchemes/src/colorSchemes/Darcula.xml +++ /dev/null @@ -1,1652 +0,0 @@ - - - - diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java index d9dce154db7b..a2dd4a3e6300 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java @@ -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 list = new ArrayList(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); diff --git a/platform/platform-resources/src/DefaultColorSchemesManager.xml b/platform/platform-resources/src/DefaultColorSchemesManager.xml index 83962be2446e..68308311f723 100644 --- a/platform/platform-resources/src/DefaultColorSchemesManager.xml +++ b/platform/platform-resources/src/DefaultColorSchemesManager.xml @@ -1129,4 +1129,1649 @@ + + + + diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImplTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImplTest.java index 0d5abd1b77cb..675f6715f201 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImplTest.java @@ -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("", 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("", 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); + } } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index f04431fabb5d..3053f33b65b7 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -1196,8 +1196,6 @@ - -