scoop:scoop.window:0.1.0
src/text/menu_commands.scoop
Selected production source · src/text/menu_commands.scoop
1
package scoop.window3
/** Availability of standard menu edits, independent of an IME connection. */4
public 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 = false12
)14
public var Window.textCommandAvailability: TextCommandAvailability?15
get() {16
owner.requireOpen()17
return owner.textCommands18
}19
set(value) {20
owner.requireOpen()21
if (owner.textCommands == value) return22
val flags = when (value) {23
case None -> 024
case Some(val commands) -> 128 + commands.menuFlags25
}26
@Unsafe27
{28
nativeTextCommands(owner.pointer!!, flags)29
}30
owner.textCommands = value31
}33
internal 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) * 6437
@Extern(name = "scoop_window_text_commands")38
@Unsafe39
internal fun nativeTextCommands(window: Ptr<Unit>, flags: Int)41
internal fun menuTextCommand(code: Int): TextEditCommand = when (code) {42
4 -> TextEditCommand.Cut43
5 -> TextEditCommand.Copy44
6 -> TextEditCommand.Paste45
7 -> TextEditCommand.SelectAll46
8 -> TextEditCommand.Undo47
9 -> TextEditCommand.Redo48
10 -> TextEditCommand.DeleteSelection49
else -> throw WindowException("native menu editing command", WindowErrorKind.NativeFailure)50
}