Skip to content

Commit 3d99712

Browse files
committed
[FEATURE] enable/disable info balloons, test & code cleanup
Fixes #62
1 parent 82ee540 commit 3d99712

File tree

7 files changed

+59
-22
lines changed

7 files changed

+59
-22
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
public class CsvAnnotator implements Annotator {
2929

3030
protected static final Integer MAX_COLUMN_HIGHLIGHT_COLORS = 10;
31-
protected static final Key<Integer> MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS = Key.create("CSV_LAST_DEFINED_COLOR_INDEX_KEY");
32-
protected static final Key<TextAttributes> TAB_SEPARATOR_HIGHLIGHT_COLOR = Key.create("CSV_TAB_SEPARATOR_HIGHLIGHT_COLOR");
33-
protected static final Key<Boolean> TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED = Key.create("CSV_TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED");
31+
protected static final Key<Integer> MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS = Key.create("CSV_PLUGIN_LAST_DEFINED_COLOR_INDEX_KEY");
32+
protected static final Key<TextAttributes> TAB_SEPARATOR_HIGHLIGHT_COLOR = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR");
33+
protected static final Key<Boolean> TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED");
34+
protected static final Key<Boolean> SHOW_INFO_BALLOON = Key.create("CSV_PLUGIN_SHOW_INFO_BALLOON");
3435

3536
public static final ColorDescriptor[] COLOR_DESCRIPTORS;
3637

@@ -63,13 +64,16 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio
6364
if (columnInfo != null) {
6465
PsiElement headerElement = columnInfo.getHeaderElement();
6566
String message = XmlStringUtil.escapeString(headerElement == null ? "" : headerElement.getText(), true);
66-
String tooltip = XmlStringUtil.wrapInHtml(
67-
String.format("%s<br /><br />Header: %s<br />Index: %d",
68-
XmlStringUtil.escapeString(element.getText(), true),
69-
message,
70-
columnInfo.getColumnIndex()
71-
)
72-
);
67+
String tooltip = null;
68+
if (showInfoBalloon(holder.getCurrentAnnotationSession())) {
69+
tooltip = XmlStringUtil.wrapInHtml(
70+
String.format("%s<br /><br />Header: %s<br />Index: %d",
71+
XmlStringUtil.escapeString(element.getText(), true),
72+
message,
73+
columnInfo.getColumnIndex()
74+
)
75+
);
76+
}
7377
TextRange textRange = columnInfo.getRowInfo(element).getTextRange();
7478
if (textRange.getStartOffset() - csvFile.getTextLength() == 0 && textRange.getStartOffset() > 0) {
7579
textRange = TextRange.from(textRange.getStartOffset() - 1, 1);
@@ -81,6 +85,15 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio
8185
}
8286
}
8387

88+
protected boolean showInfoBalloon(@NotNull AnnotationSession annotationSession) {
89+
Boolean showInfoBalloon = annotationSession.getUserData(SHOW_INFO_BALLOON);
90+
if (showInfoBalloon == null) {
91+
showInfoBalloon = CsvEditorSettingsExternalizable.getInstance().isShowInfoBalloon();
92+
annotationSession.putUserData(SHOW_INFO_BALLOON, showInfoBalloon);
93+
}
94+
return showInfoBalloon;
95+
}
96+
8497
protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull AnnotationHolder holder, IElementType elementType, CsvFile csvFile) {
8598
if (elementType == CsvTypes.COMMA) {
8699
TextAttributes textAttributes = holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR);

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static final class OptionSet {
2424
public boolean USE_SOFT_WRAP;
2525
public boolean COLUMN_HIGHTLIGHTING;
2626
public boolean HIGHTLIGHT_TAB_SEPARATOR;
27+
public boolean SHOW_INFO_BALLOON;
2728
public String TAB_HIGHLIGHT_COLOR;
2829

2930
public OptionSet() {
@@ -32,6 +33,7 @@ public OptionSet() {
3233
USE_SOFT_WRAP = editorSettingsExternalizable.isUseSoftWraps();
3334
COLUMN_HIGHTLIGHTING = false;
3435
HIGHTLIGHT_TAB_SEPARATOR = true;
36+
SHOW_INFO_BALLOON = true;
3537
TAB_HIGHLIGHT_COLOR = "-7984";
3638
}
3739
}
@@ -94,6 +96,13 @@ public void setHighlightTabSeparator(boolean highlightTabSeparator) {
9496
getState().HIGHTLIGHT_TAB_SEPARATOR = highlightTabSeparator;
9597
}
9698

99+
public boolean isShowInfoBalloon() {
100+
return getState().SHOW_INFO_BALLOON;
101+
}
102+
public void setShowInfoBalloon(boolean showInfoBalloon) {
103+
getState().SHOW_INFO_BALLOON = showInfoBalloon;
104+
}
105+
97106
public Color getTabHighlightColor() {
98107
String color = getState().TAB_HIGHLIGHT_COLOR;
99108
try {

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<title-color color="-16777216"/>
1414
</border>
1515
<children>
16-
<grid id="d2422" binding="panelHighlighting" layout-manager="GridLayoutManager" row-count="5" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
16+
<grid id="d2422" layout-manager="GridLayoutManager" row-count="5" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1717
<margin top="10" left="10" bottom="10" right="10"/>
1818
<constraints>
1919
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -50,7 +50,7 @@
5050
</hspacer>
5151
</children>
5252
</grid>
53-
<grid id="6ba47" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
53+
<grid id="6ba47" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
5454
<margin top="10" left="10" bottom="10" right="10"/>
5555
<constraints>
5656
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -60,17 +60,25 @@
6060
<children>
6161
<component id="6fb36" class="javax.swing.JCheckBox" binding="cbUseSoftWraps">
6262
<constraints>
63-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
63+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
6464
</constraints>
6565
<properties>
6666
<text value="Use soft wraps"/>
6767
</properties>
6868
</component>
6969
<hspacer id="d39ae">
7070
<constraints>
71-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
71+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
7272
</constraints>
7373
</hspacer>
74+
<component id="a3d49" class="javax.swing.JCheckBox" binding="cbShowInfoBalloonCheckBox">
75+
<constraints>
76+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
77+
</constraints>
78+
<properties>
79+
<text value="Show info balloon"/>
80+
</properties>
81+
</component>
7482
</children>
7583
</grid>
7684
<vspacer id="ff292">

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class CsvEditorSettingsProvider implements SearchableConfigurable {
1515
private JPanel myMainPanel;
1616
private JCheckBox cbUseSoftWraps;
1717
private JCheckBox cbColumnHighlighting;
18-
private JPanel panelHighlighting;
1918
private CheckBoxWithColorChooser cbTabHighlightColor;
19+
private JCheckBox cbShowInfoBalloonCheckBox;
2020

2121
@NotNull
2222
@Override
@@ -52,6 +52,7 @@ public boolean isModified() {
5252
isModified(cbUseSoftWraps, csvEditorSettingsExternalizable.isUseSoftWraps()) ||
5353
isModified(cbColumnHighlighting, csvEditorSettingsExternalizable.isColumnHighlightingEnabled()) ||
5454
cbTabHighlightColor.isSelected() != csvEditorSettingsExternalizable.isHighlightTabSeparator() ||
55+
cbShowInfoBalloonCheckBox.isSelected() != csvEditorSettingsExternalizable.isShowInfoBalloon() ||
5556
!Objects.equals(cbTabHighlightColor.getColor(), csvEditorSettingsExternalizable.getTabHighlightColor());
5657
}
5758

@@ -62,6 +63,7 @@ public void reset() {
6263
cbUseSoftWraps.setSelected(csvEditorSettingsExternalizable.isUseSoftWraps());
6364
cbColumnHighlighting.setSelected(csvEditorSettingsExternalizable.isColumnHighlightingEnabled());
6465
cbTabHighlightColor.setSelected(csvEditorSettingsExternalizable.isHighlightTabSeparator());
66+
cbShowInfoBalloonCheckBox.setSelected(csvEditorSettingsExternalizable.isShowInfoBalloon());
6567
cbTabHighlightColor.setColor(csvEditorSettingsExternalizable.getTabHighlightColor());
6668
}
6769

@@ -72,11 +74,11 @@ public void apply() throws ConfigurationException {
7274
csvEditorSettingsExternalizable.setUseSoftWraps(cbUseSoftWraps.isSelected());
7375
csvEditorSettingsExternalizable.setColumnHighlightingEnabled(cbColumnHighlighting.isSelected());
7476
csvEditorSettingsExternalizable.setHighlightTabSeparator(cbTabHighlightColor.isSelected());
77+
csvEditorSettingsExternalizable.setShowInfoBalloon(cbShowInfoBalloonCheckBox.isSelected());
7578
csvEditorSettingsExternalizable.setTabHighlightColor(cbTabHighlightColor.getColor());
7679
}
7780

78-
79-
private void createUIComponents() {
81+
protected void createUIComponents() {
8082
cbTabHighlightColor = new CheckBoxWithColorChooser("Highlight tab separator ");
8183
cbTabHighlightColor.setColor(Color.CYAN);
8284
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/intention/CsvIntentionHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,9 @@ public static int getOpeningQuotePosition(PsiElement errorElement) {
189189
}
190190
lastFieldElement = lastFieldElement.getLastChild();
191191
if (CsvHelper.getElementType(lastFieldElement) != CsvTypes.FIELD) {
192-
throw new RuntimeException("Field element expected");
192+
throw new IllegalArgumentException("Field element expected");
193193
}
194194
return getOpeningQuotePosition(lastFieldElement.getFirstChild(), lastFieldElement.getLastChild());
195-
196195
}
197196

198197
public static PsiElement findQuotePositionsUntilSeparator(final PsiElement element, List<Integer> quotePositions) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
]]></description>
4141

4242
<change-notes><![CDATA[
43-
<b>NEW:</b> CSV/TSV editor settings (<i>File > Settings > General > CSV/TSV Editor)</i><br>
43+
<b>NEW:</b> CSV/TSV editor settings (<i>File > Settings > General > CSV/TSV Editor</i>)<br>
4444
<b>NEW:</b> TAB (separator) highlighting<br>
45-
<b>NEW:</b> Soft wrap settings specific for CSV/TSV</li>
46-
<b>NEW:</b> Customizable column coloring (<i>File > Settings > Editor > Color Scheme > CSV)</i><br>
45+
<b>NEW:</b> Enable/disable balloon info</li><br>
46+
<b>NEW:</b> Soft wrap settings specific for CSV/TSV</li><br>
47+
<b>NEW:</b> Customizable column coloring (<i>File > Settings > Editor > Color Scheme > CSV</i>)<br>
4748
<br><br>
4849
]]>
4950
</change-notes>

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProviderTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ public void testResetAndModified() throws ConfigurationException {
5353
CsvEditorSettingsProvider editorSettingsPanel = new CsvEditorSettingsProvider();
5454

5555
CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance();
56+
csvEditorSettingsExternalizable.loadState(new CsvEditorSettingsExternalizable.OptionSet());
5657
csvEditorSettingsExternalizable.setCaretRowShown(false);
5758
csvEditorSettingsExternalizable.setUseSoftWraps(true);
5859
csvEditorSettingsExternalizable.setColumnHighlightingEnabled(true);
5960
csvEditorSettingsExternalizable.setHighlightTabSeparator(false);
61+
csvEditorSettingsExternalizable.setShowInfoBalloon(false);
6062
csvEditorSettingsExternalizable.setTabHighlightColor(Color.BLACK);
6163

6264
assertEquals(true, editorSettingsPanel.isModified());
@@ -68,6 +70,7 @@ public void testResetAndModified() throws ConfigurationException {
6870
assertEquals(true, csvEditorSettingsExternalizable.isUseSoftWraps());
6971
assertEquals(true, csvEditorSettingsExternalizable.isColumnHighlightingEnabled());
7072
assertEquals(false, csvEditorSettingsExternalizable.isHighlightTabSeparator());
73+
assertEquals(false, csvEditorSettingsExternalizable.isShowInfoBalloon());
7174
assertEquals(Color.BLACK, csvEditorSettingsExternalizable.getTabHighlightColor());
7275

7376
editorSettingsPanel.disposeUIResources();
@@ -83,6 +86,7 @@ public void testApply() throws ConfigurationException {
8386
csvEditorSettingsExternalizable.setUseSoftWraps(true);
8487
csvEditorSettingsExternalizable.setColumnHighlightingEnabled(true);
8588
csvEditorSettingsExternalizable.setHighlightTabSeparator(false);
89+
csvEditorSettingsExternalizable.setShowInfoBalloon(false);
8690
csvEditorSettingsExternalizable.setTabHighlightColor(Color.BLACK);
8791

8892
editorSettingsPanel.apply();
@@ -94,6 +98,7 @@ public void testApply() throws ConfigurationException {
9498
assertEquals(freshOptionSet.USE_SOFT_WRAP, csvEditorSettingsExternalizable.isUseSoftWraps());
9599
assertEquals(freshOptionSet.COLUMN_HIGHTLIGHTING, csvEditorSettingsExternalizable.isColumnHighlightingEnabled());
96100
assertEquals(freshOptionSet.HIGHTLIGHT_TAB_SEPARATOR, csvEditorSettingsExternalizable.isHighlightTabSeparator());
101+
assertEquals(freshOptionSet.SHOW_INFO_BALLOON, csvEditorSettingsExternalizable.isShowInfoBalloon());
97102
assertEquals(freshOptionSet.TAB_HIGHLIGHT_COLOR, "" + csvEditorSettingsExternalizable.getTabHighlightColor().getRGB());
98103

99104
editorSettingsPanel.disposeUIResources();

0 commit comments

Comments
 (0)