add xml highlighting to svg files

This commit is contained in:
Konstantin Bulenkov
2017-06-12 14:44:05 +02:00
parent d4d6b2f305
commit 21cda60826
3 changed files with 62 additions and 23 deletions
+2 -2
View File
@@ -10,6 +10,6 @@
<orderEntry type="module" module-name="lang-api" />
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="library" name="Sanselan" level="project" />
<orderEntry type="module" module-name="xml-psi-impl" />
</component>
</module>
</module>
@@ -19,8 +19,6 @@ import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeConsumer;
import com.intellij.openapi.fileTypes.UserBinaryFileType;
import com.intellij.openapi.fileTypes.UserFileType;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import gnu.trove.THashSet;
@@ -44,17 +42,12 @@ final class ImageFileTypeManagerImpl extends ImageFileTypeManager {
@NonNls private static final String IMAGE_FILE_TYPE_NAME = "Images";
private static final String IMAGE_FILE_TYPE_DESCRIPTION = ImagesBundle.message("images.filetype.description");
private static final UserFileType imageFileType;
private static final UserFileType svgFileType;
static {
imageFileType = new ImageFileType();
imageFileType.setIcon(ImagesIcons.ImagesFileType);
imageFileType.setName(IMAGE_FILE_TYPE_NAME);
imageFileType.setDescription(IMAGE_FILE_TYPE_DESCRIPTION);
svgFileType = new SvgFileType();
svgFileType.setIcon(ImagesIcons.ImagesFileType);
svgFileType.setName("Scalable Vector Graphics");
svgFileType.setDescription("SVG images");
}
public boolean isImage(VirtualFile file) {
@@ -68,17 +61,6 @@ final class ImageFileTypeManagerImpl extends ImageFileTypeManager {
public static final class ImageFileType extends UserBinaryFileType {
}
public static final class SvgFileType extends UserFileType {
@Override
public SettingsEditor getEditor() {
return null;
}
@Override
public boolean isBinary() {
return false;
}
}
public void createFileTypes(final @NotNull FileTypeConsumer consumer) {
@@ -93,8 +75,6 @@ final class ImageFileTypeManagerImpl extends ImageFileTypeManager {
processed.add(IfsUtil.ICO_FORMAT.toLowerCase());
consumer.consume(imageFileType, StringUtil.join(processed, FileTypeConsumer.EXTENSION_DELIMITER));
if (Registry.is("ide.svg.editor")) {
consumer.consume(svgFileType, "svg");
}
consumer.consume(SvgFileType.INSTANCE, "svg");
}
}
@@ -0,0 +1,59 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.intellij.images.fileTypes.impl;
import com.intellij.ide.highlighter.XmlLikeFileType;
import com.intellij.lang.xml.XMLLanguage;
import icons.ImagesIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author Konstantin Bulenkov
*/
public final class SvgFileType extends XmlLikeFileType {
public static final SvgFileType INSTANCE = new SvgFileType();
private SvgFileType() {
super(XMLLanguage.INSTANCE);
}
@NotNull
@Override
public String getName() {
return "SVG";
}
@NotNull
@Override
public String getDescription() {
return "Scalable Vector Graphics";
}
@NotNull
@Override
public String getDefaultExtension() {
return "svg";
}
@Nullable
@Override
public Icon getIcon() {
return ImagesIcons.ImagesFileType;
}
}