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
+ }
0 commit comments