scoop:scoop.surface:0.1.0
src/shared/shortcuts/scope.scoop
Selected production source · src/shared/shortcuts/scope.scoop
1
package scoop.surface3
import scoop.window.*5
/** Window-local shortcuts, executed after the current node's ordinary default behavior. */6
public class ShortcutScope public constructor(7
public val input: InputScope,8
bindings: Array<ShortcutBinding> = []9
): Closeable {10
private var entries = checkedBindings(bindings)11
private var accepts = true12
private var closed = false13
private val registration = input.addShortcutAction { context, event -> handle(context, event) }15
public val isClosed: Boolean get() {16
input.owner.checkThread()17
return closed || input.isClosed18
}19
public var enabled: Boolean20
get() {21
input.owner.checkThread()22
return accepts23
}24
set(value) {25
checkOpen()26
accepts = value27
}28
public var bindings: Array<ShortcutBinding>29
get() {30
input.owner.checkThread()31
return entries32
}33
set(value) {34
checkOpen()35
entries = checkedBindings(value)36
}37
private fun checkOpen() {38
input.checkOpen()39
if (closed)40
throw IllegalStateException(Some("shortcut scope is closed"))41
}42
private fun handle(context: RoutedEventContext, event: InputEvent) {43
runShortcutBindings(context, event, entries) {44
!closed && accepts && !input.isClosed && input.owner.path(input).size > 0L45
}46
}47
public override fun close() {48
input.owner.checkThread()49
if (closed)50
return51
closed = true52
entries = []53
registration.close()54
}55
}