Skip to content

Commit

Permalink
Merge 035e196 into 44df9ee
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeSharpSoft committed Dec 21, 2018
2 parents 44df9ee + 035e196 commit ffead61
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 166 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
@@ -1,3 +1,11 @@
2.1.0
Dec 22, 2018

NEW: support column highlighting for table editor
NEW: support all kind of text attributes for column highlighting
NEW: table editor values not longer enforced to be quoted on save (customizable)
FIX: prevent backspace/delete erasing cell value while editing (table editor)

2.0.2
Dec 16, 2018

Expand Down
14 changes: 11 additions & 3 deletions README.md
Expand Up @@ -62,13 +62,13 @@ All functionality that is available for plain CSV files (inspections, intentions

### \*NEW\* Table Editor

The plugin provides editing of CSV files via a table editor since version 2.0.0. This editor is NOT related to the _Edit as table..._ functionality of [IntelliJ IDEA Ultimate/PhpStorm/DataGrip/etc.](https://www.jetbrains.com/help/phpstorm/editing-csv-and-tsv-files.html) and does not share any of its features or settings. It is a an alternative to the CSV text editor and not meant to replace or mirror the capabilities of the Jetbrains _"Data"_ tab.
The plugin provides editing of CSV files via a table editor since version 2.0.0. This editor is NOT related to the _Edit as table..._ functionality of [IntelliJ IDEA Ultimate/PhpStorm/DataGrip/etc.](https://www.jetbrains.com/help/phpstorm/editing-csv-and-tsv-files.html) and does not share any implementation or settings. It is a an alternative to the CSV text editor and not meant to replace or mirror the capabilities of the Jetbrains _"Data"_ tab.

**!!! IMPORTANT !!!**

The table editor requires a syntactically correct formatted CSV file. If the file can't be parsed, the table editor will be not available. The file needs to be fixed first via a text editor before it can be viewed and edited in the table editor.

**Using the table editor might change the format of the CSV file:** All fields will be surrounded by double quotes and any spaces that are not part of the content will be removed!
**Using the table editor might change the format of the CSV file:** Until version 2.1.0 all fields were surrounded by double quotes and any spaces that are not part of the content was removed! Since version 2.1.0 the default changed but the described behavior can still be enabled (see *Editor Settings -> Enforce value quoting*).

![Table editor](./docs/tableeditor.png)

Expand Down Expand Up @@ -119,7 +119,7 @@ The highlighting of the current caret row might interfere with custom background

###### Enable column highlighting

An easy way to switch the newly introduced *Column Highlighting* on or off.
An easy way to switch *Column Highlighting* on or off (in text editor).

###### Highlight tab separator

Expand All @@ -145,6 +145,14 @@ Defines how many lines of text are shown in one editor cell by default. *Auto* d

Enables/disables the info panel at the bottom of the table editor.

##### **NEW** Enforce value quoting

Always quotes a single value on save - even if not required.

##### **NEW** Enable column highlighting

An easy way to switch *Column Highlighting* on or off (in table editor).

### Color Scheme

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:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -3,7 +3,7 @@
# https://www.jetbrains.com/intellij-repository/snapshots

name='CSV Plugin'
pluginVersion=2.0.2
pluginVersion=2.1.0
javaVersion=1.8
javaTargetVersion=1.8
downloadIntellijSources=false
@@ -1,11 +1,7 @@
package net.seesharpsoft.intellij.plugins.csv.editor;

import com.intellij.lang.annotation.*;
import com.intellij.openapi.editor.colors.ColorKey;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
Expand All @@ -16,33 +12,17 @@
import net.seesharpsoft.intellij.plugins.csv.psi.CsvFile;
import net.seesharpsoft.intellij.plugins.csv.psi.CsvTypes;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvCodeStyleSettings;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvColorSettings;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

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

@SuppressWarnings("MagicNumber")
public class CsvAnnotator implements Annotator {

protected static final Integer MAX_COLUMN_HIGHLIGHT_COLORS = 10;
protected static final Key<Integer> MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS = Key.create("CSV_PLUGIN_LAST_DEFINED_COLOR_INDEX_KEY");
protected static final Key<TextAttributes> TAB_SEPARATOR_HIGHLIGHT_COLOR = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR");
protected static final Key<Boolean> TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED");
protected static final Key<Boolean> SHOW_INFO_BALLOON = Key.create("CSV_PLUGIN_SHOW_INFO_BALLOON");

public static final ColorDescriptor[] COLOR_DESCRIPTORS;

static {
List<ColorDescriptor> colorDescriptorList = new ArrayList();
for (int i = 0; i < MAX_COLUMN_HIGHLIGHT_COLORS; ++i) {
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));
}
COLOR_DESCRIPTORS = colorDescriptorList.toArray(new ColorDescriptor[MAX_COLUMN_HIGHLIGHT_COLORS]);
}
protected static final Key<TextAttributes> TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR");
protected static final Key<Boolean> TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED");
protected static final Key<Boolean> SHOW_INFO_BALLOON_KEY = Key.create("CSV_PLUGIN_SHOW_INFO_BALLOON");

public static final HighlightSeverity CSV_COLUMN_INFO_SEVERITY =
new HighlightSeverity("CSV_COLUMN_INFO_SEVERITY", TYPO.myVal + 5);
Expand Down Expand Up @@ -80,31 +60,35 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio
}

Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip);
annotation.setEnforcedTextAttributes(getTextAttributes(holder.getCurrentAnnotationSession(), columnInfo));
annotation.setEnforcedTextAttributes(
CsvEditorSettingsExternalizable.getInstance().isColumnHighlightingEnabled() ?
CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) :
null
);
annotation.setNeedsUpdateOnTyping(false);
}
}

