Skip to content

Commit bdaf8c8

Browse files
authored
Merge pull request #109 from SeeSharpSoft/master
Release 2.3.0
2 parents 4404031 + dc4e5f0 commit bdaf8c8

19 files changed

+295
-116
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2222
hs_err_pid*
2323

24+
*.iml
2425
.idea
2526
out/
26-
gen/
27+
gen/

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2.3.0
2+
Mar 04, 2019
3+
4+
NEW: Zoom table-editor cells with Ctrl+Mouse Wheel (contribution by @royqh1979)
5+
FIX: Scratches are now recognised as CSV
6+
FIX: Several issues resolved by reworking column/row editing
7+
18
2.2.1
29
Jan 26, 2019
310

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Additionally the file type TSV was introduced as a kind of CSV language.
6060
For TSV files the same formatter and code style settings are applied as for CSV itself, but the separator is considered to be a tab.
6161
All functionality that is available for plain CSV files (inspections, intentions, structure view, etc.) can be used for TSV as well.
6262

63-
### \*NEW\* Table Editor
63+
### Table Editor
6464

6565
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.
6666

@@ -143,19 +143,19 @@ Set whether soft wrapping should be activated for CSV/TSV. It still can be chang
143143

144144
#### Table Editor
145145

146-
##### Textlines per row (default)
146+
##### Text-lines per row (default)
147147

148148
Defines how many lines of text are shown in one editor cell by default. *Auto* does recalculate the height on the fly that can cause some flickering while editing. This setting can be changed in the table editor itself per file.
149149

150150
##### Show info panel
151151

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

154-
##### **NEW** Enforce value quoting
154+
##### Enforce value quoting
155155

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

158-
##### **NEW** Enable column highlighting
158+
##### Enable column highlighting
159159

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

@@ -326,6 +326,10 @@ Contributions are welcome. Please check [CONTRIBUTING.md](./CONTRIBUTING.md) for
326326

