scoop:scoop.ui.component.desktop:0.1.0
src/window.scoop
Selected production source · src/window.scoop
1
package scoop.ui.component.desktop3
import scoop.desktop.*4
import scoop.ui.*5
import scoop.window.*7
public class NativeDesktopWindowBuilder internal constructor() {8
public var icon: DesktopImage? = None9
public var overlayIcon: DesktopImage? = None10
public var overlayDescription: String = ""11
public var progress: DesktopProgress = DesktopProgress.None12
public var miniwindowCaption: String? = None13
public var thumbnailTooltip: String? = None14
}16
internal class NativeDesktopWindowProps(17
val controller: NativeDesktopController,18
val window: Window,19
val icon: DesktopImage?,20
val overlay: DesktopImage?,21
val overlayDescription: String,22
val progress: DesktopProgress,23
val miniwindowCaption: String?,24
val thumbnailTooltip: String?25
)27
public fun nativeDesktopWindow(28
controller: NativeDesktopController,29
window: Window,30
key: ViewKey,31
configure: NativeDesktopWindowBuilder.() -> Unit = {}32
): ApplicationItem {33
val builder = NativeDesktopWindowBuilder()34
builder.configure()35
return applicationElement(36
NativeDesktopWindowProps(37
controller,38
window,39
builder.icon,40
builder.overlayIcon,41
builder.overlayDescription,42
builder.progress,43
builder.miniwindowCaption,44
builder.thumbnailTooltip45
),46
{ props, scope -> NativeDesktopWindowElement(props, scope) },47
key48
)49
}51
internal class NativeDesktopWindowElement(52
private val props: Props<NativeDesktopWindowProps>,53
scope: ApplicationScope54
): ApplicationElement(scope) {55
private var binding: DesktopWindow? = None56
private var previous: NativeDesktopWindowProps? = None57
public override fun update() {58
val next = props.value59
when (previous) {60
case Some(val old) -> if (61
!(old.controller === next.controller) || !(old.window === next.window)62
) {63
binding?.close()64
binding = None65
previous = None66
}67
case None -> {}68
}69
if (70
next.controller.isClosed ||71
next.window.state ==72
WindowState.Closing ||73
next.window.state ==74
WindowState.Destroyed75
)76
return77
val target =78
when (binding) {79
case Some(val value) -> value80
case None -> {81
val value =82
scope.resource { next.controller.application.attachWindow(next.window) }83
binding = Some(value)84
value85
}86
}87
if (target.isClosed)88
return89
target.setIcon(next.icon)90
target.setOverlayIcon(next.overlay, next.overlayDescription)91
when (previous) {92
case Some(val old) -> {93
if (!sameDesktopProgress(old.progress, next.progress))94
target.setProgress(next.progress)95
if (old.miniwindowCaption != next.miniwindowCaption)96
target.setMiniwindowCaption(next.miniwindowCaption)97
if (old.thumbnailTooltip != next.thumbnailTooltip)98
target.setThumbnailTooltip(next.thumbnailTooltip)99
}100
case None -> {101
target.setProgress(next.progress)102
target.setMiniwindowCaption(next.miniwindowCaption)103
target.setThumbnailTooltip(next.thumbnailTooltip)104
}105
}106
previous = Some(next)107
}108
public override fun onUnmount() {109
binding?.close()110
binding = None111
previous = None112
}113
}115
private fun sameDesktopProgress(left: DesktopProgress, right: DesktopProgress): Boolean =116
when ((left, right)) {117
case(None, None) -> true118
case(Indeterminate, Indeterminate) -> true119
case(Normal(val a, val b), Normal(val c, val d)) -> a == c && b == d120
case(Paused(val a, val b), Paused(val c, val d)) -> a == c && b == d121
case(Error(val a, val b), Error(val c, val d)) -> a == c && b == d122
else -> false123
}