|
| 1 | +package io.protostuff.jetbrains.plugin; |
| 2 | + |
| 3 | +import com.intellij.openapi.editor.colors.TextAttributesKey; |
| 4 | +import com.intellij.openapi.fileTypes.SyntaxHighlighter; |
| 5 | +import com.intellij.openapi.options.colors.AttributesDescriptor; |
| 6 | +import com.intellij.openapi.options.colors.ColorDescriptor; |
| 7 | +import com.intellij.openapi.options.colors.ColorSettingsPage; |
| 8 | +import org.jetbrains.annotations.NotNull; |
| 9 | +import org.jetbrains.annotations.Nullable; |
| 10 | + |
| 11 | +import javax.swing.*; |
| 12 | +import java.util.HashMap; |
| 13 | +import java.util.Map; |
| 14 | + |
| 15 | +public class ProtoColorSettingsPage implements ColorSettingsPage { |
| 16 | + private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{ |
| 17 | + new AttributesDescriptor("Keyword", ProtoSyntaxHighlighter.KEYWORD), |
| 18 | + new AttributesDescriptor("String", ProtoSyntaxHighlighter.STRING), |
| 19 | + new AttributesDescriptor("Number", ProtoSyntaxHighlighter.NUMBER), |
| 20 | + new AttributesDescriptor("Line comment", ProtoSyntaxHighlighter.LINE_COMMENT), |
| 21 | + new AttributesDescriptor("Block comment", ProtoSyntaxHighlighter.BLOCK_COMMENT), |
| 22 | + new AttributesDescriptor("Enum constant", ProtoSyntaxHighlighter.ENUM_CONSTANT) |
| 23 | + }; |
| 24 | + |
| 25 | + private Map<String, TextAttributesKey> additionalTags; |
| 26 | + |
| 27 | + public ProtoColorSettingsPage() { |
| 28 | + additionalTags = new HashMap<>(); |
| 29 | + additionalTags.put("keyword", ProtoSyntaxHighlighter.KEYWORD); |
| 30 | + additionalTags.put("constant", ProtoSyntaxHighlighter.ENUM_CONSTANT); |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + @Nullable |
| 35 | + @Override |
| 36 | + public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() { |
| 37 | + return additionalTags; |
| 38 | + } |
| 39 | + |
| 40 | + @Nullable |
| 41 | + @Override |
| 42 | + public Icon getIcon() { |
| 43 | + return Icons.PROTO_ICON; |
| 44 | + } |
| 45 | + |
| 46 | + @NotNull |
| 47 | + @Override |
| 48 | + public SyntaxHighlighter getHighlighter() { |
| 49 | + return new ProtoSyntaxHighlighter(); |
| 50 | + } |
| 51 | + |
| 52 | + @NotNull |
| 53 | + @Override |
| 54 | + public String getDemoText() { |
| 55 | + return |
| 56 | + "/* block comment */\n" + |
| 57 | + "<keyword>message</keyword> Foo {\n" + |
| 58 | + " // line comment\n" + |
| 59 | + " <keyword>optional</keyword> <keyword>int32</keyword> x = 1;\n\n" + |
| 60 | + " <keyword>enum</keyword> Bar {\n" + |
| 61 | + " <constant>CONSTANT</constant> = 0 [baz = \"daf\"];\n" + |
| 62 | + " }\n" + |
| 63 | + "}\n"; |
| 64 | + } |
| 65 | + |
| 66 | + @NotNull |
| 67 | + @Override |
| 68 | + public AttributesDescriptor[] getAttributeDescriptors() { |
| 69 | + return DESCRIPTORS; |
| 70 | + } |
| 71 | + |
| 72 | + @NotNull |
| 73 | + @Override |
| 74 | + public ColorDescriptor[] getColorDescriptors() { |
| 75 | + return ColorDescriptor.EMPTY_ARRAY; |
| 76 | + } |
| 77 | + |
| 78 | + @NotNull |
| 79 | + @Override |
| 80 | + public String getDisplayName() { |
| 81 | + return "Protobuf"; |
| 82 | + } |
| 83 | +} |
0 commit comments