Skip to content

Commit e86a69c

Browse files
authored
Merge pull request #883 from SeeSharpSoft/feat_401
Release 4.0.1
2 parents 9556c28 + 997c646 commit e86a69c

22 files changed

+239
-128
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,25 @@
1010

1111
### Fixed
1212

13-
## [4.0.0] - Oct 07, 2024
13+
## [4.0.1] - Dec 01, 2024
14+
15+
### Added
16+
17+
- Localization support
18+
19+
### Changed
20+
21+
- Upgrade to gradle 8.10
22+
- Improve check for CsvFile
23+
- Code cleanup
24+
25+
### Fixed
26+
27+
- Read access is allowed from inside read-action only #878
28+
- Failsafe acceptCsvFile check #882
29+
- Use ProjectActivity instead of StartupActivity
30+
31+
## 4.0.0 - Oct 07, 2024
1432

1533
### Added
1634
- Tabularize formatting is back!

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
pluginName=CSV Editor
66
pluginId=net.seesharpsoft.intellij.plugins.csv
7-
pluginVersion=4.0.0
7+
pluginVersion=4.0.1
88

99
pluginSinceBuild=242
1010

@@ -19,4 +19,3 @@ org.gradle.parallel=true
1919
# Opt-out flag for bundling Kotlin standard library.
2020
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
2121
kotlin.stdlib.default.dependency=false
22-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class RowInfo {
108108
this(element, row, -1, -1);
109109
}
110110

