Skip to content

Commit 21b7c1d

Browse files
committed
feat: Add some listener events in CodeXPEventListener
1 parent f31d2f5 commit 21b7c1d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.ilovegamecoding.intellijcodexp.listeners
2+
3+
import com.github.ilovegamecoding.intellijcodexp.services.CodeXPService
4+
import com.github.ilovegamecoding.intellijcodexp.model.CodeXPChallenge
5+
import com.intellij.ide.FrameStateListener
6+
import com.intellij.openapi.components.service
7+
import com.intellij.openapi.diagnostic.thisLogger
8+
import com.intellij.openapi.editor.EditorFactory
9+
import com.intellij.openapi.editor.event.DocumentEvent
10+
import com.intellij.openapi.editor.event.DocumentListener
11+
import com.intellij.openapi.editor.event.EditorFactoryEvent
12+
import com.intellij.openapi.editor.event.EditorFactoryListener
13+
14+
internal class CodeXPEventListener : DocumentListener, EditorFactoryListener, FrameStateListener {
15+
private val codeXPService = service<CodeXPService>()
16+
17+
init {
18+
val editorFactory = EditorFactory.getInstance()
19+
for (editor in editorFactory.allEditors) {
20+
editor.document.addDocumentListener(this)
21+
}
22+
editorFactory.addEditorFactoryListener(this) { }
23+
}
24+
25+
override fun documentChanged(event: DocumentEvent) {
26+
super.documentChanged(event)
27+
thisLogger().warn("CodeXPEventListener.documentChanged")
28+
codeXPService.increaseChallengeValue(CodeXPChallenge.Type.TYPING_COUNT, 1)
29+
}
30+
31+
override fun editorCreated(event: EditorFactoryEvent) {
32+
event.editor.document.addDocumentListener(this)
33+
}
34+
35+
override fun onFrameActivated() {
36+
37+
}
38+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@
1919
</application-components>
2020

2121
<applicationListeners>
22+
<listener class="com.github.ilovegamecoding.intellijcodexp.listeners.CodeXPEventListener"
23+
topic="com.intellij.ide.FrameStateListener"/>
24+
<listener class="com.github.ilovegamecoding.intellijcodexp.listeners.CodeXPEventListener"
25+
topic="com.intellij.openapi.editor.event.DocumentListener"/>
26+
<listener class="com.github.ilovegamecoding.intellijcodexp.listeners.CodeXPEventListener"
27+
topic="com.intellij.openapi.editor.event.EditorFactoryListener"/>
2228
</applicationListeners>
2329
</idea-plugin>

0 commit comments

Comments
 (0)