How to publish my Topic to other plugin

I have two different plugin projects.

In my fisrt plugin,I publish my Topic

@Override
public void actionPerformed(AnActionEvent e) {
if(e.getProject()!=null){
System.out.println("1 step");
MessageBus bus=e.getProject().getMessageBus();
Messages.showMessageDialog(e.getProject().toString(),"123",null);
bus.syncPublisher(ChangeActionNotifier.CHANGE_ACTION_TOPIC).afterAction();
}
System.out.println("haha4");
}

In my second plugin ,I subscribe it.
@Override
public void actionPerformed(AnActionEvent e) {
if(conn==null&& e.getProject()!=null){
Messages.showMessageDialog(e.getProject().toString(),"1243",null);
conn= e.getProject().getMessageBus().connect();
conn.setDefaultHandler(new MessageHandler() {
@Override
public void handle(Method method, Object... objects) {
System.out.println("haha i handle u");
Utils.openBrowser("https://www.atatech.org/");
}
});
conn.subscribe(ChangeActionNotifier.CHANGE_ACTION_TOPIC);
}
}
And my interface is :
public interface ChangeActionNotifier {
Topic<ChangeActionNotifier> CHANGE_ACTION_TOPIC = Topic.create("web browser", ChangeActionNotifier.class,Topic.BroadcastDirection.TO_PARENT);

void afterAction();
}
But my subcriber can't receive the message.
1
3 comments
Avatar
Permanently deleted user

I find a way by using action.But how to deliver message?

@Override
public void actionPerformed(AnActionEvent e) {
ActionManager inst = ActionManager.getInstance();
AnAction other = inst.getAction("MergeRequest"); // another plugin's action
other.actionPerformed(e);
}


0

Firstly you need to add a dependency from the second plugin to the first plugin (see our docs) and ensure that ChangeActionNotifier interface is packed into the first plugin only (otherwise the second plugin will use its own version of ChangeActionNotifier and event won't be delivered).

Also note that 'actionPerformed' method is called only when user invokes the action, so the second plugin will get the message only if you invoke that action in it before invoking the action in the first plugin. 

And it's better to pass an instance of ChangeActionNotifier to 'subscribe' method instead of using 'setDefaultHandler', this will be more convenient after you add more methods to ChangeActionNotifier or add parameters to them.

0

The docs don't explain how to add one plugin as a dependency when both plugins are being locally developed.

I saw this approach: project(':projectName') however I am not able to create the dependency. Can you explain how I can create the dependency and how the projects should be organised? I've tried multiple methods but the second plugin still seems to use it's own version of the Notifier so the message isn't delivered.

 

 

0

Please sign in to leave a comment.