From 20c6781b671c768249b466baf7d88c90dc491455 Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 16:14:31 -0500 Subject: [PATCH 1/9] Fix: Failsafe acceptCsvFile check #882 --- .../plugins/csv/editor/CsvFileEditorProvider.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvFileEditorProvider.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvFileEditorProvider.java index 1a951949..76c961f2 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvFileEditorProvider.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvFileEditorProvider.java @@ -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 From 626603783f169fe99bdb71fccfa19bd3ab6d4133 Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 16:15:46 -0500 Subject: [PATCH 2/9] Fix: Read access is allowed from inside read-action only #878 --- .../intellij/plugins/csv/editor/table/CsvTableModelBase.java | 2 +- src/main/java/net/seesharpsoft/intellij/psi/PsiHelper.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableModelBase.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableModelBase.java index fb87d48f..7e7c3de6 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableModelBase.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableModelBase.java @@ -92,7 +92,7 @@ private void resetCachedValues() { } private void resetPointer() { - myPointedRecord = PsiTreeUtil.findChildOfType(getPsiFile(), CsvRecord.class); + myPointedRecord = PsiHelper.getFirstChildOfType(getPsiFile(), CsvRecord.class); myPointedRow = 0; } diff --git a/src/main/java/net/seesharpsoft/intellij/psi/PsiHelper.java b/src/main/java/net/seesharpsoft/intellij/psi/PsiHelper.java index 638e1bbb..a83d8463 100644 --- a/src/main/java/net/seesharpsoft/intellij/psi/PsiHelper.java +++ b/src/main/java/net/seesharpsoft/intellij/psi/PsiHelper.java @@ -19,6 +19,11 @@ public static IElementType getElementType(PsiElement element) { return element == null || element.getNode() == null ? null : element.getNode().getElementType(); } + @Nullable + public static T getFirstChildOfType(@NotNull final PsiElement parent, @NotNull Class aClass) { + return getNthChildOfType(parent, 0, aClass); + } + @Nullable public static T getNthChildOfType(@NotNull final PsiElement parent, int n, @NotNull Class aClass) { PsiElement firstChild = parent.getFirstChild(); From 77d1f5392b0c247117994147bdef4c53516309a6 Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 16:17:58 -0500 Subject: [PATCH 3/9] Chore: Improve check for CsvFile --- .../intellij/plugins/csv/CsvHelper.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java index 1da813f8..958c6be3 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java @@ -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; @@ -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; @@ -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); } From 70129bee8ab823a6359248dc2d4213a785d56459 Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 16:19:34 -0500 Subject: [PATCH 4/9] Chore: Code cleanup --- .../intellij/plugins/csv/CsvColumnInfo.java | 4 ++-- .../csv/actions/CsvCustomSeparatorAction.java | 2 +- .../csv/editor/table/CsvTableEditorProvider.java | 9 ++++----- .../table/swing/CsvMultiLineCellRenderer.java | 15 ++++++--------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvColumnInfo.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvColumnInfo.java index ec48819d..23f057d2 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvColumnInfo.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvColumnInfo.java @@ -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) { @@ -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); } } } diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/actions/CsvCustomSeparatorAction.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/actions/CsvCustomSeparatorAction.java index dffe5d34..cfdb1177 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/actions/CsvCustomSeparatorAction.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/actions/CsvCustomSeparatorAction.java @@ -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; } diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditorProvider.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditorProvider.java index 74efba20..cdd07835 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditorProvider.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditorProvider.java @@ -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; } @@ -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); } @@ -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); } }; diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvMultiLineCellRenderer.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvMultiLineCellRenderer.java index 5ace1383..f502aefd 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvMultiLineCellRenderer.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvMultiLineCellRenderer.java @@ -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; @@ -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; @@ -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()); @@ -153,9 +152,8 @@ public void cancelCellEditing() { protected void fireStopCellEditing() { ChangeEvent changeEvent = new ChangeEvent(this); synchronized (cellEditorListenerSet) { - Iterator it = cellEditorListenerSet.iterator(); - while (it.hasNext()) { - it.next().editingStopped(changeEvent); + for (CellEditorListener cellEditorListener : cellEditorListenerSet) { + cellEditorListener.editingStopped(changeEvent); } } } @@ -163,9 +161,8 @@ protected void fireStopCellEditing() { protected void fireCancelCellEditing() { ChangeEvent changeEvent = new ChangeEvent(this); synchronized (cellEditorListenerSet) { - Iterator it = cellEditorListenerSet.iterator(); - while (it.hasNext()) { - it.next().editingCanceled(changeEvent); + for (CellEditorListener cellEditorListener : cellEditorListenerSet) { + cellEditorListener.editingCanceled(changeEvent); } } } From e4c4b2430242c40a1dfe04fce1ec19ee5cd2e162 Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 16:20:41 -0500 Subject: [PATCH 5/9] Chore: Upgrade gradle to 8.10 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 171d8761..707e499a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 From 02906be7294b125a62e32991ce8bbf4abe891cfb Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 18:50:07 -0500 Subject: [PATCH 6/9] Feat: Support localization --- .../intellij/plugins/csv/CsvPlugin.java | 15 ++++++ .../swing/CsvTableEditorActionListeners.java | 20 ++++--- .../table/swing/CsvTableEditorSwing.form | 4 +- .../table/swing/CsvTableEditorSwing.java | 6 ++- .../CsvCodeStyleSettingsProvider.java | 19 +++---- .../csv/settings/CsvColorSettings.java | 21 ++++---- .../csv/settings/CsvEditorSettings.java | 14 ++--- .../settings/CsvEditorSettingsProvider.form | 54 +++++++++++-------- .../settings/CsvEditorSettingsProvider.java | 7 +-- .../CsvLanguageCodeStyleSettingsProvider.java | 38 +++++++------ .../i18n/CSVEditorResources.properties | 51 ++++++++++++++++++ 11 files changed, 170 insertions(+), 79 deletions(-) create mode 100644 src/main/resources/i18n/CSVEditorResources.properties diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java index b41bfee8..19cc2023 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java @@ -16,8 +16,12 @@ import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettingsProvider; import org.jetbrains.annotations.NotNull; +import java.util.ResourceBundle; + public class CsvPlugin implements StartupActivity, StartupActivity.DumbAware { + private static ResourceBundle _resourceBundle; + protected static IdeaPluginDescriptor getPluginDescriptor() { return PluginManagerCore.getPlugin(PluginId.getId("net.seesharpsoft.intellij.plugins.csv")); } @@ -101,4 +105,15 @@ public void runActivity(@NotNull Project project) { Notifications.Bus.notify(notification); } + + public static ResourceBundle getResourceBundle() { + if (_resourceBundle == null) { + _resourceBundle = ResourceBundle.getBundle("i18n/CSVEditorResources"); + } + return _resourceBundle; + } + + public static String getLocalizedText(String token) { + return getResourceBundle().getString(token); + } } \ No newline at end of file diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorActionListeners.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorActionListeners.java index ed97f946..ca9b7fb9 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorActionListeners.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorActionListeners.java @@ -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; @@ -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 openTextEditor = new OpenTextEditor(); public CsvTableEditorActionListeners(CsvTableEditorSwing tableEditor) { super(tableEditor); @@ -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 { @@ -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()) ); @@ -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); @@ -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 { @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 + ); + } } } } diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.form b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.form index 7772541a..08f17a4b 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.form +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.form @@ -26,7 +26,7 @@ - + @@ -37,7 +37,7 @@ - + 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 cfe1439e..da137a4e 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 @@ -26,7 +26,7 @@ public class CsvTableEditorSwing extends CsvTableEditor { private JTable tblEditor; private JPanel panelMain; - private LinkLabel lnkTextEditor; + private LinkLabel lnkTextEditor; private JLabel lblErrorText; private JScrollPane tableScrollPane; private JPanel panelTop; @@ -61,10 +61,12 @@ public CsvTableEditorSwing(@NotNull Project projectArg, @NotNull VirtualFile fil protected void createUIComponents() { tblEditor = new CsvTable(new CsvTableModelSwing(this)); tblEditor.setRowSorter(null); - lnkTextEditor = new LinkLabel("Open file in text editor", null); + lnkTextEditor = new LinkLabel<>("Open.file.in.text.editor", null); } private void initializedUIComponents() { + lnkTextEditor.setListener(this.tableEditorActions.openTextEditor, null); + EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); tblEditor.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvCodeStyleSettingsProvider.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvCodeStyleSettingsProvider.java index 9864f088..ef75f206 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvCodeStyleSettingsProvider.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvCodeStyleSettingsProvider.java @@ -8,27 +8,28 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.*; import net.seesharpsoft.intellij.plugins.csv.CsvLanguage; +import net.seesharpsoft.intellij.plugins.csv.CsvPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class CsvCodeStyleSettingsProvider extends CodeStyleSettingsProvider { @Override - public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) { + public CustomCodeStyleSettings createCustomSettings(@NotNull CodeStyleSettings settings) { return new CsvCodeStyleSettings(settings); } @Nullable @Override public String getConfigurableDisplayName() { - return "CSV/TSV/PSV"; + return CsvPlugin.getLocalizedText("settings.title"); } @NotNull @Override - public CodeStyleConfigurable createConfigurable(CodeStyleSettings settings, CodeStyleSettings originalSettings) { + public CodeStyleConfigurable createConfigurable(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings originalSettings) { return new CodeStyleAbstractConfigurable(settings, originalSettings, CsvLanguage.INSTANCE.getDisplayName()) { @Override - protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) { + protected @NotNull CodeStyleAbstractPanel createPanel(@NotNull CodeStyleSettings settings) { return new CsvCodeStyleMainPanel(getCurrentSettings(), settings); } @@ -64,8 +65,8 @@ public CsvWrappingPanel(CodeStyleSettings settings) { } @Override - public String getTabTitle() { - return "Wrapping"; + public @NotNull String getTabTitle() { + return CsvPlugin.getLocalizedText("settings.codestyle.wrapping"); } } @@ -75,8 +76,8 @@ public CsvSpacesPanel(CodeStyleSettings settings) { } @Override - protected String getTabTitle() { - return "Spaces"; + protected @NotNull String getTabTitle() { + return CsvPlugin.getLocalizedText("settings.codestyle.spaces"); } @Override @@ -85,7 +86,7 @@ public LanguageCodeStyleSettingsProvider.SettingsType getSettingsType() { } @Override - protected PsiFile doReformat(Project project, PsiFile psiFile) { + protected @NotNull PsiFile doReformat(Project project, @NotNull PsiFile psiFile) { CodeStyleManager.getInstance(project).reformatText(psiFile, 0, psiFile.getTextLength()); return psiFile; } 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 277bf6d1..6bc92c67 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 @@ -14,6 +14,7 @@ import com.intellij.openapi.util.UserDataHolder; import net.seesharpsoft.UnhandledSwitchCaseException; import net.seesharpsoft.intellij.plugins.csv.CsvIconProvider; +import net.seesharpsoft.intellij.plugins.csv.CsvPlugin; import net.seesharpsoft.intellij.plugins.csv.highlighter.CsvSyntaxHighlighter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.ResourceBundle; import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; @@ -46,20 +48,21 @@ public class CsvColorSettings implements ColorSettingsPage { private static final Key> COLUMN_COLORING_TEXT_ATTRIBUTES = Key.create("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTES"); static { - List attributesDescriptors = new ArrayList(); - attributesDescriptors.add(new AttributesDescriptor("Separator", COMMA)); - attributesDescriptors.add(new AttributesDescriptor("Quote", QUOTE)); - attributesDescriptors.add(new AttributesDescriptor("Text", TEXT)); - attributesDescriptors.add(new AttributesDescriptor("Escaped Text", ESCAPED_TEXT)); - attributesDescriptors.add(new AttributesDescriptor("Comment", COMMENT)); + List attributesDescriptors = new ArrayList<>(); + ResourceBundle bundle = CsvPlugin.getResourceBundle(); + attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.separator"), COMMA)); + attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.quote"), QUOTE)); + attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.text"), TEXT)); + attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.text.escaped"), ESCAPED_TEXT)); + attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.comment"), COMMENT)); COLUMN_COLORING_ATTRIBUTES = new ArrayList<>(); for (int i = 0; i < MAX_COLUMN_COLORING_COLORS; ++i) { TextAttributesKey textAttributesKey = createTextAttributesKey(String.format("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTE_%d", i), TEXT); COLUMN_COLORING_ATTRIBUTES.add(textAttributesKey); - attributesDescriptors.add(new AttributesDescriptor(String.format("Column Color %d", i + 1), textAttributesKey)); + attributesDescriptors.add(new AttributesDescriptor(String.format(bundle.getString("color.attribute.column.nr"), i + 1), textAttributesKey)); } - DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[attributesDescriptors.size()]); + DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[0]); } public static TextAttributesKey getTextAttributesKeys(int columnIndex) { @@ -150,6 +153,6 @@ public ColorDescriptor[] getColorDescriptors() { @NotNull @Override public String getDisplayName() { - return "CSV/TSV/PSV"; + return CsvPlugin.getLocalizedText("settings.title"); } } \ No newline at end of file diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java index 410c7633..e7262642 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java @@ -7,7 +7,9 @@ import com.intellij.openapi.components.Storage; import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; import com.intellij.util.xmlb.annotations.OptionTag; +import com.intellij.util.xmlb.annotations.Transient; import net.seesharpsoft.intellij.plugins.csv.CsvEscapeCharacter; +import net.seesharpsoft.intellij.plugins.csv.CsvPlugin; import net.seesharpsoft.intellij.plugins.csv.CsvStorageHelper; import net.seesharpsoft.intellij.plugins.csv.CsvValueSeparator; import org.jetbrains.annotations.NotNull; @@ -39,9 +41,9 @@ public class CsvEditorSettings implements PersistentStateComponent - + @@ -27,14 +27,14 @@ - + - + @@ -51,14 +51,14 @@ - + - + @@ -71,7 +71,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -92,14 +92,14 @@ - + - + @@ -115,7 +115,8 @@ - + + @@ -146,7 +147,8 @@ - + + @@ -177,7 +179,8 @@ - + + @@ -208,7 +211,7 @@ - + @@ -223,7 +226,8 @@ - + + @@ -245,7 +249,7 @@ - + @@ -254,7 +258,8 @@ - + + @@ -275,7 +280,7 @@ - + @@ -286,7 +291,7 @@ - + @@ -295,7 +300,8 @@ - + + @@ -324,7 +330,8 @@ - + + @@ -355,7 +362,7 @@ - + @@ -368,7 +375,7 @@ - + @@ -386,7 +393,8 @@ - + + diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettingsProvider.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettingsProvider.java index 477e459a..26970441 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettingsProvider.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettingsProvider.java @@ -10,6 +10,7 @@ import com.intellij.ui.JBColor; import com.intellij.util.FileContentUtilCore; import net.seesharpsoft.intellij.plugins.csv.CsvEscapeCharacter; +import net.seesharpsoft.intellij.plugins.csv.CsvPlugin; import net.seesharpsoft.intellij.plugins.csv.CsvValueSeparator; import net.seesharpsoft.intellij.ui.CustomDisplayListCellRenderer; import org.jetbrains.annotations.NotNull; @@ -55,12 +56,12 @@ public String getId() { @Override public String getDisplayName() { - return "CSV/TSV/PSV"; + return CsvPlugin.getLocalizedText("settings.title"); } @Override public String getHelpTopic() { - return "Editor Options for CSV/TSV/PSV files"; + return CsvPlugin.getLocalizedText("settings.editor.help"); } @Nullable @@ -163,7 +164,7 @@ protected void createUIComponents() { comboValueColoring = new ComboBox<>(CsvEditorSettings.ValueColoring.values()); comboValueColoring.setRenderer(new CustomDisplayListCellRenderer<>(CsvEditorSettings.ValueColoring::getDisplay)); - cbTabHighlightColor = new CheckBoxWithColorChooser("Highlight tab separator "); + cbTabHighlightColor = new CheckBoxWithColorChooser(CsvPlugin.getLocalizedText("settings.editor.highlight.tab.separator")); cbTabHighlightColor.setColor(JBColor.CYAN); NumberFormat numberFormat = NumberFormat.getIntegerInstance(); diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvLanguageCodeStyleSettingsProvider.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvLanguageCodeStyleSettingsProvider.java index aa862a61..810e4b9c 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvLanguageCodeStyleSettingsProvider.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvLanguageCodeStyleSettingsProvider.java @@ -5,8 +5,11 @@ import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider; import net.seesharpsoft.intellij.plugins.csv.CsvLanguage; +import net.seesharpsoft.intellij.plugins.csv.CsvPlugin; import org.jetbrains.annotations.NotNull; +import java.util.ResourceBundle; + public class CsvLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider { @NotNull @Override @@ -16,45 +19,46 @@ public Language getLanguage() { @Override public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @NotNull SettingsType settingsType) { + ResourceBundle bundle = CsvPlugin.getResourceBundle(); if (settingsType == SettingsType.LANGUAGE_SPECIFIC) { consumer.showCustomOption(CsvCodeStyleSettings.class, "SPACE_BEFORE_SEPARATOR", - "Space before separator", - "Separator"); + bundle.getString("group.separator.space.before"), + bundle.getString("group.separator")); consumer.showCustomOption(CsvCodeStyleSettings.class, "SPACE_AFTER_SEPARATOR", - "Space after separator", - "Separator"); + bundle.getString("group.separator.space.after"), + bundle.getString("group.separator")); consumer.showCustomOption(CsvCodeStyleSettings.class, "TABULARIZE", - "Format as table", - "Tabularize"); + bundle.getString("group.tabularize.as.table"), + bundle.getString("group.tabularize")); consumer.showCustomOption(CsvCodeStyleSettings.class, "WHITE_SPACES_OUTSIDE_QUOTES", - "Keep quoted value as is", - "Tabularize"); + bundle.getString("group.tabularize.keep.quoted"), + bundle.getString("group.tabularize")); consumer.showCustomOption(CsvCodeStyleSettings.class, "LEADING_WHITE_SPACES", - "Align right", - "Tabularize"); + bundle.getString("group.tabularize.align.right"), + bundle.getString("group.tabularize")); consumer.showCustomOption(CsvCodeStyleSettings.class, "ENABLE_WIDE_CHARACTER_DETECTION", - "Enhanced width calculation (slower)", - "Tabularize"); + bundle.getString("group.tabularize.enhanced.width.calculation"), + bundle.getString("group.tabularize")); // consumer.showCustomOption(CsvCodeStyleSettings.class, // "TREAT_AMBIGUOUS_CHARACTERS_AS_WIDE", // "Ambiguous as wide characters", -// "Tabularize"); +// bundle.getString("group.tabularize")); consumer.showCustomOption(CsvCodeStyleSettings.class, "TRIM_LEADING_WHITE_SPACES", - "Trim leading whitespaces", - "Trimming (only if not tabularized)"); + bundle.getString("group.trimming.leading"), + bundle.getString("group.trimming")); consumer.showCustomOption(CsvCodeStyleSettings.class, "TRIM_TRAILING_WHITE_SPACES", - "Trim trailing whitespaces", - "Trimming (only if not tabularized)"); + bundle.getString("group.trimming.trailing"), + bundle.getString("group.trimming")); } else if (settingsType == SettingsType.WRAPPING_AND_BRACES_SETTINGS) { consumer.showStandardOptions( CodeStyleSettingsCustomizable.WrappingOrBraceOption.WRAP_LONG_LINES.name(), diff --git a/src/main/resources/i18n/CSVEditorResources.properties b/src/main/resources/i18n/CSVEditorResources.properties new file mode 100644 index 00000000..c36f08cc --- /dev/null +++ b/src/main/resources/i18n/CSVEditorResources.properties @@ -0,0 +1,51 @@ +auto.detect.initially=auto-detect initially +can.be.adjusted.per.file.in.editor.context.menu=Can be adjusted per file in editor context menu +color.attribute.separator=Separator +color.attribute.quote=Quote +color.attribute.text=Text +color.attribute.text.escaped=Escaped text +color.attribute.comment=Comment +color.attribute.column.nr=Column Color %d +column.numbering=Column numbering: +default.column.width.in.px=Default column width in px (10 - 10000): +default.escape.character=Default Escape Character: +default.row.height.in.px=Default row height in px (20-100): +default.value.separator.csv.only=Default Value Separator (CSV only): +editor.usage=Editor usage: +enforce.value.quoting=Enforce value quoting +error.while.parsing.content.please.fix.issues.in.text.editor=\ Error while parsing content - please fix issues in text editor! +general=General +group.separator=Separator +group.separator.space.before=Space before separator +group.separator.space.after=Space after separator +group.tabularize=Tabularize +group.tabularize.as.table=Format as table +group.tabularize.keep.quoted=Keep quoted value as is +group.tabularize.align.right=Align right +group.tabularize.enhanced.width.calculation=Enhanced width calculation (slower) +group.trimming=Trimming (only if not tabularized) +group.trimming.leading=Trim leading whitespaces +group.trimming.trailing=Trim trailing whitespaces +highlight.caret.row=Highlight caret row +highlighting=Highlighting +keep.trailing.whitespaces.if.unchecked.general.editor.setting.apply=Keep trailing whitespaces (if unchecked, general editor setting apply) +line.comment.indicator=Line comment indicator: +maximum.column.width.in.px=Maximum column width in px (0 = no maximum): +open.file.in.text.editor=Open file in text editor +others=Others +settings.title=CSV/TSV/PSV +settings.codestyle.spaces=Spaces +settings.codestyle.wrapping=Wrapping +settings.editor.coloring.rainbow=Rainbow (Column Color) +settings.editor.coloring.simple=Simple (Text Color) +settings.editor.help=Editor Options for CSV/TSV/PSV files +settings.editor.highlight.tab.separator=Highlight tab separator +settings.editor.prio.table_first=Table editor first +settings.editor.prio.text_first=Text editor first +settings.editor.prio.text_only=Text editor only +show.info.balloon=Show info balloon +table.editor=Table Editor +text.editor=Text Editor +use.soft.wraps=Use soft wraps +value.coloring=Value Coloring: +zero.based=Zero-based \ No newline at end of file From 2ba2bcd520ec84ba9d3ebdfa2a311b5731179b7b Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 19:50:03 -0500 Subject: [PATCH 7/9] Chore: Use ProjectActivity instead of StartupActivity --- .../intellij/plugins/csv/CsvPlugin.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java index 19cc2023..ed27a98c 100644 --- a/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java +++ b/src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java @@ -9,16 +9,20 @@ 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; import java.util.ResourceBundle; -public class CsvPlugin implements StartupActivity, StartupActivity.DumbAware { +public class CsvPlugin implements ProjectActivity, DumbAware { private static ResourceBundle _resourceBundle; @@ -70,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 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( @@ -104,6 +108,8 @@ public void runActivity(@NotNull Project project) { })); Notifications.Bus.notify(notification); + + return continuation; } public static ResourceBundle getResourceBundle() { @@ -116,4 +122,6 @@ public static ResourceBundle getResourceBundle() { public static String getLocalizedText(String token) { return getResourceBundle().getString(token); } + + } \ No newline at end of file From 997c646fcc89f3d122df395f43b893ca05bd064f Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 1 Dec 2024 19:51:20 -0500 Subject: [PATCH 8/9] Prepare update to 4.0.1 --- CHANGELOG.md | 20 +++++++++++++++++++- gradle.properties | 3 +-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe7a0972..8438b577 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,25 @@ ### Fixed -## [4.0.0] - Oct 07, 2024 +## [4.0.1] - Dec 01, 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! diff --git a/gradle.properties b/gradle.properties index 1a60b793..cbc2835f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginName=CSV Editor pluginId=net.seesharpsoft.intellij.plugins.csv -pluginVersion=4.0.0 +pluginVersion=4.0.1 pluginSinceBuild=242 @@ -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 - From 267bf37d617f3081bb45161f752d8eeeb846f7fa Mon Sep 17 00:00:00 2001 From: GeeK Date: Sun, 8 Dec 2024 19:51:23 -0500 Subject: [PATCH 9/9] Release 4.0.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8438b577..b18c1f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Fixed -## [4.0.1] - Dec 01, 2024 +## [4.0.1] - Dec 08, 2024 ### Added