Skip to content

Commit 8d71948

Browse files
committed
[FEATURE] Startup activity showing a notification if new version installed
1 parent 01db0e5 commit 8d71948

File tree

6 files changed

+107
-9
lines changed

6 files changed

+107
-9
lines changed

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

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

3-
import com.intellij.ide.scratch.ScratchFileType;
43
import com.intellij.ide.scratch.ScratchUtil;
54
import com.intellij.lang.*;
65
import com.intellij.lexer.Lexer;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package net.seesharpsoft.intellij.plugins.csv;
2+
3+
import com.intellij.ide.actions.ShowSettingsUtilImpl;
4+
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl;
5+
import com.intellij.ide.plugins.PluginManager;
6+
import com.intellij.notification.*;
7+
import com.intellij.openapi.extensions.PluginId;
8+
import com.intellij.openapi.options.ShowSettingsUtil;
9+
import com.intellij.openapi.project.Project;
10+
import com.intellij.openapi.startup.StartupActivity;
11+
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
12+
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettingsProvider;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
import javax.swing.event.HyperlinkEvent;
16+
import java.awt.*;
17+
import java.io.IOException;
18+
import java.net.URI;
19+
20+
public class CsvPlugin implements StartupActivity {
21+
22+
protected static IdeaPluginDescriptorImpl getPluginDescriptor() {
23+
return (IdeaPluginDescriptorImpl)PluginManager.getPlugin(PluginId.getId("net.seesharpsoft.intellij.plugins.csv"));
24+
}
25+
26+
protected static String getVersion() {
27+
return getPluginDescriptor().getVersion();
28+
}
29+
30+
protected static String getChangeNotes() {
31+
return getPluginDescriptor().getChangeNotes();
32+
}
33+
34+
private static final String SETTINGS_URL = "#Settings";
35+
36+
private static void openLink(Project project, String link) {
37+
if (!project.isDisposed() && link.startsWith("#")) {
38+
((ShowSettingsUtilImpl)ShowSettingsUtil.getInstance()).showSettingsDialog(project, link.substring(1), null);
39+
}
40+
if (Desktop.isDesktopSupported()) {
41+
Desktop desktop = Desktop.getDesktop();
42+
if (desktop.isSupported(Desktop.Action.BROWSE)) {
43+
try {
44+
desktop.browse(URI.create(link));
45+
} catch (IOException e) {
46+
e.printStackTrace();
47+
}
48+
}
49+
}
50+
}
51+
52+
@Override
53+
public void runActivity(@NotNull Project project) {
54+
if (CsvEditorSettings.getInstance().checkCurrentPluginVersion(getVersion())) {
55+
return;
56+
}
57+
58+
NotificationGroup notificationGroup = new NotificationGroup(
59+
"CsvPlugin", NotificationDisplayType.STICKY_BALLOON, true
60+
);
61+
62+
NotificationListener.Adapter notificationListener = new NotificationListener.Adapter() {
63+
@Override
64+
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
65+
openLink(project, e.getDescription());
66+
}
67+
};
68+
69+
Notification notification = notificationGroup.createNotification(
70+
"CSV Plugin " + getVersion() + " - Change Notes",
71+
getChangeNotes() +
72+
"<p><b>Customize plugin settings:</b> " +
73+
"<a href=\"#" + CsvEditorSettingsProvider.CSV_EDITOR_SETTINGS_ID + "\">Editor/General</a>, " +
74+
"<a href=\"#reference.settingsdialog.IDE.editor.colors.CSV/TSV/PSV\">Color Scheme</a>, " +
75+
"<a href=\"#preferences.sourceCode.CSV/TSV/PSV\">Formatting</a></p>" +
76+
"<br>" +
77+
"<p>Visit the <a href=\"https://github.com/SeeSharpSoft/intellij-csv-validator\">CSV Plugin GitHub</a> to read more about the available features & settings, " +
78+
"submit <a href=\"https://github.com/SeeSharpSoft/intellij-csv-validator/issues\">issues & feature request</a>, " +
79+
"or show your support by <a href=\"https://plugins.jetbrains.com/plugin/10037-csv-plugin\">rating this plugin</a>. <b>Thanks!</b></p>"
80+
,
81+
NotificationType.INFORMATION,
82+
notificationListener
83+
);
84+
85+
Notifications.Bus.notify(notification);
86+
}
87+
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.seesharpsoft.intellij.plugins.csv.settings;
22