protected boolean showInfoBalloon(@NotNull AnnotationSession annotationSession) {
Boolean showInfoBalloon = annotationSession.getUserData(SHOW_INFO_BALLOON);
Boolean showInfoBalloon = annotationSession.getUserData(SHOW_INFO_BALLOON_KEY);
if (showInfoBalloon == null) {
showInfoBalloon = CsvEditorSettingsExternalizable.getInstance().isShowInfoBalloon();
annotationSession.putUserData(SHOW_INFO_BALLOON, showInfoBalloon);
annotationSession.putUserData(SHOW_INFO_BALLOON_KEY, showInfoBalloon);
}
return showInfoBalloon;
}

protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull AnnotationHolder holder, IElementType elementType, CsvFile csvFile) {
if (elementType == CsvTypes.COMMA) {
TextAttributes textAttributes = holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR);
if (!Boolean.TRUE.equals(holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED))) {
TextAttributes textAttributes = holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY);
if (!Boolean.TRUE.equals(holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY))) {
String separator = CsvCodeStyleSettings.getCurrentSeparator(csvFile.getProject(), csvFile.getLanguage());
if (CsvEditorSettingsExternalizable.getInstance().isHighlightTabSeparator() && separator.equals(CsvCodeStyleSettings.TAB_SEPARATOR)) {
textAttributes = new TextAttributes(null,
CsvEditorSettingsExternalizable.getInstance().getTabHighlightColor(),
null, null, 0);
holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR, textAttributes);
holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED, Boolean.TRUE);
holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY, textAttributes);
holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY, Boolean.TRUE);
}
}
if (textAttributes != null) {
Expand All @@ -121,23 +105,5 @@ protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull A
return false;
}