111-
RowInfo(@NotNull T element, @NotNull int row, int startIndex, int endIndex) {
111+
RowInfo(@NotNull T element, int row, int startIndex, int endIndex) {
112112
this.myElement = element;
113113
this.myRow = row;
114114
if (startIndex <= endIndex && startIndex >= 0) {
@@ -140,7 +140,7 @@ public boolean equals(Object other) {
140140
if (!(other instanceof CsvColumnInfo.RowInfo)) {
141141
return false;
142142
}
143-
return this.myElement.equals(((RowInfo) other).myElement);
143+
return this.myElement.equals(((CsvColumnInfo<?>.RowInfo) other).myElement);
144144
}
145145
}
146146
}

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.intellij.lang.*;
44
import com.intellij.lexer.Lexer;
5-
import com.intellij.openapi.fileTypes.FileType;
65
import com.intellij.openapi.fileTypes.FileTypeRegistry;
76
import com.intellij.openapi.project.Project;
87
import com.intellij.openapi.vfs.VirtualFile;
@@ -22,8 +21,6 @@
2221
import net.seesharpsoft.intellij.plugins.csv.psi.CsvRecord;
2322
import net.seesharpsoft.intellij.plugins.csv.psi.CsvTypes;
2423
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
25-
import net.seesharpsoft.intellij.plugins.psv.PsvFileType;
26-
import net.seesharpsoft.intellij.plugins.tsv.TsvFileType;
2724
import net.seesharpsoft.intellij.psi.PsiHelper;
2825
import org.jetbrains.annotations.NotNull;
2926

@@ -58,26 +55,19 @@ public static boolean isCsvFile(String extension) {
5855
if (extension == null) {
5956
return false;
6057
}
61-
// simple check to always in include the defaults even if association was removed
62-
switch (extension.toLowerCase()) {
63-
case "csv":
64-
case "tsv":
65-
case "tab":
66-
case "psv":
67-
return true;
68-
default:
69-
// but also consider other extensions that are associated manually
70-
FileType fileType = FileTypeRegistry.getInstance().getFileTypeByExtension(extension);
71-
return fileType == CsvFileType.INSTANCE ||
72-
fileType == TsvFileType.INSTANCE ||
73-
fileType == PsvFileType.INSTANCE;
74-
}
58+
Language language = LanguageUtil.getFileTypeLanguage(
59+
FileTypeRegistry.getInstance().getFileTypeByExtension(extension)
60+
);
61+
return language != null && language.isKindOf(CsvLanguage.INSTANCE);
7562
}
7663

7764
public static boolean isCsvFile(Project project, VirtualFile file) {
78-
if (project == null || file == null || !isCsvFile(file.getExtension())) {
65+
if (file == null) {
7966
return false;
8067
}
68+
if (project == null) {
69+
return isCsvFile(file.getExtension());
70+
}
8171
final Language language = LanguageUtil.getLanguageForPsi(project, file);
8272
return language != null && language.isKindOf(CsvLanguage.INSTANCE);
8373
}

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@
99
import com.intellij.openapi.progress.ProgressIndicator;
1010
import com.intellij.openapi.progress.ProgressManager;
1111
import com.intellij.openapi.progress.Task;
12+
import com.intellij.openapi.project.DumbAware;
1213
import com.intellij.openapi.project.Project;
13-
import com.intellij.openapi.startup.StartupActivity;
14+
import com.intellij.openapi.startup.ProjectActivity;
15+
import kotlin.Unit;
16+
import kotlin.coroutines.Continuation;
1417
import net.seesharpsoft.intellij.plugins.csv.components.CsvFileAttributes;
1518
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
1619
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettingsProvider;
1720
import org.jetbrains.annotations.NotNull;
21+
import org.jetbrains.annotations.Nullable;
1822

19-
public class CsvPlugin implements StartupActivity, StartupActivity.DumbAware {
23+
import java.util.ResourceBundle;
2024

25+
public class CsvPlugin implements ProjectActivity, DumbAware {
26+
27+
private static ResourceBundle _resourceBundle;
28+
2129
protected static IdeaPluginDescriptor getPluginDescriptor() {
2230
return PluginManagerCore.getPlugin(PluginId.getId("net.seesharpsoft.intellij.plugins.csv"));
2331
}
@@ -66,12 +74,12 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
6674
}
6775

6876
@Override
69-
public void runActivity(@NotNull Project project) {
77+
public @Nullable Object execute(@NotNull Project project, @NotNull Continuation<? super Unit> continuation) {
7078
doAsyncProjectMaintenance(project);
71-
79+
7280
NotificationGroup notificationGroup = NotificationGroupManager.getInstance().getNotificationGroup("net.seesharpsoft.intellij.plugins.csv");
7381
if (notificationGroup == null || CsvEditorSettings.getInstance().checkCurrentPluginVersion(getVersion())) {
74-
return;
82+
return continuation;
7583
}
7684

7785
Notification notification = notificationGroup.createNotification(
@@ -100,5 +108,20 @@ public void runActivity(@NotNull Project project) {
100108
}));
101109

102110
Notifications.Bus.notify(notification);
111+
112+
return continuation;
113+
}
114+
115+
public static ResourceBundle getResourceBundle() {
116+
if (_resourceBundle == null) {
117+
_resourceBundle = ResourceBundle.getBundle("i18n/CSVEditorResources");
118+
}
119+
return _resourceBundle;
103120
}
121+
122+
public static String getLocalizedText(String token) {
123+
return getResourceBundle().getString(token);
124+
}
125+
126+
104127
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/actions/CsvCustomSeparatorAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void setSelected(@NotNull AnActionEvent anActionEvent, boolean selected)
4141
if (customValueSeparator == null) {
4242
return;
4343
}
44-
if (customValueSeparator.length() == 0 || customValueSeparator.contains(" ")) {
44+
if (customValueSeparator.isEmpty() || customValueSeparator.contains(" ")) {
4545
JOptionPane.showMessageDialog(fileEditor == null ? null : fileEditor.getComponent(), "Value separator must have at least one character and no spaces!");
4646
return;
4747
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ public class CsvFileEditorProvider implements AsyncFileEditorProvider, DumbAware
1818
public static final String EDITOR_TYPE_ID = "csv-text-editor";
1919

2020
public static boolean acceptCsvFile(@NotNull Project project, @NotNull VirtualFile file) {
21-
return CsvHelper.isCsvFile(project, file)
22-
&& !SingleRootFileViewProvider.isTooLargeForContentLoading(file)
23-
&& !SingleRootFileViewProvider.isTooLargeForIntelligence(file)
24-
&& !(file instanceof DiffViewerVirtualFile);
21+
try {
22+
return !SingleRootFileViewProvider.isTooLargeForContentLoading(file)
23+
&& !SingleRootFileViewProvider.isTooLargeForIntelligence(file)
24+
&& !(file instanceof DiffViewerVirtualFile)
25+
&& CsvHelper.isCsvFile(project, file);
26+
} catch(Exception exc) {
27+
return false;
28+
}
2529
}
2630

2731
@Override

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CsvTableEditorProvider implements AsyncFileEditorProvider, DumbAwar
1818
public static final String EDITOR_TYPE_ID = "csv-table-editor";
1919

2020
@Override
21-
public String getEditorTypeId() {
21+
public @NotNull String getEditorTypeId() {
2222
return EDITOR_TYPE_ID;
2323
}
2424

@@ -48,16 +48,15 @@ public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile vi
4848
}
4949

5050
@Override
51-
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
51+
public @NotNull FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
5252
return CsvTableEditorState.create(sourceElement, project, file);
5353
}
5454

5555
@Override
5656
public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
57-
if (!(state instanceof CsvTableEditorState)) {
57+
if (!(state instanceof CsvTableEditorState csvTableEditorState)) {
5858
return;
5959
}
60-
CsvTableEditorState csvTableEditorState = (CsvTableEditorState) state;
6160
csvTableEditorState.write(project, targetElement);
6261
}
6362

@@ -66,7 +65,7 @@ public void writeState(@NotNull FileEditorState state, @NotNull Project project,
6665
public Builder createEditorAsync(@NotNull Project project, @NotNull VirtualFile virtualFile) {
6766
return new Builder() {
6867
@Override
69-
public FileEditor build() {
68+
public @NotNull FileEditor build() {
7069
return new CsvTableEditorSwing(project, virtualFile);
7170
}
7271
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void resetCachedValues() {
9292
}
9393

9494
private void resetPointer() {
95-
myPointedRecord = PsiTreeUtil.findChildOfType(getPsiFile(), CsvRecord.class);
95+
myPointedRecord = PsiHelper.getFirstChildOfType(getPsiFile(), CsvRecord.class);
9696
myPointedRow = 0;
9797
}
9898

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import com.intellij.openapi.editor.markup.TextAttributes;
66
import com.intellij.openapi.util.UserDataHolder;
77
import com.intellij.ui.components.JBScrollPane;
8+
import com.intellij.util.ui.JBUI;
89
import com.intellij.util.ui.UIUtil;
910
import net.seesharpsoft.intellij.plugins.csv.settings.CsvColorSettings;
1011
import org.jetbrains.annotations.NotNull;
1112

1213
import javax.swing.*;
13-
import javax.swing.border.EmptyBorder;
1414
import javax.swing.event.CellEditorListener;
1515
import javax.swing.event.ChangeEvent;
1616
import javax.swing.table.TableCellEditor;
@@ -21,7 +21,6 @@
2121
import java.awt.event.KeyEvent;
2222
import java.awt.geom.Rectangle2D;
2323
import java.util.EventObject;
24-
import java.util.Iterator;
2524
import java.util.Set;
2625
import java.util.concurrent.CopyOnWriteArraySet;
2726

@@ -80,7 +79,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
8079
myTextArea.setBackground(UIManager.getColor(editorColorsScheme.getDefaultBackground()));
8180
}
8281
} else {
83-
myTextArea.setBorder(new EmptyBorder(1, 2, 1, 2));
82+
myTextArea.setBorder(JBUI.Borders.empty(1, 2));
8483
}
8584

8685
this.setFont(table.getFont());
@@ -153,19 +152,17 @@ public void cancelCellEditing() {
153152
protected void fireStopCellEditing() {
154153
ChangeEvent changeEvent = new ChangeEvent(this);
155154
synchronized (cellEditorListenerSet) {
156-
Iterator<CellEditorListener> it = cellEditorListenerSet.iterator();
157-
while (it.hasNext()) {
158-
it.next().editingStopped(changeEvent);
155+
for (CellEditorListener cellEditorListener : cellEditorListenerSet) {
156+
cellEditorListener.editingStopped(changeEvent);
159157
}
160158
}
161159
}
162160

163161
protected void fireCancelCellEditing() {
164162
ChangeEvent changeEvent = new ChangeEvent(this);
165163
synchronized (cellEditorListenerSet) {
166-
Iterator<CellEditorListener> it = cellEditorListenerSet.iterator();
167-
while (it.hasNext()) {
168-
it.next().editingCanceled(changeEvent);
164+
for (CellEditorListener cellEditorListener : cellEditorListenerSet) {
165+
cellEditorListener.editingCanceled(changeEvent);
169166
}
170167
}
171168
}

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

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

3-
import com.intellij.ide.BrowserUtil;
43
import com.intellij.openapi.fileEditor.FileEditorManager;
54
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
65
import com.intellij.ui.components.labels.LinkLabel;
@@ -25,7 +24,7 @@ public class CsvTableEditorActionListeners extends CsvTableEditorUtilBase implem
2524
protected ActionListener adjustColumnWidthAction = event -> adjustColumnWidths(csvTableEditor);
2625
protected ActionListener resetColumnWidthAction = event -> resetColumnWidths(csvTableEditor);
2726

28-
protected LinkListener openTextEditor = new OpenTextEditor();
27+
protected LinkListener<Object> openTextEditor = new OpenTextEditor();
2928

3029
public CsvTableEditorActionListeners(CsvTableEditorSwing tableEditor) {
3130
super(tableEditor);
@@ -89,7 +88,7 @@ public void deleteSelectedRows(CsvTableEditorSwing tableEditor) {
8988
}
9089
int currentColumn = table.getSelectedColumn();
9190

92-
tableEditor.removeRows(Arrays.stream(currentRows).map(row -> table.convertRowIndexToModel(row)).boxed().collect(Collectors.toList()));
91+
tableEditor.removeRows(Arrays.stream(currentRows).map(table::convertRowIndexToModel).boxed().collect(Collectors.toList()));
9392

9493
selectCell(table, currentRows[0], currentColumn);
9594
} finally {
@@ -116,7 +115,7 @@ public void deleteSelectedColumns(CsvTableEditorSwing tableEditor) {
116115
tableEditor.removeColumns(
117116
Arrays.stream(selectedColumns)
118117
.filter(selectedColumn -> selectedColumn >= 0 && selectedColumn < columnCount)
119-
.map(col -> table.convertColumnIndexToModel(col))
118+
.map(table::convertColumnIndexToModel)
120119
.boxed()
121120
.collect(Collectors.toList())
122121
);
@@ -148,8 +147,8 @@ public void clearSelectedCells(CsvTableEditorSwing tableEditor) {
148147
int focusedColumn = table.getSelectedColumn();
149148

150149
tableEditor.clearCells(
151-
Arrays.stream(selectedRows).map(row -> table.convertRowIndexToModel(row)).boxed().collect(Collectors.toList()),
152-
Arrays.stream(selectedColumns).map(col -> table.convertColumnIndexToModel(col)).boxed().collect(Collectors.toList())
150+
Arrays.stream(selectedRows).map(table::convertRowIndexToModel).boxed().collect(Collectors.toList()),
151+
Arrays.stream(selectedColumns).map(table::convertColumnIndexToModel).boxed().collect(Collectors.toList())
153152
);
154153

155154
selectCell(table, focusedRow, focusedColumn);
@@ -167,10 +166,15 @@ private void selectCell(JTable table, int row, int column) {
167166
table.changeSelection(actualRow, actualColumn, false, false);
168167
}
169168

170-
private final class OpenTextEditor implements LinkListener {
169+
private final class OpenTextEditor implements LinkListener<Object> {
171170
@Override
172171
public void linkSelected(LinkLabel linkLabel, Object o) {
173-
FileEditorManager.getInstance(csvTableEditor.getProject()).openTextEditor(new OpenFileDescriptor(csvTableEditor.getProject(), csvTableEditor.getFile()), true);
172+
if (csvTableEditor.getProject() != null && csvTableEditor.getFile() != null) {
173+
FileEditorManager.getInstance(csvTableEditor.getProject()).openTextEditor(
174+
new OpenFileDescriptor(csvTableEditor.getProject(), csvTableEditor.getFile()),
175+
true
176+
);
177+
}
174178
}
175179
}
176180
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</constraints>
2727
<properties>
2828
<horizontalTextPosition value="10"/>
29-
<text value="Open file in text editor"/>
29+
<text resource-bundle="i18n/CSVEditorResources" key="open.file.in.text.editor"/>
3030
</properties>
3131
</component>
3232
<component id="157b0" class="javax.swing.JLabel" binding="lblErrorText">
@@ -37,7 +37,7 @@
3737
<properties>
3838
<font size="12" style="1"/>
3939
<foreground color="-65536"/>
40-
<text value=" Error while parsing content - please fix issues in text editor!"/>
40+
<text resource-bundle="i18n/CSVEditorResources" key="error.while.parsing.content.please.fix.issues.in.text.editor"/>
4141
</properties>
4242
</component>
4343
<component id="d8426" class="javax.swing.JToolBar$Separator">

0 commit comments

Comments
 (0)