3-
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
43
import com.intellij.openapi.editor.colors.EditorColorsManager;
54
import com.intellij.openapi.editor.colors.EditorColorsScheme;
65
import com.intellij.openapi.editor.colors.TextAttributesKey;

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import com.intellij.openapi.components.Storage;
77
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
88
import com.intellij.util.xmlb.annotations.OptionTag;
9-
import net.seesharpsoft.intellij.plugins.csv.CsvEscapeCharacter;
10-
import net.seesharpsoft.intellij.plugins.csv.CsvStorageHelper;
11-
import net.seesharpsoft.intellij.plugins.csv.CsvValueSeparator;
9+
import net.seesharpsoft.intellij.plugins.csv.*;
1210
import org.jetbrains.annotations.NotNull;
1311

1412
import java.awt.*;
@@ -58,6 +56,8 @@ public String getDisplay() {
5856
}
5957

6058
public static final class OptionSet {
59+
public String CURRENT_PLUGIN_VERSION;
60+
6161
public boolean CARET_ROW_SHOWN;
6262
public boolean USE_SOFT_WRAP;
6363
public boolean HIGHTLIGHT_TAB_SEPARATOR = true;
@@ -292,4 +292,13 @@ public ColumnColoring getColumnColoring() {
292292
public void setColumnColoring(ColumnColoring columnColoring) {
293293
getState().COLUMN_COLORING = columnColoring;
294294
}
295+
296+
public boolean checkCurrentPluginVersion(String actualVersion) {
297+
return false;
298+
// if (!actualVersion.equals(getState().CURRENT_PLUGIN_VERSION)) {
299+
// getState().CURRENT_PLUGIN_VERSION = actualVersion;
300+
// return false;
301+
// }
302+
// return true;
303+
}
295304
}

src/main/resources/META-INF/plugin.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<p>
3434
<b>TSV/PSV file support:</b> <em>TSV/PSV files are recognized as such but treated as a variant of CSV files, the same syntax highlighting and code style settings are applied.</em>
3535
<br><br>
36-
<b>Code formatting:</b> <em>Default code formatting is 'Tabularize'. Can be changed in Settings -> Editor -> Code Style -> CSV</em>
36+
<b>Code formatting:</b> <em>Default code formatting is 'Tabularize'. Can be changed in Settings -> Editor -> Code Style -> CSV/TSV/PSV</em>
3737
<br><br>
3838
For more detailed information please have a look at the <a href="https://github.com/SeeSharpSoft/intellij-csv-validator/blob/master/README.md">README</a>.
3939
<br><br><br>
@@ -49,7 +49,9 @@
4949

5050
<change-notes><![CDATA[
5151
<pre style="font-family: sans-serif">
52-
NEW: Support for customizable line comments ('#' indicates a line comment per default - can be customized/deactivated via settings)
52+
NEW: Predefined column colors (Rainbow-style)
53+
NEW: Enhanced color scheme switch
54+
NEW: Table Editor coloring
5355
</pre>
5456
]]>
5557
</change-notes>
@@ -161,6 +163,8 @@ NEW: Support for customizable line comments ('#' indicates a line comment per de
161163
</intentionAction>
162164

163165
<stripTrailingSpacesFilterFactory implementation="net.seesharpsoft.intellij.plugins.csv.settings.CsvStripTrailingSpacesFilterFactory" />
166+
167+
<postStartupActivity implementation="net.seesharpsoft.intellij.plugins.csv.CsvPlugin" />
164168
</extensions>
165169

166170
<actions>

src/test/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettingsProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void testResetAndModified() throws ConfigurationException {
7878
csvEditorSettings.setDefaultValueSeparator(CsvValueSeparator.PIPE);
7979
csvEditorSettings.setKeepTrailingSpaces(true);
8080
csvEditorSettings.setCommentIndicator("//");
81-
csvEditorSettings.setColumnColoring(CsvEditorSettings.ColumnColoring.TEXT);
81+
csvEditorSettings.setColumnColoring(CsvEditorSettings.ColumnColoring.SIMPLE);
8282

8383
assertEquals(true, editorSettingsPanel.isModified());
8484

@@ -101,7 +101,7 @@ public void testResetAndModified() throws ConfigurationException {
101101
assertEquals(CsvValueSeparator.PIPE, csvEditorSettings.getDefaultValueSeparator());
102102
assertEquals(true, csvEditorSettings.getKeepTrailingSpaces());
103103
assertEquals("//", csvEditorSettings.getCommentIndicator());
104-
assertEquals( CsvEditorSettings.ColumnColoring.TEXT, csvEditorSettings.getColumnColoring());
104+
assertEquals( CsvEditorSettings.ColumnColoring.SIMPLE, csvEditorSettings.getColumnColoring());
105105

106106
editorSettingsPanel.disposeUIResources();
107107
}

0 commit comments

Comments
 (0)