Skip to content

Commit cbe9f70

Browse files
authored
Merge pull request #236 from SeeSharpSoft/fb_column_coloring
Column coloring & change note welcome
2 parents 63dfb65 + 4744d3e commit cbe9f70

File tree

19 files changed

+386
-107
lines changed

19 files changed

+386
-107
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2.14.0
2+
3+
NEW: Predefined column colors (Rainbow-style)
4+
NEW: Enhanced color scheme switch
5+
NEW: Table Editor coloring
6+
17
2.13.0
28
Jul 20, 2020
39

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ Please note:
155155

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

158+
##### Value coloring
159+
160+
Choose the coloring method of values. Possible options are:
161+
162+
- _Rainbow (Column Color)_ - values are colored based on their column.
163+
- _Simple (Text Color)_ - values are colored based on the defined text color.
164+
165+
All colors can be adjusted via [CSV Color Scheme](#color-scheme) settings.
166+
158167
#### Text Editor
159168

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

164173
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.
165174

166-
###### Enable column highlighting
167-
168-
An easy way to switch *Column Highlighting* on or off (in text editor).
169-
170175
###### Highlight tab separator
171176

172177
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.
@@ -205,7 +210,7 @@ The maximum width of a single table column in _px_, which is used when adjusting
205210

206211
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.
207212

208-
##### Keep/ignore linebreak at end of file
213+
##### Keep/ignore linebreak at file end
209214

210215
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.
211216

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

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

220-
##### Enable column highlighting
221-
222-
An easy way to switch *Column Highlighting* on or off (in table editor).
223-
224225
### Color Scheme
225226

226-
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:
227+
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:
227228

228-
- _File > Settings > Editor > Color Scheme > CSV_
229+
- _File > Settings > Editor > Color Scheme > CSV/TSV/PSV_
229230

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

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

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

236-
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.
237241

238242
### Formatting
239243

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jacocoTestReport {
2424
}
2525

2626
group 'net.seesharpsoft.intellij.plugins'
27-
version '2.13.0'
27+
version '2.14.0'
2828

2929
apply plugin: 'java'
3030
sourceCompatibility = javaVersion

docs/colorsettings.png

-3.6 KB
Loading

docs/example.png

-3.19 KB
Loading

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.seesharpsoft.intellij.plugins.csv;
22

3-
import com.intellij.ide.scratch.ScratchFileType;
43
import com.intellij.ide.scratch.ScratchUtil;
54
import com.intellij.lang.*;
65
import com.intellij.lexer.Lexer;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package net.seesharpsoft.intellij.plugins.csv;
2+
3+
import com.intellij.ide.actions.ShowSettingsUtilImpl;
4+
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl;
5+
import com.intellij.ide.plugins.PluginManager;
6+
import com.intellij.notification.*;
7+
import com.intellij.openapi.extensions.PluginId;
8+
import com.intellij.openapi.options.ShowSettingsUtil;
9+
import com.intellij.openapi.project.Project;
10+
import com.intellij.openapi.startup.StartupActivity;
11+
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
12+
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettingsProvider;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
import javax.swing.event.HyperlinkEvent;
16+
import java.awt.*;
17+
import java.io.IOException;
18+
import java.net.URI;
19+
20+
public class CsvPlugin implements StartupActivity {
21+
22+
protected static IdeaPluginDescriptorImpl getPluginDescriptor() {
23+
return (IdeaPluginDescriptorImpl)PluginManager.getPlugin(PluginId.getId("net.seesharpsoft.intellij.plugins.csv"));
24+
}
25+
26+
protected static String getVersion() {
27+
return getPluginDescriptor().getVersion();
28+
}
29+
30+
protected static String getChangeNotes() {
31+
return getPluginDescriptor().getChangeNotes();
32+
}
33+
34+
private static void openLink(Project project, String link) {
35+
if (!project.isDisposed() && link.startsWith("#")) {
36+
((ShowSettingsUtilImpl)ShowSettingsUtil.getInstance()).showSettingsDialog(project, link.substring(1), null);
37+
}
38+
if (Desktop.isDesktopSupported()) {
39+
Desktop desktop = Desktop.getDesktop();
40+
if (desktop.isSupported(Desktop.Action.BROWSE)) {
41+
try {
42+
desktop.browse(URI.create(link));
43+
} catch (IOException e) {
44+
e.printStackTrace();
45+
}
46+
}
47+
}
48+
}
49+
50+
@Override
51+
public void runActivity(@NotNull Project project) {
52+
if (CsvEditorSettings.getInstance().checkCurrentPluginVersion(getVersion())) {
53+
return;
54+
}
55+
56+
NotificationGroup notificationGroup = new NotificationGroup(
57+
"CsvPlugin", NotificationDisplayType.STICKY_BALLOON, true
58+
);
59+
60+
NotificationListener.Adapter notificationListener = new NotificationListener.Adapter() {
61+
@Override
62+
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
63+
openLink(project, e.getDescription());
64+
}
65+
};
66+
67+
Notification notification = notificationGroup.createNotification(
68+
"CSV Plugin " + getVersion() + " - Change Notes",
69+
getChangeNotes() +
70+
"<p><b>Customize plugin settings:</b> " +
71+
"<a href=\"#" + CsvEditorSettingsProvider.CSV_EDITOR_SETTINGS_ID + "\">Editor/General</a>, " +
72+
"<a href=\"#reference.settingsdialog.IDE.editor.colors.CSV/TSV/PSV\">Color Scheme</a>, " +
73+
"<a href=\"#preferences.sourceCode.CSV/TSV/PSV\">Formatting</a></p>" +
74+
"<br>" +
75+
"<p>Visit the <a href=\"https://github.com/SeeSharpSoft/intellij-csv-validator\">CSV Plugin GitHub</a> to read more about the available features & settings, " +
76+
"submit <a href=\"https://github.com/SeeSharpSoft/intellij-csv-validator/issues\">issues & feature request</a>, " +
77+
"or show your support by <a href=\"https://plugins.jetbrains.com/plugin/10037-csv-plugin\">rating this plugin</a>. <b>Thanks!</b></p>"
78+
,
79+
NotificationType.INFORMATION,
80+
notificationListener
81+
);
82+
83+
Notifications.Bus.notify(notification);
84+
}
85+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio
6767

6868
Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip);
6969
annotation.setEnforcedTextAttributes(
70-
CsvEditorSettings.getInstance().isColumnHighlightingEnabled() ?
70+
CsvEditorSettings.getInstance().getValueColoring() == CsvEditorSettings.ValueColoring.RAINBOW ?
7171
CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) :
7272
null
7373
);

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;
22

