Scoop API

scoop:scoop.window:0.1.0

src/text/menu_commands.scoop

Selected production source · src/text/menu_commands.scoop

1package scoop.window
3/** Availability of standard menu edits, independent of an IME connection. */
4public struct TextCommandAvailability(
5 val cut: Boolean = false,
6 val copy: Boolean = false,
7 val paste: Boolean = false,
8 val selectAll: Boolean = false,
9 val undo: Boolean = false,
10 val redo: Boolean = false,
11 val deleteSelection: Boolean = false
14public var Window.textCommandAvailability: TextCommandAvailability?
15 get() {
16 owner.requireOpen()
17 return owner.textCommands
18 }
19 set(value) {
20 owner.requireOpen()
21 if (owner.textCommands == value) return
22 val flags = when (value) {
23 case None -> 0
24 case Some(val commands) -> 128 + commands.menuFlags
25 }
26 @Unsafe
27 {
28 nativeTextCommands(owner.pointer!!, flags)
29 }
30 owner.textCommands = value
31 }
33internal val TextCommandAvailability.menuFlags: Int get() =
34 flag(cut) + flag(copy) * 2 + flag(paste) * 4 + flag(selectAll) * 8 +
35 flag(undo) * 16 + flag(redo) * 32 + flag(deleteSelection) * 64
37@Extern(name = "scoop_window_text_commands")
38@Unsafe
39internal fun nativeTextCommands(window: Ptr<Unit>, flags: Int)
41internal fun menuTextCommand(code: Int): TextEditCommand = when (code) {
42 4 -> TextEditCommand.Cut
43 5 -> TextEditCommand.Copy
44 6 -> TextEditCommand.Paste
45 7 -> TextEditCommand.SelectAll
46 8 -> TextEditCommand.Undo
47 9 -> TextEditCommand.Redo
48 10 -> TextEditCommand.DeleteSelection
49 else -> throw WindowException("native menu editing command", WindowErrorKind.NativeFailure)