Registering actions programatically with ActionManager
Hello All,
I am migrating the plugin from the deprecated component-way to the modern services-listeners-extensions one.
I used to create actions for the context menu as it was described at https://confluence.jetbrains.com/pages/viewpage.action?pageId=36017181
// If you register the MyPluginRegistration class in the <application-components> section of// the plugin.xml file, this method is called on IDEA start-up. public void initComponent() {
ActionManager am = ActionManager.getInstance();
TextBoxes action = new TextBoxes();
// Passes an instance of your custom TextBoxes class to the registerAction method of the ActionManager class.
am.registerAction("MyPluginAction", action);
However, with latest IDEA this initComponent() method is not invoked anymore for the plugin and there is a link in API to follow:
components are deprecated... Please see
* http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_components.html for guidelines on migrating to other APIs.
I tried to move the actions-specific code into listeners and services, but none of them allow to execute the line ActionManager.getInstance():
Instead they throw:
java.lang.NullPointerException
at com.intellij.openapi.actionSystem.ActionManager.getInstance(ActionManager.java:39)
at my.plugin.PluginService.initActions(InstantPatchRemotePluginService.java:32)
at my.plugin.AppLifecycleListener.toolWindowRegistered(InstantPatchRemoteAppLifecycleListener.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.intellij.util.messages.impl.MessageBusImpl.invokeListener(MessageBusImpl.java:546)
at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:139)
at com.intellij.u...
Is there some specific point in the plugin lifecycle where the actions may be instantiated now?
Thanks
Please sign in to leave a comment.
I will add an update:
The threads that happens in are either
or
There are also few warnings in the console when I run the runIde gradle task (may be they have some consequences)
In the first post, you're referring to the outdated docs - please use https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html instead.
Please also follow the Dynamic Plugins for more information about the migration and troubleshooting.
Using older approach is essentially what I described in my question, and I attempted to migrate to the newer one.
After the migration there are Actions which can not be instantiated due to
Could you suggest how to overcome that please?