33
import com.intellij.openapi.editor.colors.EditorColorsManager;
4+
import com.intellij.openapi.editor.colors.EditorColorsScheme;
45
import com.intellij.openapi.project.Project;
56
import com.intellij.openapi.vfs.VirtualFile;
67
import com.intellij.psi.PsiElement;
@@ -94,6 +95,8 @@ protected void createUIComponents() {
9495
}
9596

9697
private void initializedUIComponents() {
98+
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
99+
97100
btnRedo.addActionListener(tableEditorActions.redo);
98101
btnUndo.addActionListener(tableEditorActions.undo);
99102
btnAddRow.addActionListener(tableEditorActions.addRow);
@@ -129,6 +132,8 @@ private void initializedUIComponents() {
129132
tblEditor.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
130133
tblEditor.setShowColumns(true);
131134
tblEditor.setFont(getFont());
135+
tblEditor.setBackground(editorColorsScheme.getDefaultBackground());
136+
tblEditor.setForeground(editorColorsScheme.getDefaultForeground());
132137
setTableRowHeight(0);
133138

134139
tblEditor.getColumnModel().addColumnModelListener(tableEditorListener);

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;
22

33
import com.intellij.openapi.editor.colors.EditorColorsManager;
4+
import com.intellij.openapi.editor.colors.EditorColorsScheme;
45
import com.intellij.openapi.editor.colors.EditorFontType;
56
import com.intellij.openapi.editor.impl.FontFallbackIterator;
67
import com.intellij.openapi.editor.markup.TextAttributes;
78
import com.intellij.openapi.util.UserDataHolder;
89
import com.intellij.ui.components.JBScrollPane;
910
import com.intellij.util.ui.UIUtil;
10-
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
1111
import net.seesharpsoft.intellij.plugins.csv.settings.CsvColorSettings;
1212
import org.jetbrains.annotations.NotNull;
1313

@@ -46,10 +46,7 @@ public MultiLineCellRenderer(CsvTableEditorKeyListener keyListener, UserDataHold
4646
}
4747

4848
private TextAttributes getColumnTextAttributes(int column) {
49-
if (CsvEditorSettings.getInstance().isTableColumnHighlightingEnabled()) {
50-
return CsvColorSettings.getTextAttributesOfColumn(column, myUserDataHolder);
51-
}
52-
return null;
49+
return CsvColorSettings.getTextAttributesOfColumn(column, myUserDataHolder);
5350
}
5451

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

6562
@Override
6663
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
64+
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
65+
6766
if (isSelected) {
6867
myTextArea.setForeground(table.getSelectionForeground());
6968
myTextArea.setBackground(table.getSelectionBackground());
@@ -74,8 +73,8 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
7473
if (hasFocus) {
7574
myTextArea.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
7675
if (table.isCellEditable(row, column)) {
77-
myTextArea.setForeground(UIManager.getColor("Table.focusCellForeground"));
78-
myTextArea.setBackground(UIManager.getColor("Table.focusCellBackground"));
76+
myTextArea.setForeground(UIManager.getColor(editorColorsScheme.getDefaultForeground()));
77+
myTextArea.setBackground(UIManager.getColor(editorColorsScheme.getDefaultBackground()));
7978
}
8079
} else {
8180
myTextArea.setBorder(new EmptyBorder(1, 2, 1, 2));

0 commit comments

Comments
 (0)