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

2 comments
Comment actions Permalink

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
Comment actions Permalink

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

Please sign in to leave a comment.