Skip to content

Commit 58fe443

Browse files
committed
[FEATURE] settings added, README & plugin info updated
1 parent 6021213 commit 58fe443

File tree

5 files changed

+58
-39
lines changed

5 files changed

+58
-39
lines changed

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This enables default editor features like syntax validation, highlighting and in
2121
- intentions (Alt+Enter), e.g. Quote/Unquote (all), Shift Column Left/Right
2222
- structure view (header-entry layout)
2323
- support for ',', ';', '|' and '↹' as value separator
24+
- highlight of active column values
25+
- customizable column coloring
2426

2527
### Syntax parser & validation
2628

@@ -38,16 +40,6 @@ Please note that if a document is syntactically incorrect, other features like c
3840

3941
![Editor with syntax validation and highlighting](./docs/editor.png)
4042

41-
### Highlighting
42-
43-
The different symbols of a CSV document, namely the separator (comma), the quotes, the escaped literals and the text elements itself, are highlighted by a coloring scheme that can be customized:
44-
45-
- _File > Settings > Editor > Color Scheme > CSV_
46-
47-
Preset colors are based on Jetbrains IDE defaults and support the different UI themes.
48-
49-
![Color scheme settings](./docs/colorsettings.png)
50-
5143
### Separator
5244

5345
CSV files provide a high degree of flexibility and can be used universally for all kind of data.
@@ -63,6 +55,21 @@ Additionally the file type TSV was introduced as a kind of CSV language.
6355
For TSV files the same formatter and code style settings are applied as for CSV itself, but the separator is considered to be a tab.
6456
All functionality that is available for plain CSV files (inspections, intentions, structure view, etc.) can be used for TSV as well.
6557

58+
### Highlighting
59+
60+
The different symbols of a CSV document, namely the separator (comma), the quotes, the escaped literals and the text elements itself, are highlighted by a coloring scheme that can be customized:
61+
62+
- _File > Settings > Editor > Color Scheme > CSV_
63+
64+
Preset colors are based on Jetbrains IDE defaults and support the different UI themes.
65+
66+
![Color scheme settings](./docs/colorsettings.png)
67+
68+
#### Column Highlighting Colors
69+
70+
**NEW**
71+
Besides defining colors and font-style variants for the different CSV symbols, additionally up to 10 different column highlight colors can be defined. Those colors are applied to the columns round robin. Undefined column highlight colors will be skipped if they are not followed by any other color definition.
72+
6673
### Formatting
6774

6875
- _File > Settings > Editor > Code Style > CSV_

docs/colorsettings.png

27.6 KB
Loading

src/main/java/net/seesharpsoft/intellij/plugins/csv/annotation/CsvAnnotator.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package net.seesharpsoft.intellij.plugins.csv.annotation;
22

3-
import com.intellij.lang.annotation.Annotation;
4-
import com.intellij.lang.annotation.AnnotationHolder;
5-
import com.intellij.lang.annotation.Annotator;
6-
import com.intellij.lang.annotation.HighlightSeverity;
7-
import com.intellij.openapi.editor.markup.AttributesFlyweight;
3+
import com.intellij.lang.annotation.*;
4+
import com.intellij.openapi.editor.colors.ColorKey;
5+
import com.intellij.openapi.editor.colors.EditorColorsManager;
6+
import com.intellij.openapi.editor.colors.EditorColorsScheme;
87
import com.intellij.openapi.editor.markup.TextAttributes;
8+
import com.intellij.openapi.options.colors.ColorDescriptor;
9+
import com.intellij.openapi.util.Key;
910
import com.intellij.openapi.util.TextRange;
1011
import com.intellij.psi.PsiElement;
1112
import com.intellij.xml.util.XmlStringUtil;
@@ -16,22 +17,25 @@
1617
import org.jetbrains.annotations.NotNull;
1718

1819
import java.awt.*;
20+
import java.util.ArrayList;
21+
import java.util.List;
1922

2023
import static com.intellij.spellchecker.SpellCheckerSeveritiesProvider.TYPO;
2124

25+
@SuppressWarnings("MagicNumber")
2226
public class CsvAnnotator implements Annotator {
2327

24-
public static final TextAttributes[] COLUMNS = new TextAttributes[] {
25-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, null, 0, null, null, null)),
26-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(240, 240, 240), 0, null, null, null)),
27-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(255, 240, 240), 0, null, null, null)),
28-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(240, 255, 240), 0, null, null, null)),
29-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(240, 240, 255), 0, null, null, null)),
30-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(255, 255, 240), 0, null, null, null)),
31-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(255, 240, 255), 0, null, null, null)),
32-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(240, 255, 255), 0, null, null, null)),
33-
TextAttributes.fromFlyweight(AttributesFlyweight.create(null, new Color(255, 255, 255), 0, null, null, null)),
34-
};
28+
protected static final Integer MAX_COLUMN_HIGHLIGHT_COLORS = 10;
29+
protected static final Key<Integer> MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS = Key.create("CSV_LAST_DEFINED_COLOR_INDEX_KEY");
30+
31+
public static final ColorDescriptor[] COLOR_DESCRIPTORS;
32+
static {
33+
List<ColorDescriptor> colorDescriptorList = new ArrayList();
34+
for (int i = 0; i < MAX_COLUMN_HIGHLIGHT_COLORS; ++i) {
35+
colorDescriptorList.add(new ColorDescriptor(String.format("Column Highlighting Color %d", i + 1), ColorKey.createColorKey(String.format("CSV_COLUMN_COLOR_%d", i + 1), (Color) null), ColorDescriptor.Kind.BACKGROUND));
36+
}
37+
COLOR_DESCRIPTORS = colorDescriptorList.toArray(new ColorDescriptor[MAX_COLUMN_HIGHLIGHT_COLORS]);
38+
}
3539