protected TextAttributes getTextAttributes(AnnotationSession annotationSession, CsvColumnInfo<PsiElement> columnInfo) {
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
Integer maxNoOfDefinedColumnHighlightColors = annotationSession.getUserData(MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS);
if (maxNoOfDefinedColumnHighlightColors == null) {
maxNoOfDefinedColumnHighlightColors = 0;
if (CsvEditorSettingsExternalizable.getInstance().isColumnHighlightingEnabled()) {
for (int colorDescriptorIndex = 0; colorDescriptorIndex < COLOR_DESCRIPTORS.length; ++colorDescriptorIndex) {
if (editorColorsScheme.getColor(COLOR_DESCRIPTORS[colorDescriptorIndex].getKey()) != null) {
maxNoOfDefinedColumnHighlightColors = colorDescriptorIndex + 1;
}
}
}
annotationSession.putUserData(MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS, maxNoOfDefinedColumnHighlightColors);
}
return maxNoOfDefinedColumnHighlightColors == 0 ? null :
new TextAttributes(null,
editorColorsScheme.getColor(COLOR_DESCRIPTORS[columnInfo.getColumnIndex() % maxNoOfDefinedColumnHighlightColors].getKey()),
null, null, 0);
}

}
Expand Up @@ -38,6 +38,7 @@ public static final class OptionSet {
public String TAB_HIGHLIGHT_COLOR;
public EditorPrio EDITOR_PRIO;
public int TABLE_EDITOR_ROW_HEIGHT;
public boolean TABLE_COLUMN_HIGHTLIGHTING;

public boolean SHOW_TABLE_EDITOR_INFO_PANEL;
public boolean QUOTING_ENFORCED;
Expand All @@ -46,14 +47,15 @@ public OptionSet() {
EditorSettingsExternalizable editorSettingsExternalizable = EditorSettingsExternalizable.getInstance();
CARET_ROW_SHOWN = editorSettingsExternalizable.isCaretRowShown();
USE_SOFT_WRAP = editorSettingsExternalizable.isUseSoftWraps();
COLUMN_HIGHTLIGHTING = false;
COLUMN_HIGHTLIGHTING = true;
HIGHTLIGHT_TAB_SEPARATOR = true;
SHOW_INFO_BALLOON = true;
TAB_HIGHLIGHT_COLOR = "-7984";
EDITOR_PRIO = EditorPrio.TEXT_FIRST;
SHOW_TABLE_EDITOR_INFO_PANEL = true;
TABLE_EDITOR_ROW_HEIGHT = TABLE_EDITOR_DEFAULT_ROW_HEIGHT;
QUOTING_ENFORCED = false;
TABLE_COLUMN_HIGHTLIGHTING = true;
}
}

Expand Down Expand Up @@ -164,4 +166,11 @@ public boolean isQuotingEnforced() {
public void setQuotingEnforced(boolean quotingEnforced) {
getState().QUOTING_ENFORCED = quotingEnforced;
}

public boolean isTableColumnHighlightingEnabled() {
return getState().TABLE_COLUMN_HIGHTLIGHTING;
}
public void setTableColumnHighlightingEnabled(boolean columnHighlightingEnabled) {
getState().TABLE_COLUMN_HIGHTLIGHTING = columnHighlightingEnabled;
}
}
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="1180" height="578"/>
<xy x="20" y="20" width="1180" height="648"/>
</constraints>
<properties>
<enabled value="true"/>
Expand Down Expand Up @@ -91,14 +91,47 @@
</grid>
</children>
</grid>
<grid id="3e325" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="3e325" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="line" title="Table Editor"/>
<children>
<grid id="a07e0" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="bfa35" class="javax.swing.JLabel">
<constraints/>
<properties>
<text value="Textlines per row (default):"/>
</properties>
</component>
<component id="d6ab5" class="javax.swing.JComboBox" binding="cbRowHeight">
<constraints/>
<properties>
<model>
<item value="Auto"/>
<item value="1"/>
<item value="2"/>
<item value="3"/>
<item value="4"/>
<item value="5"/>
<item value="6"/>
<item value="7"/>
<item value="8"/>
<item value="9"/>
<item value="10"/>
</model>
</properties>
</component>
</children>
</grid>
<component id="97488" class="javax.swing.JCheckBox" binding="cbShowInfoPanel">
<constraints>
<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"/>
Expand All @@ -107,47 +140,27 @@
<text value="Show info panel"/>
</properties>
</component>
<component id="bfa35" class="javax.swing.JLabel">
<component id="d6a8e" class="javax.swing.JCheckBox" binding="cbQuotingEnforced">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Textlines per row (default):"/>
<text value="Enforce value quoting"/>
</properties>
</component>
<component id="d6ab5" class="javax.swing.JComboBox" binding="cbRowHeight">
<component id="f25dc" class="javax.swing.JCheckBox" binding="cbTableColumnHighlighting">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="Auto"/>
<item value="1"/>
<item value="2"/>
<item value="3"/>
<item value="4"/>
<item value="5"/>
<item value="6"/>
<item value="7"/>
<item value="8"/>
<item value="9"/>
<item value="10"/>
</model>
<text value="Enable column highlighting (Editor &gt; Color Scheme &gt; CSV &gt; Column Hightlighting Colors)"/>
</properties>
</component>
<hspacer id="a028b">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="d6a8e" class="javax.swing.JCheckBox" binding="cbQuotingEnforced">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Quote every value (even if not needed)"/>
</properties>
</component>
</children>
</grid>
<vspacer id="ff292">
Expand Down

0 comments on commit ffead61

Please sign in to comment.