13
13
import com .intellij .ide .BrowserUtil ;
14
14
import com .intellij .ide .plugins .IdeaPluginDescriptor ;
15
15
import com .intellij .ide .plugins .PluginManagerCore ;
16
- import com .intellij .notification .*;
16
+ import com .intellij .notification .Notification ;
17
+ import com .intellij .notification .NotificationType ;
17
18
import com .intellij .notification .impl .NotificationFullContent ;
19
+ import com .intellij .openapi .actionSystem .ActionManager ;
20
+ import com .intellij .openapi .actionSystem .AnAction ;
21
+ import com .intellij .openapi .actionSystem .Constraints ;
22
+ import com .intellij .openapi .actionSystem .DefaultActionGroup ;
23
+ import com .intellij .openapi .diagnostic .Logger ;
18
24
import com .intellij .openapi .extensions .PluginId ;
19
25
import com .intellij .openapi .project .DumbAwareAction ;
20
26
import com .intellij .openapi .project .Project ;
21
27
import com .intellij .openapi .startup .StartupActivity ;
22
28
import org .jetbrains .annotations .NotNull ;
29
+ import su .gov .headers .actions .CurlAction ;
23
30
import su .gov .headers .icons .PluginIcon ;
24
31
import su .gov .headers .setting .SettingsPersistentState ;
32
+ import su .gov .headers .transform .TransformScriptModel ;
33
+
34
+ import java .util .List ;
35
+ import java .util .Objects ;
25
36
26
37
public class HeadersPlugin implements StartupActivity {
38
+
39
+ private static final Logger LOGGER = Logger .getInstance (HeadersPlugin .class );
27
40
public static final String PLUGIN_ID = "su.gov.Header" ;
28
41
29
- public static final IdeaPluginDescriptor descriptor = PluginManagerCore . getPlugin ( PluginId .getId (PLUGIN_ID ) );
42
+ public static final PluginId ID = PluginId .getId (PLUGIN_ID );
30
43
31
- private static String version ;
44
+ public @ NotNull
45
+ static final IdeaPluginDescriptor DESCRIPTOR = Objects .requireNonNull (PluginManagerCore .getPlugin (ID ));
32
46
33
- private static String name ;
47
+ private static DefaultActionGroup CURL_ACTION_GROUP ;
34
48
35
- public static @ NotNull String getVersion () {
36
- if (version == null ) {
37
- assert descriptor != null ;
38
- version = descriptor .getVersion ();
49
+
50
+ public static void registerActions (ActionManager manager , List <TransformScriptModel > models ) {
51
+ unRegisterActions (manager , models );
52
+ LOGGER .debug ("Registering " + models + "to group:" + CURL_ACTION_GROUP );
53
+ for (int i = models .size () - 1 ; i >= 0 ; i --) {
54
+ CurlAction action = new CurlAction (models .get (i ));
55
+ manager .registerAction (action .getId (), action , HeadersPlugin .ID );
56
+ CURL_ACTION_GROUP .add (action , Constraints .FIRST );
39
57
}
40
- return version ;
41
58
}
42
59
43
- public static @ NotNull String getName () {
44
- if (name == null ) {
45
- assert descriptor != null ;
46
- name = descriptor .getName ();
60
+ public static void unRegisterActions (ActionManager manager , List <TransformScriptModel > models ) {
61
+ LOGGER .debug ("Unregistering " + models + "to group:" + CURL_ACTION_GROUP );
62
+ for (TransformScriptModel model : models ) {
63
+ AnAction action = manager .getActionOrStub (model .getId ());
64
+ if (action != null ) {
65
+ CURL_ACTION_GROUP .remove (action );
66
+ manager .unregisterAction (model .getId ());
67
+ }
47
68
}
48
- return name ;
69
+
49
70
}
50
71
51
72
static class WelcomeNotification extends Notification implements NotificationFullContent {
@@ -63,9 +84,13 @@ public WelcomeNotification() {
63
84
64
85
@ Override
65
86
public void runActivity (@ NotNull Project project ) {
87
+ ActionManager manager = ActionManager .getInstance ();
88
+ CURL_ACTION_GROUP = (DefaultActionGroup ) manager .getAction ("Headers.Group.CurlGroup" );
66
89
SettingsPersistentState state = SettingsPersistentState .getInstance ();
67
- if (!getVersion ().equals (state .getVersion ())) {
68
- state .setVersion (getVersion ());
90
+ registerActions (manager , state .getTransformModels ());
91
+ String version = state .getVersion ();
92
+ if (!DESCRIPTOR .getVersion ().equals (version )) {
93
+ state .setVersion (DESCRIPTOR .getVersion ());
69
94
new WelcomeNotification ().notify (project );
70
95
}
71
96
}
0 commit comments