3640
public static final HighlightSeverity CSV_COLUMN_INFO_SEVERITY =
3741
new HighlightSeverity("CSV_COLUMN_INFO_SEVERITY", TYPO.myVal + 5);
@@ -61,12 +65,26 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio
6165
}
6266

6367
Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip);
64-
annotation.setEnforcedTextAttributes(getTextAttributes(columnInfo));
68+
annotation.setEnforcedTextAttributes(getTextAttributes(holder.getCurrentAnnotationSession(), columnInfo));
6569
annotation.setNeedsUpdateOnTyping(false);
6670
}
6771
}
6872

69-
protected TextAttributes getTextAttributes(CsvColumnInfo<PsiElement> columnInfo) {
70-
return COLUMNS[columnInfo.getColumnIndex() % COLUMNS.length];
73+
protected TextAttributes getTextAttributes(AnnotationSession annotationSession, CsvColumnInfo<PsiElement> columnInfo) {
74+
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getSchemeForCurrentUITheme();
75+
Integer maxNoOfDefinedColumnHighlightColors = annotationSession.getUserData(MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS);
76+
if (maxNoOfDefinedColumnHighlightColors == null) {
77+
maxNoOfDefinedColumnHighlightColors = 0;
78+
for (int colorDescriptorIndex = 0; colorDescriptorIndex < COLOR_DESCRIPTORS.length; ++colorDescriptorIndex) {
79+
if (editorColorsScheme.getColor(COLOR_DESCRIPTORS[colorDescriptorIndex].getKey()) != null) {
80+
maxNoOfDefinedColumnHighlightColors = colorDescriptorIndex + 1;
81+
}
82+
}
83+
annotationSession.putUserData(MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS, maxNoOfDefinedColumnHighlightColors);
84+
}
85+
return maxNoOfDefinedColumnHighlightColors == 0 ? null :
86+
new TextAttributes(null,
87+
editorColorsScheme.getColor(COLOR_DESCRIPTORS[columnInfo.getColumnIndex() % maxNoOfDefinedColumnHighlightColors].getKey()),
88+
null, null, 0);
7189
}
7290
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.openapi.options.colors.ColorSettingsPage;
88
import net.seesharpsoft.intellij.plugins.csv.CsvIconProvider;
99
import net.seesharpsoft.intellij.plugins.csv.CsvLanguage;
10+
import net.seesharpsoft.intellij.plugins.csv.annotation.CsvAnnotator;
1011
import net.seesharpsoft.intellij.plugins.csv.highlighter.CsvSyntaxHighlighter;
1112
import org.jetbrains.annotations.NotNull;
1213
import org.jetbrains.annotations.Nullable;
@@ -60,7 +61,7 @@ public AttributesDescriptor[] getAttributeDescriptors() {
6061
@NotNull
6162
@Override
6263
public ColorDescriptor[] getColorDescriptors() {
63-
return ColorDescriptor.EMPTY_ARRAY;
64+
return CsvAnnotator.COLOR_DESCRIPTORS;
6465
}
6566

6667
@NotNull

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<li>structure view (header-entry layout)</li>
1919
<li>support for ',', ';', '|' or '&#8633;' as value separator</li>
2020
<li>highlight of active column values</li>
21+
<li>customizable column coloring</li>
2122
</ul>
2223
2324
<b>TSV file support:</b> <em>TSV files are recognized as such but treated as a variant of CSV files, the same syntax highlighting and code style settings are applied.</em>
@@ -37,15 +38,7 @@
3738
]]></description>
3839

3940
<change-notes><![CDATA[
40-
<b>NEW:</b> Custom 'Wrapping' settings<br>
41-
<b>NEW:</b> Column highlighter takes whitespaces into account<br>
42-
<b>NEW:</b> East Asian full-width character support for 'Tabularize' (optional) - disabled by default due to lower performance<br>
43-
<b>CHANGE:</b> Column highlighting only happens on selection<br>
44-
<b>FIX:</b> CSV column info tooltip trumps spellchecker tooltip (but keeps the visualization of a typo)<br>
45-
<b>FIX:</b> Show tooltip even when caret is at the last position withing the CSV file<br>
46-
<b>FIX:</b> Support for suppressing inspections not relevant for CSV (e.g. 'Problematic Whitespace')<br>
47-
<b>FIX:</b> Structure View: proper handling of <undefined> elements (instead of endless loading)<br>
48-
+ several code & performance improvements
41+
<b>NEW:</b> Customizable column coloring (<i>File > Settings > Editor > Color Scheme > CSV</i><br>
4942
<br><br>
5043
]]>
5144
</change-notes>

0 commit comments

Comments
 (0)