What is 'message bus' and how to use it?

FileTypeManager.getInstance().addFileTypeListener() has been deprecated
javadoc: "Subscribe to #FILE_TYPES on any message bus level."

i didn't manage to find what is this message bus and how to use it properly

i assumed that  #FILE_TYPES is com.intellij.AppTopics#FILE_TYPES
and message bus is com.intellij.util.messages.MessageBus
but unfortunately the are no javadocs for these staff

1 comment
Comment actions Permalink

(how to) listen to "file opened" event with MessageBus :

public class FileOpenListenerA implements FileEditorManagerAdapter {

 public void fileOpened(@NotNull FileEditorManager manager,
                        @NotNull VirtualFile file) { /*  event handler  */ }

// add postStartupActivity Extension Point in plugin.xml
public class StartB implements StartupActivity {

 public void runActivity(@NotNull Project project) {
        StartupManager.getInstance(project).registerPostStartupActivity(() -> registerListenerA(project));

public void registerListenerA(Project project){
                MessageBusConnection cnn = project.getMessageBus().getParent().connect();
              cnn.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileOpenListenerA());


Please sign in to leave a comment.