Scoop API

scoop:scoop.surface:0.1.0

src/shared/shortcuts/host.scoop

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

1package scoop.surface
3/** Shared fallback after an attached window's ordinary and local shortcut defaults. */
4public class HostShortcutScope public constructor(
5 public val host: SurfaceHost,
6 bindings: Array<ShortcutBinding> = []
7): Closeable {
8 private var entries = checkedBindings(bindings)
9 private var accepts = true
10 private var closed = false
11 private val registration = host.registerShortcuts { context, event -> handle(context, event) }
13 public val isClosed: Boolean get() {
14 host.checkThread()
15 return closed || !registration.active
16 }
17 public var enabled: Boolean
18 get() {
19 host.checkThread();
20 return accepts
21 }
22 set(value) {
23 checkOpen();
24 accepts = value
25 }
27 public var bindings: Array<ShortcutBinding>
28 get() {
29 host.checkThread();
30 return entries
31 }
32 set(value) {
33 checkOpen();
34 entries = checkedBindings(value)
35 }
37 private fun checkOpen() {
38 host.checkThread()
39 if (closed || !registration.active)
40 throw IllegalStateException(Some("host shortcut scope is closed"))
41 }
42 private fun handle(context: RoutedEventContext, event: InputEvent) {
43 runShortcutBindings(context, event, entries) {
44 !closed && accepts && registration.accepts(context.currentTarget)
45 }
46 }
47 public override fun close() {
48 host.checkThread()
49 if (closed)
50 return
51 closed = true
52 entries = []
53 registration.close()
54 }