Scoop API

scoop:scoop.window:0.1.0

src/drag_drop/values.scoop

Selected production source · src/drag_drop/values.scoop

1package scoop.window
3import scoop.platform.fs.Path
5/** The native destination result. A Move still requires the source's own commit. */
6public enum DragResult {
7 Dropped(DragEffect), NotDropped, Failed(WindowException)
8}
10public enum DragFormat {
11 Text, Url, Files
14public enum DragEffect {
15 Copy, Move, Link
18public struct DragFormats(val text: Boolean, val url: Boolean, val files: Boolean) {
19 public fun contains(format: DragFormat): Boolean =
20 when (format) {
21 case Text -> text
22 case Url -> url
23 case Files -> files
24 }
27public struct DragEffects(val copy: Boolean, val move: Boolean, val link: Boolean) {
28 public fun allows(effect: DragEffect): Boolean =
29 when (effect) {
30 case Copy -> copy
31 case Move -> move
32 case Link -> link
33 }
36/** Metadata only; payloads are copied after an actual drop. */
37public struct DropOffer(
38 val formats: DragFormats,
39 val effects: DragEffects,
40 val position: LogicalPosition,
41 val modifiers: Modifiers,
42 val local: Boolean,
43 /** The source's in-process value, present only for the matching live native session. */
44 val localData: Any? = None
47public enum DropDecision {
48 Reject, Accept(DragFormat, DragEffect)
51/** Owned data. File paths do not imply that their contents have been read. */
52public enum DragContent {
53 Text(String), Url(String), Files(Array<Path>)
56public struct DropRequest(val offer: DropOffer, val effect: DragEffect, val content: DragContent)
58public struct DropHandlers(
59 val offer: (DropOffer) -> DropDecision,
60 val drop: (DropRequest) -> Boolean,
61 val leave: () -> Unit = {}
64internal fun dragFormatCode(format: DragFormat): Int =
65 when (format) {
66 case Text -> 1
67 case Url -> 2
68 case Files -> 3
69 }
71internal fun dragEffectCode(effect: DragEffect): Int =
72 when (effect) {
73 case Copy -> 1
74 case Move -> 2
75 case Link -> 4
76 }
78internal fun dropDecisionCode(offer: DropOffer, decision: DropDecision): Int =
79 when (decision) {
80 case Reject -> 0
81 case Accept(val format, val effect) ->
82 if (offer.formats.contains(format) && offer.effects.allows(effect))
83 256 * dragFormatCode(format) + dragEffectCode(effect)
84 else
85 0
86 }
88internal fun checkDragContent(content: DragContent, effects: DragEffects) {
89 requireWindow(effects.copy || effects.move || effects.link, "drag effects must not be empty")
90 when (content) {
91 case Files(val paths) -> {
92 requireWindow(paths.size > 0L, "drag file list must not be empty")
93 for (path in paths)
94 requireWindow(path.isAbsolute, "drag file paths must be absolute")
95 }
96 else -> {}
97 }