Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.14.0

NEW: Predefined column colors (Rainbow-style)
NEW: Enhanced color scheme switch
NEW: Table Editor coloring

2.13.0
Jul 20, 2020

Expand Down
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ Please note:

Enable zero-based column numbering. This affects the tooltip info of the text editor as well as column numbering of the table editor.

##### Value coloring

Choose the coloring method of values. Possible options are:

- _Rainbow (Column Color)_ - values are colored based on their column.
- _Simple (Text Color)_ - values are colored based on the defined text color.

All colors can be adjusted via [CSV Color Scheme](#color-scheme) settings.

#### Text Editor

##### Highlighting
Expand All @@ -163,10 +172,6 @@ Enable zero-based column numbering. This affects the tooltip info of the text ed

The highlighting of the current caret row might interfere with custom background color settings and can be enabled/disabled for CSV/TSV/PSV files here.

###### Enable column highlighting

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

###### Highlight tab separator

Enable/disable highlighting (and choose the highlight color) of tab characters (↹) in their role as value separator (TSV). Tabs as part of a value are therefore not highlighted on purpose.
Expand Down Expand Up @@ -205,7 +210,7 @@ The maximum width of a single table column in _px_, which is used when adjusting

If selected, the table column widths are adjusted based on the column contents automatically when the table editor is opened. This setting can be changed in the table editor itself per file.

##### Keep/ignore linebreak at end of file
##### Keep/ignore linebreak at file end

If the file ends with a completely empty line (no spaces or tabs either), the table editor will not show this line as empty values but ignore it. When table data is serialized, an existing empty line is kept at the end of the file.

Expand All @@ -217,23 +222,22 @@ Enables/disables the info panel at the bottom of the table editor.

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

##### 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:
The different symbols of a CSV document, namely the *separator* (e.g. comma, pipe, semicolon), the *quote* character, the *escaped literals* and the *text* elements itself, are colored based on the CSV color scheme settings:

- _File > Settings > Editor > Color Scheme > CSV_
- _File > Settings > Editor > Color Scheme > CSV/TSV/PSV_

Preset colors are based on Jetbrains IDE defaults and support the different UI themes.

![Color scheme settings](./docs/colorsettings.png)

#### Column Highlighting Colors
#### Column Colors

Besides the colors and font-style variants for the different CSV symbols, additionally up to 10 different column colors can be defined.
Those colors are applied to the columns round robin.
Column colors are taken into account when **Rainbow** is selected as [**Value Coloring**](#value-coloring) option in the [Editor Settings](#editor-settings).

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.

### Formatting

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jacocoTestReport {
}

group 'net.seesharpsoft.intellij.plugins'
version '2.13.0'
version '2.14.0'

apply plugin: 'java'
sourceCompatibility = javaVersion
Expand Down
Binary file modified docs/colorsettings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.seesharpsoft.intellij.plugins.csv;

import com.intellij.ide.scratch.ScratchFileType;
import com.intellij.ide.scratch.ScratchUtil;
import com.intellij.lang.*;
import com.intellij.lexer.Lexer;
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package net.seesharpsoft.intellij.plugins.csv;

import com.intellij.ide.actions.ShowSettingsUtilImpl;
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.notification.*;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettingsProvider;
import org.jetbrains.annotations.NotNull;

import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.io.IOException;
import java.net.URI;

public class CsvPlugin implements StartupActivity {

protected static IdeaPluginDescriptorImpl getPluginDescriptor() {
return (IdeaPluginDescriptorImpl)PluginManager.getPlugin(PluginId.getId("net.seesharpsoft.intellij.plugins.csv"));
}

protected static String getVersion() {
return getPluginDescriptor().getVersion();
}

protected static String getChangeNotes() {
return getPluginDescriptor().getChangeNotes();
}

private static void openLink(Project project, String link) {
if (!project.isDisposed() && link.startsWith("#")) {
((ShowSettingsUtilImpl)ShowSettingsUtil.getInstance()).showSettingsDialog(project, link.substring(1), null);
}
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(URI.create(link));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

@Override
public void runActivity(@NotNull Project project) {
if (CsvEditorSettings.getInstance().checkCurrentPluginVersion(getVersion())) {
return;
}

NotificationGroup notificationGroup = new NotificationGroup(
"CsvPlugin", NotificationDisplayType.STICKY_BALLOON, true
);

NotificationListener.Adapter notificationListener = new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
openLink(project, e.getDescription());
}
};

Notification notification = notificationGroup.createNotification(
"CSV Plugin " + getVersion() + " - Change Notes",
getChangeNotes() +
"<p><b>Customize plugin settings:</b> " +
"<a href=\"#" + CsvEditorSettingsProvider.CSV_EDITOR_SETTINGS_ID + "\">Editor/General</a>, " +
"<a href=\"#reference.settingsdialog.IDE.editor.colors.CSV/TSV/PSV\">Color Scheme</a>, " +
"<a href=\"#preferences.sourceCode.CSV/TSV/PSV\">Formatting</a></p>" +
"<br>" +
"<p>Visit the <a href=\"https://github.com/SeeSharpSoft/intellij-csv-validator\">CSV Plugin GitHub</a> to read more about the available features & settings, " +
"submit <a href=\"https://github.com/SeeSharpSoft/intellij-csv-validator/issues\">issues & feature request</a>, " +
"or show your support by <a href=\"https://plugins.jetbrains.com/plugin/10037-csv-plugin\">rating this plugin</a>. <b>Thanks!</b></p>"
,
NotificationType.INFORMATION,
notificationListener
);

Notifications.Bus.notify(notification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio

Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip);
annotation.setEnforcedTextAttributes(
CsvEditorSettings.getInstance().isColumnHighlightingEnabled() ?
CsvEditorSettings.getInstance().getValueColoring() == CsvEditorSettings.ValueColoring.RAINBOW ?
CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) :
null
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;

import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
Expand Down Expand Up @@ -94,6 +95,8 @@ protected void createUIComponents() {
}

private void initializedUIComponents() {
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();

btnRedo.addActionListener(tableEditorActions.redo);
btnUndo.addActionListener(tableEditorActions.undo);
btnAddRow.addActionListener(tableEditorActions.addRow);
Expand Down Expand Up @@ -129,6 +132,8 @@ private void initializedUIComponents() {
tblEditor.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tblEditor.setShowColumns(true);
tblEditor.setFont(getFont());
tblEditor.setBackground(editorColorsScheme.getDefaultBackground());
tblEditor.setForeground(editorColorsScheme.getDefaultForeground());
setTableRowHeight(0);

tblEditor.getColumnModel().addColumnModelListener(tableEditorListener);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;

import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.EditorFontType;
import com.intellij.openapi.editor.impl.FontFallbackIterator;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.UserDataHolder;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.ui.UIUtil;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvColorSettings;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -46,10 +46,7 @@ public MultiLineCellRenderer(CsvTableEditorKeyListener keyListener, UserDataHold
}

private TextAttributes getColumnTextAttributes(int column) {
if (CsvEditorSettings.getInstance().isTableColumnHighlightingEnabled()) {
return CsvColorSettings.getTextAttributesOfColumn(column, myUserDataHolder);
}
return null;
return CsvColorSettings.getTextAttributesOfColumn(column, myUserDataHolder);
}

private Color getColumnForegroundColor(int column, Color fallback) {
Expand All @@ -64,6 +61,8 @@ private Color getColumnBackgroundColor(int column, Color fallback) {

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();

if (isSelected) {
myTextArea.setForeground(table.getSelectionForeground());
myTextArea.setBackground(table.getSelectionBackground());
Expand All @@ -74,8 +73,8 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
if (hasFocus) {
myTextArea.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
if (table.isCellEditable(row, column)) {
myTextArea.setForeground(UIManager.getColor("Table.focusCellForeground"));
myTextArea.setBackground(UIManager.getColor("Table.focusCellBackground"));
myTextArea.setForeground(UIManager.getColor(editorColorsScheme.getDefaultForeground()));
myTextArea.setBackground(UIManager.getColor(editorColorsScheme.getDefaultBackground()));
}
} else {
myTextArea.setBorder(new EmptyBorder(1, 2, 1, 2));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.seesharpsoft.intellij.plugins.csv.settings;

import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.TextAttributesKey;
Expand All @@ -11,6 +10,7 @@
import com.intellij.openapi.options.colors.ColorSettingsPage;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolder;
import net.seesharpsoft.UnhandledSwitchCaseException;
import net.seesharpsoft.intellij.plugins.csv.CsvIconProvider;
import net.seesharpsoft.intellij.plugins.csv.highlighter.CsvSyntaxHighlighter;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,10 +25,10 @@

public class CsvColorSettings implements ColorSettingsPage {

private static final Integer MAX_COLUMN_HIGHLIGHT_COLORS = 10;
private static final Integer MAX_COLUMN_COLORING_COLORS = 10;
private static final AttributesDescriptor[] DESCRIPTORS;
private static final List<TextAttributesKey> COLUMN_HIGHLIGHT_ATTRIBUTES;
private static final Key<List<TextAttributes>> COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_HIGHLIGHT_ATTRIBUTES");
private static final List<TextAttributesKey> COLUMN_COLORING_ATTRIBUTES;
private static final Key<List<TextAttributes>> COLUMN_COLORING_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTES");

static {
List<AttributesDescriptor> attributesDescriptors = new ArrayList();
Expand All @@ -38,35 +38,51 @@ public class CsvColorSettings implements ColorSettingsPage {
attributesDescriptors.add(new AttributesDescriptor("Escaped Text", CsvSyntaxHighlighter.ESCAPED_TEXT));
attributesDescriptors.add(new AttributesDescriptor("Comment", CsvSyntaxHighlighter.COMMENT));

COLUMN_HIGHLIGHT_ATTRIBUTES = new ArrayList<>();
for (int i = 0; i < MAX_COLUMN_HIGHLIGHT_COLORS; ++i) {
TextAttributesKey textAttributesKey = createTextAttributesKey(String.format("CSV_COLUMN_HIGHLIGHT_ATTRIBUTE_%d", i + 1), DefaultLanguageHighlighterColors.STRING);
COLUMN_HIGHLIGHT_ATTRIBUTES.add(textAttributesKey);
attributesDescriptors.add(new AttributesDescriptor(String.format("Column Highlighting Color %d", i + 1), textAttributesKey));
COLUMN_COLORING_ATTRIBUTES = new ArrayList<>();
for (int i = 0; i < MAX_COLUMN_COLORING_COLORS; ++i) {
TextAttributesKey textAttributesKey = createTextAttributesKey(String.format("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTE_%d", i + 1), CsvSyntaxHighlighter.TEXT);
COLUMN_COLORING_ATTRIBUTES.add(textAttributesKey);
attributesDescriptors.add(new AttributesDescriptor(String.format("Column Color %d", i + 1), textAttributesKey));
}
DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[attributesDescriptors.size()]);
}

public static TextAttributes getTextAttributesOfColumn(int columnIndex, UserDataHolder userDataHolder) {
List<TextAttributes> textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY);
List<TextAttributes> textAttributeList = userDataHolder.getUserData(COLUMN_COLORING_TEXT_ATTRIBUTES_KEY);
if (textAttributeList == null) {
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
textAttributeList = new ArrayList<>();
int maxIndex = 0;
for (int colorDescriptorIndex = 0; colorDescriptorIndex < MAX_COLUMN_HIGHLIGHT_COLORS; ++colorDescriptorIndex) {
TextAttributesKey textAttributesKey = COLUMN_HIGHLIGHT_ATTRIBUTES.get(colorDescriptorIndex);
TextAttributes textAttributes = editorColorsScheme.getAttributes(textAttributesKey);
textAttributeList.add(textAttributes);
if (!textAttributesKey.getDefaultAttributes().equals(textAttributes)) {
maxIndex = colorDescriptorIndex;
}
switch(CsvEditorSettings.getInstance().getValueColoring()) {
case RAINBOW:
maxIndex = applyColumnTextAttributes(editorColorsScheme, textAttributeList);
break;
case SIMPLE:
textAttributeList.add(editorColorsScheme.getAttributes(CsvSyntaxHighlighter.TEXT));
break;
default:
throw new UnhandledSwitchCaseException(CsvEditorSettings.getInstance().getValueColoring());
}
textAttributeList = textAttributeList.subList(0, maxIndex + 1);
userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList);
userDataHolder.putUserData(COLUMN_COLORING_TEXT_ATTRIBUTES_KEY, textAttributeList);
}
return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size());
}

private static int applyColumnTextAttributes(EditorColorsScheme editorColorsScheme, List<TextAttributes> textAttributeList) {
int maxIndex = 0;
TextAttributes defaultTextAttributes = editorColorsScheme.getAttributes(CsvSyntaxHighlighter.TEXT);
for (int colorDescriptorIndex = 0; colorDescriptorIndex < MAX_COLUMN_COLORING_COLORS; ++colorDescriptorIndex) {
TextAttributesKey textAttributesKey = COLUMN_COLORING_ATTRIBUTES.get(colorDescriptorIndex);
TextAttributes textAttributes = editorColorsScheme.getAttributes(textAttributesKey);
textAttributeList.add(textAttributes);
if (!textAttributes.equals(defaultTextAttributes)) {
maxIndex = colorDescriptorIndex;
}
}
return maxIndex;
}

@Nullable
@Override
public Icon getIcon() {
Expand All @@ -85,7 +101,7 @@ public String getDemoText() {
return "1,\"Eldon Base for stackable storage shelf, platinum\",Muhammed MacIntyre,3,-213.25,38.94,35,Nunavut,Storage & Organization,0.8\n" +
"2,\"1.7 Cubic Foot Compact \"\"Cube\"\" Office Refrigerators\",Barry French,293,457.81,208.16,68.02,Nunavut,Appliances,0.58\n" +
"3,\"Cardinal Slant-D® Ring Binder, Heavy Gauge Vinyl\",Barry French,293,46.71,8.69,2.99,Nunavut,Binders and Binder Accessories,0.39\n" +
"4,R380,Clay Rozendal,483,1198.97,195.99,3.99,Nunavut,Telephones and Communication,0.58\n" +
"#4,R380,Clay Rozendal,483,1198.97,195.99,3.99,Nunavut,Telephones and Communication,0.58\n" +
"5,Holmes HEPA Air Purifier,Carlos Soltero,515,30.94,21.78,5.94,Nunavut,Appliances,0.5";
}

Expand Down
Loading