327327
Besides source code contributions, feel free to open bug reports or just suggest new features [here](https://github.com/SeeSharpSoft/intellij-csv-validator/issues).
328328

329+
### Code/feature contributors
330+
331+
- zoom table-editor cells with Ctrl+Mouse Wheel @royqh1979
332+
329333
## FAQ
330334

331335
> Why can't I choose the separator freely?

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://www.jetbrains.com/intellij-repository/snapshots
44

55
name='CSV Plugin'
6-
pluginVersion=2.2.1
6+
pluginVersion=2.3.0
77
javaVersion=1.8
88
javaTargetVersion=1.8
99
downloadIntellijSources=false

intellij-csv-validator.iml

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package net.seesharpsoft.intellij.plugins.csv;
22

3+
import com.intellij.ide.scratch.ScratchFileType;
34
import com.intellij.lang.*;
45
import com.intellij.lexer.Lexer;
6+
import com.intellij.openapi.fileTypes.FileType;
7+
import com.intellij.openapi.fileTypes.LanguageFileType;
58
import com.intellij.openapi.project.Project;
9+
import com.intellij.openapi.vfs.VirtualFile;
610
import com.intellij.psi.PsiElement;
711
import com.intellij.psi.PsiManager;
812
import com.intellij.psi.TokenType;
@@ -37,6 +41,12 @@ public static PsiElement createEmptyCsvField(Project project) {
3741
return node.getPsi();
3842
}
3943

44+
public static boolean isCsvFile(Project project, VirtualFile file) {
45+
final FileType fileType = file.getFileType();
46+
return (fileType instanceof LanguageFileType && ((LanguageFileType) fileType).getLanguage().isKindOf(CsvLanguage.INSTANCE)) ||
47+
(fileType == ScratchFileType.INSTANCE && LanguageUtil.getLanguageForPsi(project, file) == CsvLanguage.INSTANCE);
48+
}
49+
4050
public static IElementType getElementType(PsiElement element) {
4151
return element == null || element.getNode() == null ? null : element.getNode().getElementType();
4252
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<component id="bfa35" class="javax.swing.JLabel">
110110
<constraints/>
111111
<properties>
112-
<text value="Textlines per row (default):"/>
112+
<text value="Text-lines per row (default):"/>
113113
</properties>
114114
</component>
115115
<component id="d6ab5" class="javax.swing.JComboBox" binding="cbRowHeight">

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,18 @@
33
import com.intellij.openapi.editor.EditorSettings;
44
import com.intellij.openapi.fileEditor.*;
55
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
6-
import com.intellij.openapi.fileTypes.LanguageFileType;
76
import com.intellij.openapi.project.DumbAware;
87
import com.intellij.openapi.project.Project;
98
import com.intellij.openapi.vfs.VirtualFile;
109
import com.intellij.psi.SingleRootFileViewProvider;
11-
import net.seesharpsoft.intellij.plugins.csv.CsvLanguage;
10+
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
1211
import org.jdom.Element;
1312
import org.jetbrains.annotations.NotNull;
1413

1514
public class CsvFileEditorProvider implements AsyncFileEditorProvider, DumbAware {
1615

1716
public static final String EDITOR_TYPE_ID = "csv-text-editor";
1817

19-
public static boolean isCsvFile(VirtualFile file) {
20-
return file.getFileType() instanceof LanguageFileType && ((LanguageFileType) file.getFileType()).getLanguage().isKindOf(CsvLanguage.INSTANCE);
21-
}
22-
2318
@Override
2419
public String getEditorTypeId() {
2520
return EDITOR_TYPE_ID;
@@ -40,7 +35,7 @@ public FileEditorPolicy getPolicy() {
4035

4136
@Override
4237
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
43-
return isCsvFile(file) && !SingleRootFileViewProvider.isTooLargeForContentLoading(file);
38+
return CsvHelper.isCsvFile(project, file) && !SingleRootFileViewProvider.isTooLargeForContentLoading(file);
4439
}
4540

4641
protected void applySettings(EditorSettings editorSettings, CsvEditorSettingsExternalizable csvEditorSettingsExternalizable) {

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

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

3+
import com.google.common.primitives.Ints;
34
import com.intellij.codeHighlighting.BackgroundEditorHighlighter;
45
import com.intellij.ide.structureView.StructureViewBuilder;
56
import com.intellij.openapi.application.ApplicationManager;
@@ -15,6 +16,7 @@
1516
import com.intellij.psi.PsiDocumentManager;
1617
import com.intellij.psi.PsiElement;
1718
import com.intellij.psi.PsiFile;
19+
import com.intellij.util.ArrayUtil;
1820
import net.seesharpsoft.intellij.plugins.csv.CsvColumnInfoMap;
1921
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
2022
import net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsExternalizable;
@@ -27,12 +29,13 @@
2729
import javax.swing.*;
2830
import java.beans.PropertyChangeListener;
2931
import java.beans.PropertyChangeSupport;
32+
import java.util.Collections;
33+
import java.util.List;
3034

3135
public abstract class CsvTableEditor implements FileEditor, FileEditorLocation {
3236

3337
public static final String EDITOR_NAME = "Table Editor";
3438

35-
public static final int ROW_LINE_HEIGHT = 20;
3639
public static final int INITIAL_COLUMN_WIDTH = 100;
3740

3841
protected final Project project;
@@ -75,6 +78,9 @@ public CsvTableEditor(@NotNull Project projectArg, @NotNull VirtualFile fileArg)
7578

7679
protected abstract void afterTableComponentUpdate(Object[][] values);
7780

81+
public abstract int getPreferredRowHeight();
82+
83+
7884
public final void updateTableComponentData(Object[][] values) {
7985
beforeTableComponentUpdate();
8086
try {
@@ -85,10 +91,6 @@ public final void updateTableComponentData(Object[][] values) {
8591
}
8692
}
8793

88-
public int getPreferredRowHeight() {
89-
return ROW_LINE_HEIGHT * getFileEditorState().getRowLines();
90-
}
91-
9294
public void setEditable(boolean editable) {
9395
this.tableIsEditable = editable;
9496
this.updateInteractionElements();
@@ -282,10 +284,68 @@ public Project getProject() {
282284

283285
@Nullable
284286
public CsvFile getCsvFile() {
285-
return this.psiFile instanceof CsvFile ? (CsvFile)psiFile : null;
287+
return this.psiFile instanceof CsvFile ? (CsvFile) psiFile : null;
286288
}
287289

288290
public TableDataHandler getDataHandler() {
289291
return this.dataManagement;
290292
}
293+
294+
public int getRowCount() {
295+
return getDataHandler().getCurrentState().length;
296+
}
297+
298+
public int getColumnCount() {
299+
Object[][] currentData = getDataHandler().getCurrentState();
300+
return currentData.length > 0 ? currentData[0].length : 0;
301+
}
302+
303+
public Object[][] addRow(int focusedRowIndex, boolean before) {
304+
int index = (before ? (focusedRowIndex == -1 ? 0 : focusedRowIndex) : (focusedRowIndex == -1 ? getRowCount() : focusedRowIndex + 1)) +
305+
(getFileEditorState().getFixedHeaders() ? 1 : 0);
306+
TableDataHandler dataHandler = getDataHandler();
307+
Object[][] currentData = ArrayUtil.insert(dataHandler.getCurrentState(), index, new Object[getColumnCount()]);
308+
updateTableComponentData(dataHandler.addState(currentData));
309+
return currentData;
310+
}
311+
312+
public Object[][] removeRows(int[] indices) {
313+
List<Integer> currentRows = Ints.asList(indices);
314+
currentRows.sort(Collections.reverseOrder());
315+
TableDataHandler dataHandler = getDataHandler();
316+
Object[][] currentData = dataHandler.getCurrentState();
317+
for (int currentRow : currentRows) {
318+
currentData = ArrayUtil.remove(currentData, currentRow + (getFileEditorState().getFixedHeaders() ? 1 : 0));
319+
}
320+
updateTableComponentData(dataHandler.addState(currentData));
321+
return currentData;
322+
}
323+
324+
public Object[][] addColumn(int focusedColumnIndex, boolean before) {
325+
int index = before ? (focusedColumnIndex == -1 ? 0 : focusedColumnIndex) : (focusedColumnIndex == -1 ? getColumnCount() : focusedColumnIndex + 1);
326+
boolean fixedHeaders = getFileEditorState().getFixedHeaders();
327+
TableDataHandler dataHandler = getDataHandler();
328+
Object[][] currentData = dataHandler.getCurrentState();
329+
for (int i = 0; i < currentData.length; ++i) {
330+
currentData[i] = ArrayUtil.insert(currentData[i], index, fixedHeaders && i == 0 ? "" : null);
331+
}
332+
updateTableComponentData(dataHandler.addState(currentData));
333+
return currentData;
334+
}
335+
336+
public Object[][] removeColumns(int[] indices) {
337+
List<Integer> currentColumns = Ints.asList(indices);
338+
currentColumns.sort(Collections.reverseOrder());
339+
340+
TableDataHandler dataHandler = getDataHandler();
341+
Object[][] currentData = dataHandler.getCurrentState();
342+
343+
for (int currentColumn : currentColumns) {
344+
for (int i = 0; i < currentData.length; ++i) {
345+
currentData[i] = ArrayUtil.remove(currentData[i], currentColumn);
346+
}
347+
}
348+
updateTableComponentData(dataHandler.addState(currentData));
349+
return currentData;
350+
}
291351
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.intellij.openapi.project.Project;
99
import com.intellij.openapi.vfs.VirtualFile;
1010
import com.intellij.psi.SingleRootFileViewProvider;
11+
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
1112
import net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsExternalizable;
12-
import net.seesharpsoft.intellij.plugins.csv.editor.CsvFileEditorProvider;
1313
import net.seesharpsoft.intellij.plugins.csv.editor.table.swing.CsvTableEditorSwing;
1414
import org.jdom.Element;
1515
import org.jetbrains.annotations.NotNull;
@@ -38,7 +38,8 @@ public FileEditorPolicy getPolicy() {
3838

3939
@Override
4040
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
41-
return CsvEditorSettingsExternalizable.getInstance().getEditorPrio() != CsvEditorSettingsExternalizable.EditorPrio.TEXT_ONLY && CsvFileEditorProvider.isCsvFile(file) &&
41+
return CsvEditorSettingsExternalizable.getInstance().getEditorPrio() != CsvEditorSettingsExternalizable.EditorPrio.TEXT_ONLY &&
42+
CsvHelper.isCsvFile(project, file) &&
4243
!SingleRootFileViewProvider.isTooLargeForIntelligence(file);
4344
}
4445

0 commit comments

Comments
 (0)