Skip to content

Commit

Permalink
Add listeners for AceJump lifecycle
Browse files Browse the repository at this point in the history
External systems can now be notified about finishing of AceJump work
  • Loading branch information
AlexPl292 committed Oct 15, 2019
1 parent 01e7ce0 commit 622ba42
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/kotlin/org/acejump/control/Handler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.openapi.editor.actionSystem.*
import com.intellij.openapi.editor.colors.EditorColors.CARET_COLOR
import com.intellij.openapi.editor.colors.EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.util.containers.ContainerUtil
import org.acejump.control.Scroller.restoreScroll
import org.acejump.control.Scroller.saveScroll
import org.acejump.label.Pattern
Expand All @@ -27,6 +28,7 @@ import java.awt.Color
*/

object Handler : TypedActionHandler, Resettable {
private val listeners: MutableList<AceJumpListener> = ContainerUtil.createLockFreeCopyOnWriteList()
private val logger = Logger.getInstance(Handler::class.java)
private var enabled = false
private val typingAction = EditorActionManager.getInstance().typedAction
Expand Down Expand Up @@ -111,10 +113,21 @@ object Handler : TypedActionHandler, Resettable {
override fun reset() {
if (enabled) Listener.disable()

// In order to get Finder.query value, listeners should
// be placed before cleanup
listeners.forEach(AceJumpListener::finished)
clear()
editor.restoreSettings()
}

fun addAceJumpListener(listener: AceJumpListener) {
listeners += listener
}

fun removeAceJumpListener(listener: AceJumpListener) {
listeners -= listener
}

private fun Editor.restoreSettings() = runNow {
enabled = false
swapActionHandler()
Expand Down Expand Up @@ -163,4 +176,8 @@ object Handler : TypedActionHandler, Resettable {
.apply { backgroundColor = Model.naturalHighlight })
}
}

interface AceJumpListener {
fun finished() {}
}
}

0 comments on commit 622ba42

Please sign in to comment.