Scoop API

scoop:scoop.surface:0.1.0

src/shared/shortcuts/scope.scoop

Selected production source · src/shared/shortcuts/scope.scoop

1package scoop.surface
3import scoop.window.*
5/** Window-local shortcuts, executed after the current node's ordinary default behavior. */
6public 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 = true
12 private var closed = false
13 private val registration = input.addShortcutAction { context, event -> handle(context, event) }
15 public val isClosed: Boolean get() {
16 input.owner.checkThread()
17 return closed || input.isClosed
18 }
19 public var enabled: Boolean
20 get() {
21 input.owner.checkThread()
22 return accepts
23 }
24 set(value) {
25 checkOpen()
26 accepts = value
27 }
28 public var bindings: Array<ShortcutBinding>
29 get() {
30 input.owner.checkThread()
31 return entries
32 }
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 > 0L
45 }
46 }
47 public override fun close() {
48 input.owner.checkThread()
49 if (closed)
50 return
51 closed = true
52 entries = []
53 registration.close()
54 }