User: mysterious_dev Date: 25 Apr 23 12:58 Revision: 9e90b5bce56799392f789436851d22a4a1031f69 Summary: Migrate Plugin Update Dialog to UI DSL 2 (#2001) * Begin Work * WIP * WIP * Delete old form * Finish * Format TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=8442&personal=false Index: src/main/kotlin/update/ConfigurePluginUpdatesDialog.kt =================================================================== --- src/main/kotlin/update/ConfigurePluginUpdatesDialog.kt (revision 65419dc7b4297d343b00b580e3412a6309584955) +++ src/main/kotlin/update/ConfigurePluginUpdatesDialog.kt (revision 9e90b5bce56799392f789436851d22a4a1031f69) @@ -12,61 +12,76 @@ import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.updateSettings.impl.UpdateSettings +import com.intellij.ui.AnimatedIcon +import com.intellij.ui.dsl.builder.Cell +import com.intellij.ui.dsl.builder.panel import java.io.IOException +import javax.swing.JButton +import javax.swing.JComboBox +import javax.swing.JLabel class ConfigurePluginUpdatesDialog : DialogWrapper(true) { - private val form = ConfigurePluginUpdatesForm() - private var update: PluginUpdateStatus.Update? = null - private var initialSelectedChannel: Int = 0 + private lateinit var channelBox: Cell> + private lateinit var installButton: Cell + private lateinit var updateStatusLabel: Cell + private lateinit var updateCheckInProgressIcon: Cell - init { - title = "Configure Minecraft Development Plugin Updates" - form.updateCheckInProgressIcon.suspend() - form.updateCheckInProgressIcon.setPaintPassiveIcon(false) - - form.channelBox.addItem("Stable") - for (channels in Channels.values()) { - form.channelBox.addItem(channels.title) + private val form = panel { + row { + label("Update channel:") + channelBox = comboBox(listOf("Stable")) } - - form.checkForUpdatesNowButton.addActionListener { + row { + button("Check for updates now") { - saveSettings() + saveSettings() - form.updateCheckInProgressIcon.resume() + updateCheckInProgressIcon.component.isVisible = true - resetUpdateStatus() - PluginUpdater.runUpdateCheck { pluginUpdateStatus -> + resetUpdateStatus() + PluginUpdater.runUpdateCheck { pluginUpdateStatus -> - form.updateCheckInProgressIcon.suspend() + updateCheckInProgressIcon.component.isVisible = false - form.updateStatusLabel.text = when (pluginUpdateStatus) { + updateStatusLabel.component.text = when (pluginUpdateStatus) { - is PluginUpdateStatus.LatestVersionInstalled -> - "You have the latest version of the plugin (${PluginUtil.pluginVersion}) installed." - is PluginUpdateStatus.Update -> { - update = pluginUpdateStatus + is PluginUpdateStatus.LatestVersionInstalled -> + "You have the latest version of the plugin (${PluginUtil.pluginVersion}) installed." + is PluginUpdateStatus.Update -> { + update = pluginUpdateStatus - form.installButton.isVisible = true + installButton.component.isVisible = true - "A new version (${pluginUpdateStatus.pluginDescriptor.version}) is available" - } - else -> // CheckFailed - "Update check failed: " + (pluginUpdateStatus as PluginUpdateStatus.CheckFailed).message - } + "A new version (${pluginUpdateStatus.pluginDescriptor.version}) is available" + } + else -> // CheckFailed + "Update check failed: " + (pluginUpdateStatus as PluginUpdateStatus.CheckFailed).message + } - false - } - } + false + } + } - - form.installButton.isVisible = false - form.installButton.addActionListener { + updateCheckInProgressIcon = icon(AnimatedIcon.Default.INSTANCE) + installButton = button("Install Update") { - update?.let { update -> - close(OK_EXIT_CODE) - try { - PluginUpdater.installPluginUpdate(update) - } catch (e: IOException) { - e.printStackTrace() - } - } + update?.let { update -> + close(OK_EXIT_CODE) + try { + PluginUpdater.installPluginUpdate(update) + } catch (e: IOException) { + e.printStackTrace() + } + } + }.visible(false) } + row { + updateStatusLabel = label("") + } + } + private var update: PluginUpdateStatus.Update? = null + private var initialSelectedChannel: Int = 0 - form.channelBox.addActionListener { resetUpdateStatus() } + init { + title = "Configure Minecraft Development Plugin Updates" + for (channels in Channels.values()) { + channelBox.component.addItem(channels.title) + } + channelBox.component.selectedIndex = initialSelectedChannel + Channels.values().forEachIndexed { i, channel -> if (channel.hasChannel()) { initialSelectedChannel = i + 1 @@ -74,11 +89,12 @@ } } - form.channelBox.selectedIndex = initialSelectedChannel + channelBox.component.addActionListener { resetUpdateStatus() } + updateCheckInProgressIcon.component.isVisible = false init() } - override fun createCenterPanel() = form.panel + override fun createCenterPanel() = form private fun saveSelectedChannel(index: Int) { val hosts = UpdateSettings.getInstance().storedPluginHosts @@ -93,12 +109,12 @@ } private fun saveSettings() { - saveSelectedChannel(form.channelBox.selectedIndex) + saveSelectedChannel(channelBox.component.selectedIndex) } private fun resetUpdateStatus() { - form.updateStatusLabel.text = " " - form.installButton.isVisible = false + updateStatusLabel.component.text = " " + installButton.component.isVisible = false } override fun doOKAction() { Index: src/main/kotlin/update/ConfigurePluginUpdatesForm.form =================================================================== --- src/main/kotlin/update/ConfigurePluginUpdatesForm.form (revision 65419dc7b4297d343b00b580e3412a6309584955) +++ src/main/kotlin/update/ConfigurePluginUpdatesForm.form (revision 65419dc7b4297d343b00b580e3412a6309584955) @@ -1,83 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Index: src/main/kotlin/update/ConfigurePluginUpdatesForm.kt =================================================================== --- src/main/kotlin/update/ConfigurePluginUpdatesForm.kt (revision 65419dc7b4297d343b00b580e3412a6309584955) +++ src/main/kotlin/update/ConfigurePluginUpdatesForm.kt (revision 65419dc7b4297d343b00b580e3412a6309584955) @@ -1,31 +0,0 @@ -/* - * Minecraft Dev for IntelliJ - * - * https://minecraftdev.org - * - * Copyright (c) 2023 minecraft-dev - * - * MIT License - */ - -package com.demonwav.mcdev.update - -import com.intellij.util.ui.AsyncProcessIcon -import javax.swing.JButton -import javax.swing.JComboBox -import javax.swing.JLabel -import javax.swing.JPanel - -class ConfigurePluginUpdatesForm { - lateinit var channelBox: JComboBox - lateinit var checkForUpdatesNowButton: JButton - lateinit var panel: JPanel - lateinit var updateCheckInProgressIcon: AsyncProcessIcon - - lateinit var updateStatusLabel: JLabel - lateinit var installButton: JButton - - private fun createUIComponents() { - updateCheckInProgressIcon = AsyncProcessIcon("Plugin update check in progress") - } -}