Listeners declared in plugin.xml not working
已回答
Hello,
I am trying to register some listeners using the <applicationListeners> tag in the plugin.xml as shown in https://jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_listeners.html
They don't show up in any way, whether using println or breakpointing the listeners in the debugger.
I got this so far:
<applicationListeners>
<listener class="com.github.chicoferreira.projecttimecounter.listener.HeartbeatEditorMouseListener"
topic="com.intellij.openapi.editor.event.EditorMouseListener"/>
<listener class="com.github.chicoferreira.projecttimecounter.listener.HeartbeatVisibleAreaListener"
topic="com.intellij.openapi.editor.event.VisibleAreaListener"/>
</applicationListeners>
What I have in the plugin.xml inside <idea-plugin>
package com.github.chicoferreira.projecttimecounter.listener
import com.github.chicoferreira.projecttimecounter.HeartbeatService
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.event.EditorMouseEvent
import com.intellij.openapi.editor.event.EditorMouseListener
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.Project
class HeartbeatEditorMouseListener : EditorMouseListener {
override fun mousePressed(event: EditorMouseEvent) {
val instance = FileDocumentManager.getInstance()
val file = instance.getFile(event.editor.document)
if (file != null) {
HeartbeatService.registerHeartbeat(file)
}
}
}
package com.github.chicoferreira.projecttimecounter.listener
import com.github.chicoferreira.projecttimecounter.HeartbeatService
import com.intellij.openapi.editor.event.VisibleAreaEvent
import com.intellij.openapi.editor.event.VisibleAreaListener
import com.intellij.openapi.fileEditor.FileDocumentManager
class HeartbeatVisibleAreaListener : VisibleAreaListener {
override fun visibleAreaChanged(event: VisibleAreaEvent) {
val instance = FileDocumentManager.getInstance()
val file = instance.getFile(event.editor.document)
if (file != null) {
HeartbeatService.registerHeartbeat(file)
}
}
}
I am using kotlin and intellij 2020.2 for this project.
I already tested this classes written in java, changing <applicationListeners> to <projectListeners> (+adding Project to constructor) and setting activeInTestMode=true in both listeners. Nothing works.
Am I doing something wrong?
Thank you.
请先登录再写评论。
EditorMouseListener is supposed to be registered not as a project/application listener, but editorFactoryMouseListener Extension Point:
VisibleAreaListener should be registered directly with the Editor's ScrollingModel:
Jakub Chrzanowski Thank you so much. Where can I find more information about registering those and other listeners?
I've already posted above the working examples, but if you want more - please go through the intellij-community repository.
Jakub Chrzanowski Absolutely, thank you for the help.