Search in sources :

Example 1 with AbstractColorsScheme

use of com.intellij.openapi.editor.colors.impl.AbstractColorsScheme in project intellij-community by JetBrains.

the class EditorColorSchemeTestCase method serialize.

protected Element serialize(@NotNull EditorColorsScheme scheme) {
    Element root = new Element("scheme");
    ((AbstractColorsScheme) scheme).writeExternal(root);
    fixPlatformSpecificValues(root);
    root.removeChildren("metaInfo");
    return root;
}
Also used : AbstractColorsScheme(com.intellij.openapi.editor.colors.impl.AbstractColorsScheme) Element(org.jdom.Element)

Example 2 with AbstractColorsScheme

use of com.intellij.openapi.editor.colors.impl.AbstractColorsScheme in project intellij-community by JetBrains.

the class EditorColorSchemeTestCase method serializeWithFixedMeta.

protected Element serializeWithFixedMeta(@NotNull EditorColorsScheme scheme) {
    Element root = new Element("scheme");
    ((AbstractColorsScheme) scheme).writeExternal(root);
    fixPlatformSpecificValues(root);
    Element metaInfo = root.getChild("metaInfo");
    if (metaInfo != null) {
        metaInfo.getChildren().forEach((child) -> {
            Attribute name = child.getAttribute("name");
            if (!child.getName().equals("property") || name == null || !RainbowHighlighter.isRainbowKey(name.getValue())) {
                child.removeContent();
            }
        });
    }
    return root;
}
Also used : AbstractColorsScheme(com.intellij.openapi.editor.colors.impl.AbstractColorsScheme) Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 3 with AbstractColorsScheme

use of com.intellij.openapi.editor.colors.impl.AbstractColorsScheme in project intellij-community by JetBrains.

the class ColorSchemeActions method importScheme.

@Override
protected void importScheme(@NotNull String importerName) {
    if (tryImportWithImportHandler(importerName)) {
        return;
    }
    final SchemeImporter<EditorColorsScheme> importer = SchemeImporterEP.getImporter(importerName, EditorColorsScheme.class);
    if (importer != null) {
        VirtualFile importSource = SchemeImportUtil.selectImportSource(importer.getSourceExtensions(), getSchemesPanel(), null, "Choose " + importerName);
        if (importSource != null) {
            try {
                EditorColorsScheme imported = importer.importScheme(DefaultProjectFactory.getInstance().getDefaultProject(), importSource, getOptions().getSelectedScheme(), name -> {
                    String newName = SchemeNameGenerator.getUniqueName(name != null ? name : "Unnamed", candidate -> getSchemesPanel().getModel().containsScheme(candidate, false));
                    AbstractColorsScheme newScheme = new EditorColorsSchemeImpl(EmptyColorScheme.INSTANCE);
                    newScheme.setName(newName);
                    newScheme.setDefaultMetaInfo(EmptyColorScheme.INSTANCE);
                    return newScheme;
                });
                if (imported != null) {
                    getOptions().addImportedScheme(imported);
                }
            } catch (SchemeImportException e) {
                getSchemesPanel().showStatus("Import failed: " + e.getMessage(), MessageType.ERROR);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractColorsScheme(com.intellij.openapi.editor.colors.impl.AbstractColorsScheme) EditorColorsSchemeImpl(com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 4 with AbstractColorsScheme

use of com.intellij.openapi.editor.colors.impl.AbstractColorsScheme in project intellij-community by JetBrains.

the class ColorSchemeActions method exportScheme.

@Override
protected void exportScheme(@NotNull EditorColorsScheme scheme, @NotNull String exporterName) {
    EditorColorsScheme schemeToExport = scheme;
    if (scheme instanceof AbstractColorsScheme) {
        EditorColorsScheme parent = ((AbstractColorsScheme) scheme).getParentScheme();
        if (!(parent instanceof DefaultColorsScheme)) {
            schemeToExport = parent;
        }
    }
    if (schemeToExport.getName().startsWith(SchemeManager.EDITABLE_COPY_PREFIX)) {
        schemeToExport = (EditorColorsScheme) schemeToExport.clone();
        schemeToExport.setName(SchemeManager.getDisplayName(schemeToExport));
    }
    super.exportScheme(schemeToExport, exporterName);
}
Also used : AbstractColorsScheme(com.intellij.openapi.editor.colors.impl.AbstractColorsScheme) DefaultColorsScheme(com.intellij.openapi.editor.colors.impl.DefaultColorsScheme) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 5 with AbstractColorsScheme

use of com.intellij.openapi.editor.colors.impl.AbstractColorsScheme in project intellij-community by JetBrains.

the class EditorColorSchemeTestCase method doTestWriteRead.

@NotNull
protected Pair<EditorColorsScheme, TextAttributes> doTestWriteRead(@NotNull TextAttributesKey key, @NotNull TextAttributes attributes) {
    EditorColorsScheme defaultScheme = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME);
    EditorColorsScheme sourceScheme = (EditorColorsScheme) defaultScheme.clone();
    sourceScheme.setName("test");
    sourceScheme.setAttributes(key, attributes);
    Element root = new Element("scheme");
    ((AbstractColorsScheme) sourceScheme).writeExternal(root);
    EditorColorsScheme targetScheme = new EditorColorsSchemeImpl(defaultScheme);
    targetScheme.readExternal(root);
    assertEquals("test", targetScheme.getName());
    TextAttributes targetAttrs = targetScheme.getAttributes(key);
    return Pair.create(targetScheme, targetAttrs);
}
Also used : AbstractColorsScheme(com.intellij.openapi.editor.colors.impl.AbstractColorsScheme) EditorColorsSchemeImpl(com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl) Element(org.jdom.Element) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractColorsScheme (com.intellij.openapi.editor.colors.impl.AbstractColorsScheme)5 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)3 Element (org.jdom.Element)3 EditorColorsSchemeImpl (com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl)2 DefaultColorsScheme (com.intellij.openapi.editor.colors.impl.DefaultColorsScheme)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Attribute (org.jdom.Attribute)1 NotNull (org.jetbrains.annotations.NotNull)1