diff --git a/src/main/kotlin/dev/dediamondpro/resourcify/elements/DropDown.kt b/src/main/kotlin/dev/dediamondpro/resourcify/elements/DropDown.kt index ce457ef..d2c3c22 100644 --- a/src/main/kotlin/dev/dediamondpro/resourcify/elements/DropDown.kt +++ b/src/main/kotlin/dev/dediamondpro/resourcify/elements/DropDown.kt @@ -1,6 +1,6 @@ /* * This file is part of Resourcify - * Copyright (C) 2023 DeDiamondPro + * Copyright (C) 2023-2024 DeDiamondPro * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -35,7 +35,7 @@ class DropDown( private val placeHolder: String = "", private val canDeSelect: Boolean = !onlyOneOption ) : UIContainer() { - private val selectionUpdateListeners = mutableListOf<(List) -> Unit>() + private val selectionUpdateListeners = mutableListOf) -> Unit>() private var canOpen = false private val box = UIBlock(color = Color(0, 0, 0, 200)).constrain { @@ -126,11 +126,11 @@ class DropDown( } } - private fun updateText() { + fun updateText() { text.setText(selectedOptions.joinToString().ifBlank { placeHolder }) } - fun onSelectionUpdate(listener: (List) -> Unit): DropDown { + fun onSelectionUpdate(listener: DropDown.(List) -> Unit): DropDown { selectionUpdateListeners.add(listener) return this } diff --git a/src/main/kotlin/dev/dediamondpro/resourcify/gui/update/components/UpdateCard.kt b/src/main/kotlin/dev/dediamondpro/resourcify/gui/update/components/UpdateCard.kt index 43c3c01..c5f1efe 100644 --- a/src/main/kotlin/dev/dediamondpro/resourcify/gui/update/components/UpdateCard.kt +++ b/src/main/kotlin/dev/dediamondpro/resourcify/gui/update/components/UpdateCard.kt @@ -148,6 +148,15 @@ class UpdateCard( data.keys.map { it.getName() }, onlyOneOption = true, selectedOptions = mutableListOf(selectedService.getName()) ).onSelectionUpdate { newService -> + val downloadUrl = selectedData?.version?.getDownloadUrl() + if (downloadUrl != null && DownloadManager.getProgress(downloadUrl) != null) { + // We are currently downloading an update, don't allow changes + this.selectedOptions.clear() + this.selectedOptions.add(selectedService.getName()) + this.updateText() + return@onSelectionUpdate + } + selectedService = data.keys.firstOrNull { it.getName() == newService.first() } ?: return@onSelectionUpdate selectedData = data[selectedService]