Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.0.1 #884

Merged
merged 10 commits into from
Dec 9, 2024
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@

### Fixed

## [4.0.0] - Oct 07, 2024
## [4.0.1] - Dec 08, 2024

### Added

- Localization support

### Changed

- Upgrade to gradle 8.10
- Improve check for CsvFile
- Code cleanup

### Fixed

- Read access is allowed from inside read-action only #878
- Failsafe acceptCsvFile check #882
- Use ProjectActivity instead of StartupActivity

## 4.0.0 - Oct 07, 2024

### Added
- Tabularize formatting is back!
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

pluginName=CSV Editor
pluginId=net.seesharpsoft.intellij.plugins.csv
pluginVersion=4.0.0
pluginVersion=4.0.1

pluginSinceBuild=242

Expand All @@ -19,4 +19,3 @@ org.gradle.parallel=true
# Opt-out flag for bundling Kotlin standard library.
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
kotlin.stdlib.default.dependency=false

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class RowInfo {
this(element, row, -1, -1);
}

RowInfo(@NotNull T element, @NotNull int row, int startIndex, int endIndex) {
RowInfo(@NotNull T element, int row, int startIndex, int endIndex) {
this.myElement = element;
this.myRow = row;
if (startIndex <= endIndex && startIndex >= 0) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public boolean equals(Object other) {
if (!(other instanceof CsvColumnInfo.RowInfo)) {
return false;
}
return this.myElement.equals(((RowInfo) other).myElement);
return this.myElement.equals(((CsvColumnInfo<?>.RowInfo) other).myElement);
}
}
}
26 changes: 8 additions & 18 deletions src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.intellij.lang.*;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
Expand All @@ -22,8 +21,6 @@
import net.seesharpsoft.intellij.plugins.csv.psi.CsvRecord;
import net.seesharpsoft.intellij.plugins.csv.psi.CsvTypes;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
import net.seesharpsoft.intellij.plugins.psv.PsvFileType;
import net.seesharpsoft.intellij.plugins.tsv.TsvFileType;
import net.seesharpsoft.intellij.psi.PsiHelper;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -58,26 +55,19 @@ public static boolean isCsvFile(String extension) {
if (extension == null) {
return false;
}
// simple check to always in include the defaults even if association was removed
switch (extension.toLowerCase()) {
case "csv":
case "tsv":
case "tab":
case "psv":
return true;
default:
// but also consider other extensions that are associated manually
FileType fileType = FileTypeRegistry.getInstance().getFileTypeByExtension(extension);
return fileType == CsvFileType.INSTANCE ||
fileType == TsvFileType.INSTANCE ||
fileType == PsvFileType.INSTANCE;
}
Language language = LanguageUtil.getFileTypeLanguage(
FileTypeRegistry.getInstance().getFileTypeByExtension(extension)
);
return language != null && language.isKindOf(CsvLanguage.INSTANCE);
}

