Skip to content

Commit db8c02d

Browse files
authored
Merge 142bd64 into 811dd5f
2 parents 811dd5f + 142bd64 commit db8c02d

File tree

12 files changed

+143
-29
lines changed

12 files changed

+143
-29
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ The plugin introduces an enhanced text editor supporting custom settings - and a
105105

106106
![Editor settings](./docs/editorsettings.png)
107107

108-
#### Editor Usage
108+
#### General
109+
110+
##### Editor Usage
109111

110112
The preferred editor usage can be switched between "Text Editor first", "Table Editor first" or "Text Editor only", which has an effect on the editor tab order (or whether the table editor is shown at all). A "Table Editor only" option is not available (mainly due to the table editor restrictions when handling erroneous CSV files).
111113

114+
##### Column numbering
115+
116+
Enable zero-based column numbering. This affects the tooltip info of the text editor as well as column numbering of the table editor.
117+
112118
#### Text Editor
113119

114120
##### Highlighting

docs/editorsettings.png

-731 Bytes
Loading

docs/tableeditor.png

-2.96 KB
Loading

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
@@ -50,7 +50,7 @@ public void annotate(@NotNull final PsiElement element, @NotNull final Annotatio
5050
String.format("%s<br /><br />Header: %s<br />Index: %d",
5151
XmlStringUtil.escapeString(element.getText(), true),
5252
message,
53-
columnInfo.getColumnIndex()
53+
columnInfo.getColumnIndex() + (CsvEditorSettingsExternalizable.getInstance().isZeroBasedColumnNumbering() ? 0 : 1)
5454
)
5555
);
5656
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static final class OptionSet {
3939
public EditorPrio EDITOR_PRIO;
4040
public int TABLE_EDITOR_ROW_HEIGHT;
4141
public boolean TABLE_COLUMN_HIGHTLIGHTING;
42+
public boolean ZERO_BASED_COLUMN_NUMBERING;
4243

4344
public boolean SHOW_TABLE_EDITOR_INFO_PANEL;
4445
public boolean QUOTING_ENFORCED;
@@ -56,6 +57,7 @@ public OptionSet() {
5657
TABLE_EDITOR_ROW_HEIGHT = TABLE_EDITOR_DEFAULT_ROW_HEIGHT;
5758
QUOTING_ENFORCED = false;
5859
TABLE_COLUMN_HIGHTLIGHTING = true;
60+
ZERO_BASED_COLUMN_NUMBERING = false;
5961
}
6062
}
6163

