From 37e6160d277fcbf4e271e81317349667f2e06d39 Mon Sep 17 00:00:00 2001 From: GeeK Date: Thu, 20 Dec 2018 21:21:41 +0100 Subject: [PATCH 1/7] [FEATURE] support all kind of text attributes for column highlighting --- .../plugins/csv/editor/CsvAnnotator.java | 63 ++++++++++--------- .../csv/settings/CsvColorSettingsPage.java | 27 +++++--- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java index 77d01431..081cdedb 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java @@ -1,13 +1,14 @@ package net.seesharpsoft.intellij.plugins.csv.editor; import com.intellij.lang.annotation.*; -import com.intellij.openapi.editor.colors.ColorKey; +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; 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.openapi.util.UserDataHolder; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import com.intellij.xml.util.XmlStringUtil; @@ -18,30 +19,29 @@ import net.seesharpsoft.intellij.plugins.csv.settings.CsvCodeStyleSettings; import org.jetbrains.annotations.NotNull; -import java.awt.*; import java.util.ArrayList; import java.util.List; +import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; 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 MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS = Key.create("CSV_PLUGIN_LAST_DEFINED_COLOR_INDEX_KEY"); - protected static final Key TAB_SEPARATOR_HIGHLIGHT_COLOR = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR"); - protected static final Key TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED"); - protected static final Key SHOW_INFO_BALLOON = Key.create("CSV_PLUGIN_SHOW_INFO_BALLOON"); + protected static final Key> COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_HIGHLIGHT_ATTRIBUTES"); + protected static final Key TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR"); + protected static final Key TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED"); + protected static final Key SHOW_INFO_BALLOON_KEY = Key.create("CSV_PLUGIN_SHOW_INFO_BALLOON"); - public static final ColorDescriptor[] COLOR_DESCRIPTORS; + public static final List COLUMN_HIGHLIGHT_ATTRIBUTES; static { - List colorDescriptorList = new ArrayList(); + COLUMN_HIGHLIGHT_ATTRIBUTES = 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)); + TextAttributesKey textAttributesKey = createTextAttributesKey(String.format("CSV_COLUMN_HIGHLIGHT_ATTRIBUTE_%d", i + 1), DefaultLanguageHighlighterColors.STRING); + COLUMN_HIGHLIGHT_ATTRIBUTES.add(textAttributesKey); } - COLOR_DESCRIPTORS = colorDescriptorList.toArray(new ColorDescriptor[MAX_COLUMN_HIGHLIGHT_COLORS]); } public static final HighlightSeverity CSV_COLUMN_INFO_SEVERITY = @@ -86,25 +86,25 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio } 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) { @@ -121,23 +121,24 @@ protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull A return false; } - protected TextAttributes getTextAttributes(AnnotationSession annotationSession, CsvColumnInfo columnInfo) { - EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); - Integer maxNoOfDefinedColumnHighlightColors = annotationSession.getUserData(MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS); - if (maxNoOfDefinedColumnHighlightColors == null) { - maxNoOfDefinedColumnHighlightColors = 0; + public static TextAttributes getTextAttributes(UserDataHolder userDataHolder, CsvColumnInfo columnInfo) { + EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getSchemeForCurrentUITheme(); + List textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY); + if (textAttributeList == null) { + textAttributeList = new ArrayList<>(); + int maxIndex = 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; + 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; } } } - annotationSession.putUserData(MAX_NO_OF_DEFINED_COLUMN_HIGHLIGHT_COLORS, maxNoOfDefinedColumnHighlightColors); + userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList.subList(0, maxIndex + 1)); } - return maxNoOfDefinedColumnHighlightColors == 0 ? null : - new TextAttributes(null, - editorColorsScheme.getColor(COLOR_DESCRIPTORS[columnInfo.getColumnIndex() % maxNoOfDefinedColumnHighlightColors].getKey()), - null, null, 0); + return textAttributeList.isEmpty() ? null : textAttributeList.get(columnInfo.getColumnIndex() % textAttributeList.size()); } } \ No newline at end of file diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java index af5314e0..21b9d271 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java @@ -13,16 +13,29 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Map; public class CsvColorSettingsPage implements ColorSettingsPage { - private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{ - new AttributesDescriptor("Separator", CsvSyntaxHighlighter.COMMA), - new AttributesDescriptor("Quote", CsvSyntaxHighlighter.QUOTE), - new AttributesDescriptor("Text", CsvSyntaxHighlighter.TEXT), - new AttributesDescriptor("Escaped Text", CsvSyntaxHighlighter.ESCAPED_TEXT), - }; + private static final AttributesDescriptor[] DESCRIPTORS; + + static { + List attributesDescriptors = new ArrayList(Arrays.asList( + new AttributesDescriptor("Separator", CsvSyntaxHighlighter.COMMA), + new AttributesDescriptor("Quote", CsvSyntaxHighlighter.QUOTE), + new AttributesDescriptor("Text", CsvSyntaxHighlighter.TEXT), + new AttributesDescriptor("Escaped Text", CsvSyntaxHighlighter.ESCAPED_TEXT) + )); + + List columnHighlightAttributes = CsvAnnotator.COLUMN_HIGHLIGHT_ATTRIBUTES; + for (int i = 0; i < columnHighlightAttributes.size(); ++i) { + attributesDescriptors.add(new AttributesDescriptor(String.format("Column Highlighting Color %d", i + 1), columnHighlightAttributes.get(i))); + } + DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[attributesDescriptors.size()]); + } @Nullable @Override @@ -61,7 +74,7 @@ public AttributesDescriptor[] getAttributeDescriptors() { @NotNull @Override public ColorDescriptor[] getColorDescriptors() { - return CsvAnnotator.COLOR_DESCRIPTORS; + return new ColorDescriptor[0]; } @NotNull From c0c1e84714cb1a17b2a4a71edb76b52a201b6c0e Mon Sep 17 00:00:00 2001 From: GeeK Date: Thu, 20 Dec 2018 22:45:38 +0100 Subject: [PATCH 2/7] [FEATURE] support column highlighting for table editor --- .../plugins/csv/editor/CsvAnnotator.java | 26 ++++++++-------- .../CsvEditorSettingsExternalizable.java | 9 ++++++ .../csv/editor/CsvEditorSettingsProvider.form | 10 ++++++- .../csv/editor/CsvEditorSettingsProvider.java | 6 +++- .../table/swing/CsvTableEditorSwing.java | 8 ++--- .../table/swing/MultiLineCellRenderer.java | 30 +++++++++++++++++-- .../editor/CsvEditorSettingsProviderTest.java | 4 +++ 7 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java index 081cdedb..489a95f6 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java @@ -80,7 +80,11 @@ 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() ? + getTextAttributes(holder.getCurrentAnnotationSession(), columnInfo.getColumnIndex()) : + null + ); annotation.setNeedsUpdateOnTyping(false); } } @@ -121,24 +125,22 @@ protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull A return false; } - public static TextAttributes getTextAttributes(UserDataHolder userDataHolder, CsvColumnInfo columnInfo) { - EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getSchemeForCurrentUITheme(); + public static TextAttributes getTextAttributes(UserDataHolder userDataHolder, int columnIndex) { List textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY); if (textAttributeList == null) { + EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getSchemeForCurrentUITheme(); textAttributeList = new ArrayList<>(); int maxIndex = 0; - if (CsvEditorSettingsExternalizable.getInstance().isColumnHighlightingEnabled()) { - 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; - } + 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; } } userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList.subList(0, maxIndex + 1)); } - return textAttributeList.isEmpty() ? null : textAttributeList.get(columnInfo.getColumnIndex() % textAttributeList.size()); + return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size()); } } \ No newline at end of file diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java index d441ff05..4263e800 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java @@ -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; @@ -52,6 +53,7 @@ public OptionSet() { EDITOR_PRIO = EditorPrio.TEXT_FIRST; SHOW_TABLE_EDITOR_INFO_PANEL = true; TABLE_EDITOR_ROW_HEIGHT = TABLE_EDITOR_DEFAULT_ROW_HEIGHT; + TABLE_COLUMN_HIGHTLIGHTING = true; } } @@ -155,4 +157,11 @@ public void setTableEditorRowHeight(int rowHeight) { if (finalRowHeight < TABLE_EDITOR_MIN_ROW_HEIGHT) finalRowHeight = TABLE_EDITOR_MIN_ROW_HEIGHT; getState().TABLE_EDITOR_ROW_HEIGHT = finalRowHeight; } + + public boolean isTableColumnHighlightingEnabled() { + return getState().TABLE_COLUMN_HIGHTLIGHTING; + } + public void setTableColumnHighlightingEnabled(boolean columnHighlightingEnabled) { + getState().TABLE_COLUMN_HIGHTLIGHTING = columnHighlightingEnabled; + } } \ No newline at end of file diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form index eca6363f..607d9cbf 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form @@ -91,7 +91,7 @@ - + @@ -140,6 +140,14 @@ + + + + + + + + diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.java index 8cea6065..155d4ac4 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.java @@ -23,6 +23,7 @@ public class CsvEditorSettingsProvider implements SearchableConfigurable { private JCheckBox cbShowInfoPanel; private JComboBox cbRowHeight; private JComboBox cbEditorUsage; + private JCheckBox cbTableColumnHighlighting; @NotNull @Override @@ -62,7 +63,8 @@ public boolean isModified() { cbTabHighlightColor.isSelected() != csvEditorSettingsExternalizable.isHighlightTabSeparator() || !Objects.equals(cbTabHighlightColor.getColor(), csvEditorSettingsExternalizable.getTabHighlightColor()) || !Objects.equals(cbRowHeight.getSelectedIndex(), csvEditorSettingsExternalizable.getTableEditorRowHeight()) || - !Objects.equals(cbEditorUsage.getSelectedIndex(), csvEditorSettingsExternalizable.getEditorPrio().ordinal()); + !Objects.equals(cbEditorUsage.getSelectedIndex(), csvEditorSettingsExternalizable.getEditorPrio().ordinal()) || + isModified(cbTableColumnHighlighting, csvEditorSettingsExternalizable.isTableColumnHighlightingEnabled()); } @Override @@ -77,6 +79,7 @@ public void reset() { cbTabHighlightColor.setColor(csvEditorSettingsExternalizable.getTabHighlightColor()); cbRowHeight.setSelectedIndex(csvEditorSettingsExternalizable.getTableEditorRowHeight()); cbEditorUsage.setSelectedIndex(csvEditorSettingsExternalizable.getEditorPrio().ordinal()); + cbTableColumnHighlighting.setSelected(csvEditorSettingsExternalizable.isTableColumnHighlightingEnabled()); } @Override @@ -91,6 +94,7 @@ public void apply() throws ConfigurationException { csvEditorSettingsExternalizable.setTabHighlightColor(cbTabHighlightColor.getColor()); csvEditorSettingsExternalizable.setTableEditorRowHeight(cbRowHeight.getSelectedIndex()); csvEditorSettingsExternalizable.setEditorPrio(CsvEditorSettingsExternalizable.EditorPrio.values()[cbEditorUsage.getSelectedIndex()]); + csvEditorSettingsExternalizable.setTableColumnHighlightingEnabled(cbTableColumnHighlighting.isSelected()); } protected void createUIComponents() { diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java index 8c3aea73..3ed5b15e 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java @@ -104,10 +104,10 @@ private void initializedUIComponents() { tblEditor.getColumnModel().addColumnModelListener(tableEditorListener); - tblEditor.setDefaultRenderer(String.class, new MultiLineCellRenderer(this.tableEditorKeyListener)); - tblEditor.setDefaultRenderer(Object.class, new MultiLineCellRenderer(this.tableEditorKeyListener)); - tblEditor.setDefaultEditor(String.class, new MultiLineCellRenderer(this.tableEditorKeyListener)); - tblEditor.setDefaultEditor(Object.class, new MultiLineCellRenderer(this.tableEditorKeyListener)); + tblEditor.setDefaultRenderer(String.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this)); + tblEditor.setDefaultRenderer(Object.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this)); + tblEditor.setDefaultEditor(String.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this)); + tblEditor.setDefaultEditor(Object.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this)); tblEditor.registerKeyboardAction(this.tableEditorActions.undo, KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED); tblEditor.registerKeyboardAction(this.tableEditorActions.redo, diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java index 30343610..816938c2 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java @@ -1,5 +1,10 @@ package net.seesharpsoft.intellij.plugins.csv.editor.table.swing; +import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.util.UserDataHolder; +import net.seesharpsoft.intellij.plugins.csv.editor.CsvAnnotator; +import net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsExternalizable; + import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.event.CellEditorListener; @@ -16,12 +21,31 @@ public class MultiLineCellRenderer extends JTextArea implements TableCellRenderer, TableCellEditor { private Set cellEditorListenerSet = new HashSet<>(); + private final UserDataHolder userDataHolder; - public MultiLineCellRenderer(CsvTableEditorKeyListener keyListener) { + public MultiLineCellRenderer(CsvTableEditorKeyListener keyListener, UserDataHolder userDataHolderParam) { setLineWrap(true); setWrapStyleWord(true); setOpaque(true); addKeyListener(keyListener); + this.userDataHolder = userDataHolderParam; + } + + private TextAttributes getColumnTextAttributes(int column) { + if (CsvEditorSettingsExternalizable.getInstance().isTableColumnHighlightingEnabled()) { + return CsvAnnotator.getTextAttributes(userDataHolder, column); + } + return null; + } + + private Color getColumnForegroundColor(int column, Color fallback) { + TextAttributes textAttributes = getColumnTextAttributes(column); + return textAttributes == null || textAttributes.getForegroundColor() == null ? fallback : textAttributes.getForegroundColor(); + } + + private Color getColumnBackgroundColor(int column, Color fallback) { + TextAttributes textAttributes = getColumnTextAttributes(column); + return textAttributes == null || textAttributes.getBackgroundColor() == null ? fallback : textAttributes.getBackgroundColor(); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { @@ -29,8 +53,8 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole setForeground(table.getSelectionForeground()); setBackground(table.getSelectionBackground()); } else { - setForeground(table.getForeground()); - setBackground(table.getBackground()); + setForeground(getColumnForegroundColor(column, table.getForeground())); + setBackground(getColumnBackgroundColor(column, table.getBackground())); } setFont(table.getFont()); if (hasFocus) { diff --git a/src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProviderTest.java b/src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProviderTest.java index c42d1d92..c8e667a6 100644 --- a/src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProviderTest.java +++ b/src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProviderTest.java @@ -61,6 +61,7 @@ public void testResetAndModified() throws ConfigurationException { csvEditorSettingsExternalizable.setHighlightTabSeparator(false); csvEditorSettingsExternalizable.setShowInfoBalloon(false); csvEditorSettingsExternalizable.setTabHighlightColor(Color.BLACK); + csvEditorSettingsExternalizable.setTableColumnHighlightingEnabled(false); assertEquals(true, editorSettingsPanel.isModified()); @@ -73,6 +74,7 @@ public void testResetAndModified() throws ConfigurationException { assertEquals(false, csvEditorSettingsExternalizable.isHighlightTabSeparator()); assertEquals(false, csvEditorSettingsExternalizable.isShowInfoBalloon()); assertEquals(Color.BLACK, csvEditorSettingsExternalizable.getTabHighlightColor()); + assertEquals(false, csvEditorSettingsExternalizable.isTableColumnHighlightingEnabled()); editorSettingsPanel.disposeUIResources(); } @@ -89,6 +91,7 @@ public void testApply() throws ConfigurationException { csvEditorSettingsExternalizable.setHighlightTabSeparator(false); csvEditorSettingsExternalizable.setShowInfoBalloon(false); csvEditorSettingsExternalizable.setTabHighlightColor(Color.BLACK); + csvEditorSettingsExternalizable.setTableColumnHighlightingEnabled(false); editorSettingsPanel.apply(); @@ -101,6 +104,7 @@ public void testApply() throws ConfigurationException { assertEquals(freshOptionSet.HIGHTLIGHT_TAB_SEPARATOR, csvEditorSettingsExternalizable.isHighlightTabSeparator()); assertEquals(freshOptionSet.SHOW_INFO_BALLOON, csvEditorSettingsExternalizable.isShowInfoBalloon()); assertEquals(freshOptionSet.TAB_HIGHLIGHT_COLOR, "" + csvEditorSettingsExternalizable.getTabHighlightColor().getRGB()); + assertEquals(freshOptionSet.TABLE_COLUMN_HIGHTLIGHTING, csvEditorSettingsExternalizable.isTableColumnHighlightingEnabled()); editorSettingsPanel.disposeUIResources(); } From 3a5a7c42a3b4b715597ec9fd12fe0e5497ecdcfd Mon Sep 17 00:00:00 2001 From: GeeK Date: Thu, 20 Dec 2018 22:56:44 +0100 Subject: [PATCH 3/7] [FIX] use legacy function call --- .../seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java index 489a95f6..c6e97d2a 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java @@ -128,7 +128,7 @@ protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull A public static TextAttributes getTextAttributes(UserDataHolder userDataHolder, int columnIndex) { List textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY); if (textAttributeList == null) { - EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getSchemeForCurrentUITheme(); + EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); textAttributeList = new ArrayList<>(); int maxIndex = 0; for (int colorDescriptorIndex = 0; colorDescriptorIndex < MAX_COLUMN_HIGHLIGHT_COLORS; ++colorDescriptorIndex) { From dc7f2336c84576af13796263b8e6a18924d37e87 Mon Sep 17 00:00:00 2001 From: GeeK Date: Thu, 20 Dec 2018 23:05:40 +0100 Subject: [PATCH 4/7] [INTERNAL] code cleanup --- .../plugins/csv/editor/CsvAnnotator.java | 43 ++----------------- .../table/swing/MultiLineCellRenderer.java | 4 +- ...ettingsPage.java => CsvColorSettings.java} | 43 ++++++++++++++++--- src/main/resources/META-INF/plugin.xml | 2 +- 4 files changed, 44 insertions(+), 48 deletions(-) rename src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/{CsvColorSettingsPage.java => CsvColorSettings.java} (54%) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java index c6e97d2a..cab0d3a2 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotator.java @@ -1,14 +1,9 @@ package net.seesharpsoft.intellij.plugins.csv.editor; import com.intellij.lang.annotation.*; -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; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.UserDataHolder; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import com.intellij.xml.util.XmlStringUtil; @@ -17,33 +12,18 @@ 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.util.ArrayList; -import java.util.List; - -import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; 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> COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_HIGHLIGHT_ATTRIBUTES"); protected static final Key TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR"); protected static final Key TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY = Key.create("CSV_PLUGIN_TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED"); protected static final Key SHOW_INFO_BALLOON_KEY = Key.create("CSV_PLUGIN_SHOW_INFO_BALLOON"); - public static final List COLUMN_HIGHLIGHT_ATTRIBUTES; - - static { - 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); - } - } - public static final HighlightSeverity CSV_COLUMN_INFO_SEVERITY = new HighlightSeverity("CSV_COLUMN_INFO_SEVERITY", TYPO.myVal + 5); @@ -82,7 +62,7 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip); annotation.setEnforcedTextAttributes( CsvEditorSettingsExternalizable.getInstance().isColumnHighlightingEnabled() ? - getTextAttributes(holder.getCurrentAnnotationSession(), columnInfo.getColumnIndex()) : + CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) : null ); annotation.setNeedsUpdateOnTyping(false); @@ -125,22 +105,5 @@ protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull A return false; } - public static TextAttributes getTextAttributes(UserDataHolder userDataHolder, int columnIndex) { - List textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_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; - } - } - userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList.subList(0, maxIndex + 1)); - } - return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size()); - } + } \ No newline at end of file diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java index 816938c2..43cc0930 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/MultiLineCellRenderer.java @@ -2,8 +2,8 @@ import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.UserDataHolder; -import net.seesharpsoft.intellij.plugins.csv.editor.CsvAnnotator; import net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsExternalizable; +import net.seesharpsoft.intellij.plugins.csv.settings.CsvColorSettings; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -33,7 +33,7 @@ public MultiLineCellRenderer(CsvTableEditorKeyListener keyListener, UserDataHold private TextAttributes getColumnTextAttributes(int column) { if (CsvEditorSettingsExternalizable.getInstance().isTableColumnHighlightingEnabled()) { - return CsvAnnotator.getTextAttributes(userDataHolder, column); + return CsvColorSettings.getTextAttributesOfColumn(column, userDataHolder); } return null; } diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java similarity index 54% rename from src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java rename to src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java index 21b9d271..88cac345 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettingsPage.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java @@ -1,13 +1,18 @@ 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; +import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorDescriptor; import com.intellij.openapi.options.colors.ColorSettingsPage; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.UserDataHolder; import net.seesharpsoft.intellij.plugins.csv.CsvIconProvider; import net.seesharpsoft.intellij.plugins.csv.CsvLanguage; -import net.seesharpsoft.intellij.plugins.csv.editor.CsvAnnotator; import net.seesharpsoft.intellij.plugins.csv.highlighter.CsvSyntaxHighlighter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -18,10 +23,17 @@ import java.util.List; import java.util.Map; -public class CsvColorSettingsPage implements ColorSettingsPage { +import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; + +public class CsvColorSettings implements ColorSettingsPage { private static final AttributesDescriptor[] DESCRIPTORS; + private static final Integer MAX_COLUMN_HIGHLIGHT_COLORS = 10; + private static final List COLUMN_HIGHLIGHT_ATTRIBUTES; + + private static final Key> COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_HIGHLIGHT_ATTRIBUTES"); + static { List attributesDescriptors = new ArrayList(Arrays.asList( new AttributesDescriptor("Separator", CsvSyntaxHighlighter.COMMA), @@ -30,13 +42,34 @@ public class CsvColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Escaped Text", CsvSyntaxHighlighter.ESCAPED_TEXT) )); - List columnHighlightAttributes = CsvAnnotator.COLUMN_HIGHLIGHT_ATTRIBUTES; - for (int i = 0; i < columnHighlightAttributes.size(); ++i) { - attributesDescriptors.add(new AttributesDescriptor(String.format("Column Highlighting Color %d", i + 1), columnHighlightAttributes.get(i))); + 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)); } DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[attributesDescriptors.size()]); } + public static TextAttributes getTextAttributesOfColumn(int columnIndex, UserDataHolder userDataHolder) { + List textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_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; + } + } + userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList.subList(0, maxIndex + 1)); + } + return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size()); + } + @Nullable @Override public Icon getIcon() { diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index b5504f8e..fec66b7b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -73,7 +73,7 @@ FIX: top and bottom panel scrollable & add column/row buttons removed implementationClass="net.seesharpsoft.intellij.plugins.csv.highlighter.CsvEditorHighlighterProvider"/> - + From 74111927865b6f32b25d62f21153cb29f358fd73 Mon Sep 17 00:00:00 2001 From: GeeK Date: Thu, 20 Dec 2018 23:19:55 +0100 Subject: [PATCH 5/7] [FIX] editor settings layout --- .../csv/editor/CsvEditorSettingsProvider.form | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form index 4c5cfe11..eb8fa2aa 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsProvider.form @@ -3,7 +3,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -99,6 +99,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -107,55 +140,27 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + + From d8cb1caa032eb97f573d22b28a616a000365e77d Mon Sep 17 00:00:00 2001 From: GeeK Date: Thu, 20 Dec 2018 23:20:22 +0100 Subject: [PATCH 6/7] [INTERNAL] enable text editor column highlighting by default --- .../plugins/csv/editor/CsvEditorSettingsExternalizable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java index c17b963c..50e213f7 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvEditorSettingsExternalizable.java @@ -47,7 +47,7 @@ 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"; From 035e19657b897b76d63fb3266abd983f0f2c13cd Mon Sep 17 00:00:00 2001 From: GeeK Date: Fri, 21 Dec 2018 23:34:36 +0100 Subject: [PATCH 7/7] [INTERNAL] update changelog, readme, etc for release 2.1.0 --- CHANGELOG | 8 ++++++++ README.md | 14 +++++++++++--- gradle.properties | 2 +- .../csv/settings/CsvColorSettings.java | 19 ++++++++----------- src/main/resources/META-INF/plugin.xml | 5 ++++- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3b80fcea..eb837f38 100644 --- a/CHANGELOG +++ b/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 diff --git a/README.md b/README.md index ac6f5077..161c0bf7 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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: diff --git a/gradle.properties b/gradle.properties index d2770d35..d19d963d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java index 88cac345..9dd9a287 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java @@ -19,7 +19,6 @@ import javax.swing.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -27,20 +26,17 @@ public class CsvColorSettings implements ColorSettingsPage { - private static final AttributesDescriptor[] DESCRIPTORS; - private static final Integer MAX_COLUMN_HIGHLIGHT_COLORS = 10; + private static final AttributesDescriptor[] DESCRIPTORS; private static final List COLUMN_HIGHLIGHT_ATTRIBUTES; - private static final Key> COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY = Key.create("CSV_PLUGIN_COLUMN_HIGHLIGHT_ATTRIBUTES"); static { - List attributesDescriptors = new ArrayList(Arrays.asList( - new AttributesDescriptor("Separator", CsvSyntaxHighlighter.COMMA), - new AttributesDescriptor("Quote", CsvSyntaxHighlighter.QUOTE), - new AttributesDescriptor("Text", CsvSyntaxHighlighter.TEXT), - new AttributesDescriptor("Escaped Text", CsvSyntaxHighlighter.ESCAPED_TEXT) - )); + List attributesDescriptors = new ArrayList(); + attributesDescriptors.add(new AttributesDescriptor("Separator", CsvSyntaxHighlighter.COMMA)); + attributesDescriptors.add(new AttributesDescriptor("Quote", CsvSyntaxHighlighter.QUOTE)); + attributesDescriptors.add(new AttributesDescriptor("Text", CsvSyntaxHighlighter.TEXT)); + attributesDescriptors.add(new AttributesDescriptor("Escaped Text", CsvSyntaxHighlighter.ESCAPED_TEXT)); COLUMN_HIGHLIGHT_ATTRIBUTES = new ArrayList<>(); for (int i = 0; i < MAX_COLUMN_HIGHLIGHT_COLORS; ++i) { @@ -65,7 +61,8 @@ public static TextAttributes getTextAttributesOfColumn(int columnIndex, UserData maxIndex = colorDescriptorIndex; } } - userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList.subList(0, maxIndex + 1)); + textAttributeList = textAttributeList.subList(0, maxIndex + 1); + userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList); } return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size()); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index fec66b7b..e2497b9e 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -48,7 +48,10 @@ -FIX: top and bottom panel scrollable & add column/row buttons removed +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) ]]>