How do I create a listener when a new file editor is opened

Hi,
     I am writing a plugin and I want to do a defined ation after I open a file. How can I do this?

Thanks.

3 comments
Comment actions Permalink

see com.intellij.openapi.fileEditor.FileEditorManagerListener which can be registered via com.intellij.openapi.fileEditor.FileEditorManager#addFileEditorManagerListener()

0
Comment actions Permalink

Thank you for your answer. It works

0
Comment actions Permalink

FileEditorManager.addFileEditorManagerListener() is deprecated. You can use MessageBus.

MessageBus messageBus = project.getMessageBus();
messageBus.connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
super.fileOpened(source, file);
}

@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
super.fileClosed(source, file);
}

@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
super.selectionChanged(event);
}
});
0

Please sign in to leave a comment.