scoop:scoop.window:0.1.0
src/drag_drop/values.scoop
Selected production source · src/drag_drop/values.scoop
1
package scoop.window3
import scoop.platform.fs.Path5
/** The native destination result. A Move still requires the source's own commit. */6
public enum DragResult {7
Dropped(DragEffect), NotDropped, Failed(WindowException)8
}10
public enum DragFormat {11
Text, Url, Files12
}14
public enum DragEffect {15
Copy, Move, Link16
}18
public struct DragFormats(val text: Boolean, val url: Boolean, val files: Boolean) {19
public fun contains(format: DragFormat): Boolean =20
when (format) {21
case Text -> text22
case Url -> url23
case Files -> files24
}25
}27
public struct DragEffects(val copy: Boolean, val move: Boolean, val link: Boolean) {28
public fun allows(effect: DragEffect): Boolean =29
when (effect) {30
case Copy -> copy31
case Move -> move32
case Link -> link33
}34
}36
/** Metadata only; payloads are copied after an actual drop. */37
public 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? = None45
)47
public enum DropDecision {48
Reject, Accept(DragFormat, DragEffect)49
}51
/** Owned data. File paths do not imply that their contents have been read. */52
public enum DragContent {53
Text(String), Url(String), Files(Array<Path>)54
}56
public struct DropRequest(val offer: DropOffer, val effect: DragEffect, val content: DragContent)58
public struct DropHandlers(59
val offer: (DropOffer) -> DropDecision,60
val drop: (DropRequest) -> Boolean,61
val leave: () -> Unit = {}62
)64
internal fun dragFormatCode(format: DragFormat): Int =65
when (format) {66
case Text -> 167
case Url -> 268
case Files -> 369
}71
internal fun dragEffectCode(effect: DragEffect): Int =72
when (effect) {73
case Copy -> 174
case Move -> 275
case Link -> 476
}78
internal fun dropDecisionCode(offer: DropOffer, decision: DropDecision): Int =79
when (decision) {80
case Reject -> 081
case Accept(val format, val effect) ->82
if (offer.formats.contains(format) && offer.effects.allows(effect))83
256 * dragFormatCode(format) + dragEffectCode(effect)84
else85
086
}88
internal 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
}98
}