Skip to content

Commit 6f28d1f

Browse files
Color settings dialog
1 parent bf4ce07 commit 6f28d1f

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Plugin is compatible with IntelliJ IDEA 2016.1. Other JetBrains IDEs of the same
2323
- [x] keywords
2424
- [x] enum constants
2525
- [x] scalar value types (currently they are not keywords)
26-
- [ ] color settings
26+
- [x] color settings
2727

2828
### Build
2929

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

src/main/java/io/protostuff/jetbrains/plugin/ProtoSyntaxHighlighter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
* for bad characters HighlighterColors.BAD_CHARACTER can be used."
3737
*/
3838
public class ProtoSyntaxHighlighter extends SyntaxHighlighterBase {
39-
public static final TextAttributesKey ID =
40-
createTextAttributesKey("PROTO_ID", DefaultLanguageHighlighterColors.IDENTIFIER);
39+
4140
public static final TextAttributesKey KEYWORD =
4241
createTextAttributesKey("PROTO_KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);
4342
public static final TextAttributesKey STRING =

src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
implementationClass="io.protostuff.jetbrains.plugin.ProtoSyntaxHighlighterFactory"/>
4040
<annotator language="Protobuf"
4141
implementationClass="io.protostuff.jetbrains.plugin.ProtoSyntaxKeywordsAnnotator"/>
42+
43+
<colorSettingsPage implementation="io.protostuff.jetbrains.plugin.ProtoColorSettingsPage"/>
44+
4245
</extensions>
4346

4447
<actions>

0 commit comments

Comments
 (0)