@@ -173,4 +175,11 @@ public boolean isTableColumnHighlightingEnabled() {
173175
public void setTableColumnHighlightingEnabled(boolean columnHighlightingEnabled) {
174176
getState().TABLE_COLUMN_HIGHTLIGHTING = columnHighlightingEnabled;
175177
}
178+
179+
public boolean isZeroBasedColumnNumbering() {
180+
return getState().ZERO_BASED_COLUMN_NUMBERING;
181+
}
182+
public void setZeroBasedColumnNumbering(boolean zeroBasedColumnNumbering) {
183+
getState().ZERO_BASED_COLUMN_NUMBERING = zeroBasedColumnNumbering;
184+
}
176185
}

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsProvider">
3-
<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">
3+
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
66
<xy x="20" y="20" width="1180" height="648"/>
@@ -16,7 +16,7 @@
1616
<grid id="350ae" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1717
<margin top="10" left="10" bottom="10" right="10"/>
1818
<constraints>
19-
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
19+
<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"/>
2020
</constraints>
2121
<properties/>
2222
<border type="line" title="Text Editor"/>
@@ -94,7 +94,7 @@
9494
<grid id="3e325" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
9595
<margin top="10" left="10" bottom="10" right="10"/>
9696
<constraints>
97-
<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"/>
97+
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
9898
</constraints>
9999
<properties/>
100100
<border type="line" title="Table Editor"/>
@@ -165,7 +165,7 @@
165165
</grid>
166166
<vspacer id="ff292">
167167
<constraints>
168-
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
168+
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
169169
</constraints>
170170
</vspacer>
171171
<component id="19f8" class="javax.swing.JLabel">
@@ -188,6 +188,22 @@
188188
</model>
189189
</properties>
190190
</component>
191+
<component id="980fc" class="javax.swing.JLabel">
192+
<constraints>
193+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
194+
</constraints>
195+
<properties>
196+
<text value="Column numbering:"/>
197+
</properties>
198+
</component>
199+
<component id="bfc7c" class="javax.swing.JCheckBox" binding="cbZeroBasedColumnNumbering">
200+
<constraints>
201+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
202+
</constraints>
203+
<properties>
204+
<text value="Zero-based"/>
205+
</properties>
206+
</component>
191207
</children>
192208
</grid>
193209
</form>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CsvEditorSettingsProvider implements SearchableConfigurable {
2525
private JComboBox cbEditorUsage;
2626
private JCheckBox cbQuotingEnforced;
2727
private JCheckBox cbTableColumnHighlighting;
28+
private JCheckBox cbZeroBasedColumnNumbering;
2829

2930
@NotNull
3031
@Override
@@ -67,7 +68,8 @@ public boolean isModified() {
6768
!Objects.equals(cbEditorUsage.getSelectedIndex(), csvEditorSettingsExternalizable.getEditorPrio().ordinal()) ||
6869
isModified(cbQuotingEnforced, csvEditorSettingsExternalizable.isQuotingEnforced()) ||
6970
!Objects.equals(cbEditorUsage.getSelectedIndex(), csvEditorSettingsExternalizable.getEditorPrio().ordinal()) ||
70-
isModified(cbTableColumnHighlighting, csvEditorSettingsExternalizable.isTableColumnHighlightingEnabled());
71+
isModified(cbTableColumnHighlighting, csvEditorSettingsExternalizable.isTableColumnHighlightingEnabled()) ||
72+
isModified(cbZeroBasedColumnNumbering, csvEditorSettingsExternalizable.isZeroBasedColumnNumbering());
7173
}
7274

7375
@Override
@@ -84,6 +86,7 @@ public void reset() {
8486
cbEditorUsage.setSelectedIndex(csvEditorSettingsExternalizable.getEditorPrio().ordinal());
8587
cbQuotingEnforced.setSelected(csvEditorSettingsExternalizable.isQuotingEnforced());
8688
cbTableColumnHighlighting.setSelected(csvEditorSettingsExternalizable.isTableColumnHighlightingEnabled());
89+
cbZeroBasedColumnNumbering.setSelected(csvEditorSettingsExternalizable.isZeroBasedColumnNumbering());
8790
}
8891

8992
@Override
@@ -100,6 +103,7 @@ public void apply() throws ConfigurationException {
100103
csvEditorSettingsExternalizable.setEditorPrio(CsvEditorSettingsExternalizable.EditorPrio.values()[cbEditorUsage.getSelectedIndex()]);
101104
csvEditorSettingsExternalizable.setQuotingEnforced(cbQuotingEnforced.isSelected());
102105
csvEditorSettingsExternalizable.setTableColumnHighlightingEnabled(cbTableColumnHighlighting.isSelected());
106+
csvEditorSettingsExternalizable.setZeroBasedColumnNumbering(cbZeroBasedColumnNumbering.isSelected());
103107
}
104108

105109
protected void createUIComponents() {

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public abstract class CsvTableEditor implements FileEditor, FileEditorLocation {
4747
private Object[][] initialState = null;
4848
private CsvTableEditorState storedState = null;
4949

50-
protected CsvColumnInfoMap<PsiElement> columnInfoMap;
5150
protected boolean tableIsEditable = true;
5251

5352
public CsvTableEditor(@NotNull Project projectArg, @NotNull VirtualFile fileArg) {
@@ -68,21 +67,21 @@ public CsvTableEditor(@NotNull Project projectArg, @NotNull VirtualFile fileArg)
6867

6968
protected abstract void updateInteractionElements();
7069

71-
protected abstract void applyRowLines(int rowLines);
70+
protected abstract void applyEditorState(CsvTableEditorState editorState);
7271

7372
protected abstract void setTableComponentData(Object[][] values);
7473

7574
protected abstract void beforeTableComponentUpdate();
7675

77-
protected abstract void afterTableComponentUpdate();
76+
protected abstract void afterTableComponentUpdate(Object[][] values);
7877

7978
public final void updateTableComponentData(Object[][] values) {
8079
beforeTableComponentUpdate();
8180
try {
8281
setTableComponentData(values);
8382
saveChanges();
8483
} finally {
85-
afterTableComponentUpdate();
84+
afterTableComponentUpdate(values);
8685
}
8786
}
8887

@@ -99,7 +98,13 @@ public boolean isEditable() {
9998
return this.tableIsEditable && !this.hasErrors();
10099
}
101100

101+
public CsvColumnInfoMap<PsiElement> getColumnInfoMap() {
102+
CsvFile csvFile = getCsvFile();
103+
return csvFile == null ? null : csvFile.getMyColumnInfoMap();
104+
}
105+
102106
public boolean hasErrors() {
107+
CsvColumnInfoMap columnInfoMap = getColumnInfoMap();
103108
return !isValid() || (columnInfoMap != null && columnInfoMap.hasErrors());
104109
}
105110

@@ -186,7 +191,7 @@ public void setState(@NotNull FileEditorState fileEditorState) {
186191
CsvTableEditorState tableEditorState = fileEditorState instanceof CsvTableEditorState ? (CsvTableEditorState) fileEditorState : new CsvTableEditorState();
187192
this.storedState = tableEditorState;
188193

189-
applyRowLines(getFileEditorState().getRowLines());
194+
applyEditorState(getFileEditorState());
190195
}
191196

192197
@Override

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class CsvTableEditorState implements FileEditorState {
1818

1919
private int[] columnWidths;
2020
private Boolean showInfoPanel;
21+
private Boolean fixedHeaders;
2122
private Integer rowLines;
2223

2324
public CsvTableEditorState() {
@@ -43,6 +44,14 @@ public void setShowInfoPanel(boolean showInfoPanelArg) {
4344
showInfoPanel = showInfoPanelArg;
4445
}
4546

47+
public boolean getFixedHeaders() {
48+
return fixedHeaders == null ? false : fixedHeaders;
49+
}
50+
51+
public void setFixedHeaders(boolean fixedHeadersArg) {
52+
fixedHeaders = fixedHeadersArg;
53+
}
54+
4655
public int getRowLines() {
4756
if (rowLines == null) {
4857
rowLines = CsvEditorSettingsExternalizable.getInstance().getTableEditorRowHeight();
@@ -61,6 +70,7 @@ public boolean canBeMergedWith(FileEditorState fileEditorState, FileEditorStateL
6170

6271
public void write(@NotNull Project project, @NotNull Element element) {
6372
element.setAttribute("showInfoPanel", "" + showInfoPanel());
73+
element.setAttribute("fixedHeaders", "" + getFixedHeaders());
6474
element.setAttribute("rowLines", "" + getRowLines());
6575
for (int i = 0; i < columnWidths.length; ++i) {
6676
Element cwElement = new Element("column");
@@ -79,6 +89,10 @@ public static CsvTableEditorState create(@NotNull Element element, @NotNull Proj
7989
state.setShowInfoPanel(
8090
attribute == null ? CsvEditorSettingsExternalizable.getInstance().showTableEditorInfoPanel() : Boolean.parseBoolean(attribute.getValue())
8191
);
92+
attribute = element.getAttribute("fixedHeaders");
93+
state.setFixedHeaders(
94+
attribute == null ? false : Boolean.parseBoolean(attribute.getValue())
95+
);
8296
state.setRowLines(
8397
StringUtilRt.parseInt(element.getAttributeValue("rowLines"), CsvEditorSettingsExternalizable.getInstance().getTableEditorRowHeight())
8498
);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@
5353
<visible value="false"/>
5454
</properties>
5555
</component>
56+
<component id="83d80" class="javax.swing.JCheckBox" binding="cbFixedHeaders">
57+
<constraints/>
58+
<properties>
59+
<contentAreaFilled value="false"/>
60+
<horizontalTextPosition value="10"/>
61+
<label value="Header row fixed:"/>
62+
<text value="Header row fixed:"/>
63+
</properties>
64+
</component>
65+
<component id="af7be" class="javax.swing.JToolBar$Separator">
66+
<constraints/>
67+
<properties/>
68+
</component>
5669
<component id="9bf69" class="javax.swing.JLabel" binding="lblTextlines">
5770
<constraints/>
5871
<properties>

0 commit comments

Comments
 (0)