public static boolean isCsvFile(Project project, VirtualFile file) {
if (project == null || file == null || !isCsvFile(file.getExtension())) {
if (file == null) {
return false;
}
if (project == null) {
return isCsvFile(file.getExtension());
}
final Language language = LanguageUtil.getLanguageForPsi(project, file);
return language != null && language.isKindOf(CsvLanguage.INSTANCE);
}
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.startup.ProjectActivity;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import net.seesharpsoft.intellij.plugins.csv.components.CsvFileAttributes;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettingsProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CsvPlugin implements StartupActivity, StartupActivity.DumbAware {
import java.util.ResourceBundle;

public class CsvPlugin implements ProjectActivity, DumbAware {

private static ResourceBundle _resourceBundle;

protected static IdeaPluginDescriptor getPluginDescriptor() {
return PluginManagerCore.getPlugin(PluginId.getId("net.seesharpsoft.intellij.plugins.csv"));
}
Expand Down Expand Up @@ -66,12 +74,12 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
}

@Override
public void runActivity(@NotNull Project project) {
public @Nullable Object execute(@NotNull Project project, @NotNull Continuation<? super Unit> continuation) {
doAsyncProjectMaintenance(project);

NotificationGroup notificationGroup = NotificationGroupManager.getInstance().getNotificationGroup("net.seesharpsoft.intellij.plugins.csv");
if (notificationGroup == null || CsvEditorSettings.getInstance().checkCurrentPluginVersion(getVersion())) {
return;
return continuation;
}

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

Notifications.Bus.notify(notification);

return continuation;
}

public static ResourceBundle getResourceBundle() {
if (_resourceBundle == null) {
_resourceBundle = ResourceBundle.getBundle("i18n/CSVEditorResources");
}
return _resourceBundle;
}

public static String getLocalizedText(String token) {
return getResourceBundle().getString(token);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setSelected(@NotNull AnActionEvent anActionEvent, boolean selected)
if (customValueSeparator == null) {
return;
}
if (customValueSeparator.length() == 0 || customValueSeparator.contains(" ")) {
if (customValueSeparator.isEmpty() || customValueSeparator.contains(" ")) {
JOptionPane.showMessageDialog(fileEditor == null ? null : fileEditor.getComponent(), "Value separator must have at least one character and no spaces!");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ public class CsvFileEditorProvider implements AsyncFileEditorProvider, DumbAware
public static final String EDITOR_TYPE_ID = "csv-text-editor";

public static boolean acceptCsvFile(@NotNull Project project, @NotNull VirtualFile file) {
return CsvHelper.isCsvFile(project, file)
&& !SingleRootFileViewProvider.isTooLargeForContentLoading(file)
&& !SingleRootFileViewProvider.isTooLargeForIntelligence(file)
&& !(file instanceof DiffViewerVirtualFile);
try {
return !SingleRootFileViewProvider.isTooLargeForContentLoading(file)
&& !SingleRootFileViewProvider.isTooLargeForIntelligence(file)
&& !(file instanceof DiffViewerVirtualFile)
&& CsvHelper.isCsvFile(project, file);
} catch(Exception exc) {
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CsvTableEditorProvider implements AsyncFileEditorProvider, DumbAwar
public static final String EDITOR_TYPE_ID = "csv-table-editor";

@Override
public String getEditorTypeId() {
public @NotNull String getEditorTypeId() {
return EDITOR_TYPE_ID;
}

Expand Down Expand Up @@ -48,16 +48,15 @@ public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile vi
}

@Override
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
public @NotNull FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
return CsvTableEditorState.create(sourceElement, project, file);
}

@Override
public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
if (!(state instanceof CsvTableEditorState)) {
if (!(state instanceof CsvTableEditorState csvTableEditorState)) {
return;
}
CsvTableEditorState csvTableEditorState = (CsvTableEditorState) state;
csvTableEditorState.write(project, targetElement);
}

Expand All @@ -66,7 +65,7 @@ public void writeState(@NotNull FileEditorState state, @NotNull Project project,
public Builder createEditorAsync(@NotNull Project project, @NotNull VirtualFile virtualFile) {
return new Builder() {
@Override
public FileEditor build() {
public @NotNull FileEditor build() {
return new CsvTableEditorSwing(project, virtualFile);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void resetCachedValues() {
}

private void resetPointer() {
myPointedRecord = PsiTreeUtil.findChildOfType(getPsiFile(), CsvRecord.class);
myPointedRecord = PsiHelper.getFirstChildOfType(getPsiFile(), CsvRecord.class);
myPointedRow = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.UserDataHolder;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvColorSettings;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor;
Expand All @@ -21,7 +21,6 @@
import java.awt.event.KeyEvent;
import java.awt.geom.Rectangle2D;
import java.util.EventObject;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

Expand Down Expand Up @@ -80,7 +79,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
myTextArea.setBackground(UIManager.getColor(editorColorsScheme.getDefaultBackground()));
}
} else {
myTextArea.setBorder(new EmptyBorder(1, 2, 1, 2));
myTextArea.setBorder(JBUI.Borders.empty(1, 2));
}

this.setFont(table.getFont());
Expand Down Expand Up @@ -153,19 +152,17 @@ public void cancelCellEditing() {
protected void fireStopCellEditing() {
ChangeEvent changeEvent = new ChangeEvent(this);
synchronized (cellEditorListenerSet) {
Iterator<CellEditorListener> it = cellEditorListenerSet.iterator();
while (it.hasNext()) {
it.next().editingStopped(changeEvent);
for (CellEditorListener cellEditorListener : cellEditorListenerSet) {
cellEditorListener.editingStopped(changeEvent);
}
}
}

protected void fireCancelCellEditing() {
ChangeEvent changeEvent = new ChangeEvent(this);
synchronized (cellEditorListenerSet) {
Iterator<CellEditorListener> it = cellEditorListenerSet.iterator();
while (it.hasNext()) {
it.next().editingCanceled(changeEvent);
for (CellEditorListener cellEditorListener : cellEditorListenerSet) {
cellEditorListener.editingCanceled(changeEvent);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;

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

protected LinkListener openTextEditor = new OpenTextEditor();
protected LinkListener<Object> openTextEditor = new OpenTextEditor();

public CsvTableEditorActionListeners(CsvTableEditorSwing tableEditor) {
super(tableEditor);
Expand Down Expand Up @@ -89,7 +88,7 @@ public void deleteSelectedRows(CsvTableEditorSwing tableEditor) {
}
int currentColumn = table.getSelectedColumn();

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

selectCell(table, currentRows[0], currentColumn);
} finally {
Expand All @@ -116,7 +115,7 @@ public void deleteSelectedColumns(CsvTableEditorSwing tableEditor) {
tableEditor.removeColumns(
Arrays.stream(selectedColumns)
.filter(selectedColumn -> selectedColumn >= 0 && selectedColumn < columnCount)
.map(col -> table.convertColumnIndexToModel(col))
.map(table::convertColumnIndexToModel)
.boxed()
.collect(Collectors.toList())
);
Expand Down Expand Up @@ -148,8 +147,8 @@ public void clearSelectedCells(CsvTableEditorSwing tableEditor) {
int focusedColumn = table.getSelectedColumn();

tableEditor.clearCells(
Arrays.stream(selectedRows).map(row -> table.convertRowIndexToModel(row)).boxed().collect(Collectors.toList()),
Arrays.stream(selectedColumns).map(col -> table.convertColumnIndexToModel(col)).boxed().collect(Collectors.toList())
Arrays.stream(selectedRows).map(table::convertRowIndexToModel).boxed().collect(Collectors.toList()),
Arrays.stream(selectedColumns).map(table::convertColumnIndexToModel).boxed().collect(Collectors.toList())
);

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

private final class OpenTextEditor implements LinkListener {
private final class OpenTextEditor implements LinkListener<Object> {
@Override
public void linkSelected(LinkLabel linkLabel, Object o) {
FileEditorManager.getInstance(csvTableEditor.getProject()).openTextEditor(new OpenFileDescriptor(csvTableEditor.getProject(), csvTableEditor.getFile()), true);
if (csvTableEditor.getProject() != null && csvTableEditor.getFile() != null) {
FileEditorManager.getInstance(csvTableEditor.getProject()).openTextEditor(
new OpenFileDescriptor(csvTableEditor.getProject(), csvTableEditor.getFile()),
true
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</constraints>
<properties>
<horizontalTextPosition value="10"/>
<text value="Open file in text editor"/>
<text resource-bundle="i18n/CSVEditorResources" key="open.file.in.text.editor"/>
</properties>
</component>
<component id="157b0" class="javax.swing.JLabel" binding="lblErrorText">
Expand All @@ -37,7 +37,7 @@
<properties>
<font size="12" style="1"/>
<foreground color="-65536"/>
<text value=" Error while parsing content - please fix issues in text editor!"/>
<text resource-bundle="i18n/CSVEditorResources" key="error.while.parsing.content.please.fix.issues.in.text.editor"/>
</properties>
</component>
<component id="d8426" class="javax.swing.JToolBar$Separator">
Expand Down
Loading
Loading