Is it possible to trigger function/action of another plugin from a plugin.

HI,

I have two plugins. ProjPlugin handles project related operations. UserActions plugin listens to user actions. Is it possible to trigger ProjPlugins related action (say, refresh project) from UserActions plugin?
Alternative is to move the UserActions code to ProjPlugin.

Thanks,
Chandra

0

Hello chandra,

Yes. You can call ActionManager.getAction() to retrieve the action of any
plugin by ID.

Alternatively, you can make the UserActions plugin depend on the ProjPlugin
and call the necessary method directly.

I have two plugins. ProjPlugin handles project related operations.
UserActions plugin listens to user actions. Is it possible to trigger
ProjPlugins related action (say, refresh project) from UserActions
plugin?

Alternative is to move the UserActions code to ProjPlugin.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

An example would be the following, which can be used to copy the FQN of a class in python into the clipboard:

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;


public class CopyReferenceTrigger extends AnAction {

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_COPY_REFERENCE);
action.actionPerformed(event);
}

@Override
public void update(AnActionEvent e) {
Project project = e.getProject();
e.getPresentation().setEnabledAndVisible(project != null);
}
}
0

Does getAction also allow invoking actions which are part of the UI as shipped, e.g. any action that is included in PyCharm? or is it constrained to invoking actions introduced by plugins?

0

请先登录再写评论。