Move Kotlin update channel setting to settings dialog (KT-23980)
#KT-23980 Fixed
This commit is contained in:
@@ -447,6 +447,9 @@
|
||||
displayName="Kotlin Compiler"
|
||||
parentId="project.propCompiler"/>
|
||||
|
||||
<applicationConfigurable groupId="language" displayName="Kotlin Updates" id="preferences.language.Kotlin"
|
||||
instance="org.jetbrains.kotlin.idea.configuration.KotlinUpdatesSettingsConfigurable"/>
|
||||
|
||||
<qualifiedNameProvider implementation="org.jetbrains.kotlin.idea.actions.KotlinQualifiedNameProvider"/>
|
||||
|
||||
<codeInsight.parameterInfo language="kotlin" implementationClass="org.jetbrains.kotlin.idea.parameterInfo.KotlinFunctionParameterInfoHandler"/>
|
||||
|
||||
@@ -447,6 +447,9 @@
|
||||
displayName="Kotlin Compiler"
|
||||
parentId="project.propCompiler"/>
|
||||
|
||||
<applicationConfigurable groupId="language" displayName="Kotlin Updates" id="preferences.language.Kotlin"
|
||||
instance="org.jetbrains.kotlin.idea.configuration.KotlinUpdatesSettingsConfigurable"/>
|
||||
|
||||
<qualifiedNameProvider implementation="org.jetbrains.kotlin.idea.actions.KotlinQualifiedNameProvider"/>
|
||||
|
||||
<codeInsight.parameterInfo language="kotlin" implementationClass="org.jetbrains.kotlin.idea.parameterInfo.KotlinFunctionParameterInfoHandler"/>
|
||||
|
||||
@@ -447,6 +447,9 @@
|
||||
displayName="Kotlin Compiler"
|
||||
parentId="project.propCompiler"/>
|
||||
|
||||
<applicationConfigurable groupId="language" displayName="Kotlin Updates" id="preferences.language.Kotlin"
|
||||
instance="org.jetbrains.kotlin.idea.configuration.KotlinUpdatesSettingsConfigurable"/>
|
||||
|
||||
<qualifiedNameProvider implementation="org.jetbrains.kotlin.idea.actions.KotlinQualifiedNameProvider"/>
|
||||
|
||||
<codeInsight.parameterInfo language="kotlin" implementationClass="org.jetbrains.kotlin.idea.parameterInfo.KotlinFunctionParameterInfoHandler"/>
|
||||
|
||||
@@ -448,6 +448,9 @@
|
||||
displayName="Kotlin Compiler"
|
||||
parentId="project.propCompiler"/>
|
||||
|
||||
<applicationConfigurable groupId="language" displayName="Kotlin Updates" id="preferences.language.Kotlin"
|
||||
instance="org.jetbrains.kotlin.idea.configuration.KotlinUpdatesSettingsConfigurable"/>
|
||||
|
||||
<qualifiedNameProvider implementation="org.jetbrains.kotlin.idea.actions.KotlinQualifiedNameProvider"/>
|
||||
|
||||
<codeInsight.parameterInfo language="kotlin" implementationClass="org.jetbrains.kotlin.idea.parameterInfo.KotlinFunctionParameterInfoHandler"/>
|
||||
|
||||
@@ -447,6 +447,9 @@
|
||||
displayName="Kotlin Compiler"
|
||||
parentId="project.propCompiler"/>
|
||||
|
||||
<applicationConfigurable groupId="language" displayName="Kotlin Updates" id="preferences.language.Kotlin"
|
||||
instance="org.jetbrains.kotlin.idea.configuration.KotlinUpdatesSettingsConfigurable"/>
|
||||
|
||||
<qualifiedNameProvider implementation="org.jetbrains.kotlin.idea.actions.KotlinQualifiedNameProvider"/>
|
||||
|
||||
<codeInsight.parameterInfo language="kotlin" implementationClass="org.jetbrains.kotlin.idea.parameterInfo.KotlinFunctionParameterInfoHandler"/>
|
||||
|
||||
@@ -447,6 +447,9 @@
|
||||
displayName="Kotlin Compiler"
|
||||
parentId="project.propCompiler"/>
|
||||
|
||||
<applicationConfigurable groupId="language" displayName="Kotlin Updates" id="preferences.language.Kotlin"
|
||||
instance="org.jetbrains.kotlin.idea.configuration.KotlinUpdatesSettingsConfigurable"/>
|
||||
|
||||
<qualifiedNameProvider implementation="org.jetbrains.kotlin.idea.actions.KotlinQualifiedNameProvider"/>
|
||||
|
||||
<codeInsight.parameterInfo language="kotlin" implementationClass="org.jetbrains.kotlin.idea.parameterInfo.KotlinFunctionParameterInfoHandler"/>
|
||||
|
||||
@@ -16,115 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.actions
|
||||
|
||||
import com.intellij.ide.actions.ShowSettingsUtilImpl
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.DialogWrapper
|
||||
import com.intellij.openapi.updateSettings.impl.UpdateSettings
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUpdater
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||
import org.jetbrains.kotlin.idea.PluginUpdateStatus
|
||||
import org.jetbrains.kotlin.idea.actions.ConfigurePluginUpdatesDialog.EAPChannels.EAP_1_2
|
||||
import org.jetbrains.kotlin.idea.actions.ConfigurePluginUpdatesDialog.EAPChannels.EAP_1_3
|
||||
import javax.swing.JComponent
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinUpdatesSettingsConfigurable
|
||||
|
||||
class ConfigurePluginUpdatesAction : DumbAwareAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
ConfigurePluginUpdatesDialog(e.project).show()
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigurePluginUpdatesDialog(project: Project?) : DialogWrapper(project, false) {
|
||||
private val form = ConfigurePluginUpdatesForm()
|
||||
private val initialSelectedChannel: Int
|
||||
private var update: PluginUpdateStatus.Update? = null
|
||||
|
||||
init {
|
||||
title = "Configure Kotlin Plugin Updates"
|
||||
form.updateCheckProgressIcon.suspend()
|
||||
form.updateCheckProgressIcon.setPaintPassiveIcon(false)
|
||||
|
||||
form.checkForUpdatesNowButton.addActionListener {
|
||||
saveSettings()
|
||||
form.updateCheckProgressIcon.resume()
|
||||
resetUpdateStatus()
|
||||
KotlinPluginUpdater.getInstance().runUpdateCheck{ pluginUpdateStatus ->
|
||||
form.updateCheckProgressIcon.suspend()
|
||||
when (pluginUpdateStatus) {
|
||||
PluginUpdateStatus.LatestVersionInstalled ->
|
||||
form.updateStatusLabel.text = "You have the latest version of the plugin (${KotlinPluginUtil.getPluginVersion()}) installed."
|
||||
|
||||
is PluginUpdateStatus.Update -> {
|
||||
update = pluginUpdateStatus
|
||||
form.installButton.isVisible = true
|
||||
form.updateStatusLabel.text = "A new version ${pluginUpdateStatus.pluginDescriptor.version} is available"
|
||||
}
|
||||
|
||||
is PluginUpdateStatus.CheckFailed ->
|
||||
form.updateStatusLabel.text = "Update check failed: ${pluginUpdateStatus.message}"
|
||||
}
|
||||
|
||||
false // do not auto-retry update check
|
||||
}
|
||||
}
|
||||
|
||||
form.installButton.isVisible = false
|
||||
form.installButton.addActionListener {
|
||||
update?.let {
|
||||
close(OK_EXIT_CODE)
|
||||
KotlinPluginUpdater.getInstance().installPluginUpdate(it)
|
||||
}
|
||||
}
|
||||
|
||||
form.channelCombo.addActionListener {
|
||||
resetUpdateStatus()
|
||||
}
|
||||
|
||||
fun EAPChannels.indexIfAvailable() = if (hasChannel) uiIndex else null
|
||||
initialSelectedChannel = EAP_1_3.indexIfAvailable() ?:
|
||||
EAP_1_2.indexIfAvailable() ?: 0
|
||||
|
||||
form.channelCombo.selectedIndex = initialSelectedChannel
|
||||
init()
|
||||
}
|
||||
|
||||
private fun resetUpdateStatus() {
|
||||
form.updateStatusLabel.text = " "
|
||||
form.installButton.isVisible = false
|
||||
}
|
||||
|
||||
override fun createCenterPanel(): JComponent = form.mainPanel
|
||||
|
||||
private fun saveSettings() {
|
||||
saveSelectedChannel(form.channelCombo.selectedIndex)
|
||||
}
|
||||
|
||||
private fun saveSelectedChannel(channel: Int) {
|
||||
val hosts = UpdateSettings.getInstance().storedPluginHosts
|
||||
hosts.removeIf {
|
||||
it.startsWith("https://plugins.jetbrains.com/plugins/") &&
|
||||
(it.endsWith("/6954") || it.endsWith(KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString))
|
||||
}
|
||||
when (channel) {
|
||||
EAP_1_3.uiIndex -> hosts.add(EAP_1_3.url)
|
||||
EAP_1_2.uiIndex -> hosts.add(EAP_1_2.url)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOKAction() {
|
||||
saveSettings()
|
||||
super.doOKAction()
|
||||
}
|
||||
|
||||
override fun doCancelAction() {
|
||||
saveSelectedChannel(initialSelectedChannel)
|
||||
super.doCancelAction()
|
||||
}
|
||||
|
||||
enum class EAPChannels(val url: String, val uiIndex: Int) {
|
||||
EAP_1_2("https://plugins.jetbrains.com/plugins/eap-1.2/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 1),
|
||||
EAP_1_3("https://plugins.jetbrains.com/plugins/eap-next/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 2);
|
||||
|
||||
val hasChannel: Boolean get() = url in UpdateSettings.getInstance().pluginHosts
|
||||
val project = e.getData(CommonDataKeys.PROJECT)
|
||||
ShowSettingsUtilImpl.showSettingsDialog(project, KotlinUpdatesSettingsConfigurable.ID, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.actions;
|
||||
|
||||
import com.intellij.util.ui.AsyncProcessIcon;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ConfigurePluginUpdatesForm {
|
||||
public JComboBox channelCombo;
|
||||
public JButton checkForUpdatesNowButton;
|
||||
public JPanel mainPanel;
|
||||
public AsyncProcessIcon updateCheckProgressIcon;
|
||||
public JLabel updateStatusLabel;
|
||||
public JButton installButton;
|
||||
|
||||
private void createUIComponents() {
|
||||
updateCheckProgressIcon = new AsyncProcessIcon("Plugin update check progress");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.openapi.options.Configurable
|
||||
import com.intellij.openapi.options.SearchableConfigurable
|
||||
import com.intellij.openapi.updateSettings.impl.UpdateSettings
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUpdater
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||
import org.jetbrains.kotlin.idea.PluginUpdateStatus
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.ConfigurePluginUpdatesForm
|
||||
import javax.swing.JComponent
|
||||
|
||||
class KotlinUpdatesSettingsConfigurable() : SearchableConfigurable, Configurable.NoScroll {
|
||||
companion object {
|
||||
const val ID = "preferences.language.Kotlin"
|
||||
|
||||
private fun saveSelectedChannel(channel: Int) {
|
||||
val hosts = UpdateSettings.getInstance().storedPluginHosts
|
||||
hosts.removeIf {
|
||||
it.startsWith("https://plugins.jetbrains.com/plugins/") &&
|
||||
(it.endsWith("/6954") || it.endsWith(KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString))
|
||||
}
|
||||
when (channel) {
|
||||
EAPChannels.EAP_1_3.uiIndex -> hosts.add(EAPChannels.EAP_1_3.url)
|
||||
EAPChannels.EAP_1_2.uiIndex -> hosts.add(EAPChannels.EAP_1_2.url)
|
||||
}
|
||||
}
|
||||
|
||||
enum class EAPChannels(val url: String, val uiIndex: Int) {
|
||||
EAP_1_2("https://plugins.jetbrains.com/plugins/eap-1.2/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 1),
|
||||
EAP_1_3("https://plugins.jetbrains.com/plugins/eap-next/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 2);
|
||||
|
||||
private val hasChannel: Boolean get() = url in UpdateSettings.getInstance().pluginHosts
|
||||
|
||||
fun indexIfAvailable() = if (hasChannel) uiIndex else null
|
||||
}
|
||||
}
|
||||
|
||||
private val form = ConfigurePluginUpdatesForm()
|
||||
private var update: PluginUpdateStatus.Update? = null
|
||||
|
||||
private var savedChannel: Int = EAPChannels.EAP_1_3.indexIfAvailable() ?: EAPChannels.EAP_1_2.indexIfAvailable() ?: 0
|
||||
|
||||
override fun getId(): String = ID
|
||||
|
||||
override fun getDisplayName(): String = "Kotlin Updates"
|
||||
|
||||
override fun isModified(): Boolean {
|
||||
return savedChannel != form.channelCombo.selectedIndex
|
||||
}
|
||||
|
||||
override fun apply() {
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
override fun createComponent(): JComponent? {
|
||||
form.updateCheckProgressIcon.suspend()
|
||||
form.updateCheckProgressIcon.setPaintPassiveIcon(false)
|
||||
|
||||
form.checkForUpdatesNowButton.addActionListener {
|
||||
saveSettings()
|
||||
form.updateCheckProgressIcon.resume()
|
||||
form.resetUpdateStatus()
|
||||
KotlinPluginUpdater.getInstance().runUpdateCheck{ pluginUpdateStatus ->
|
||||
form.updateCheckProgressIcon.suspend()
|
||||
when (pluginUpdateStatus) {
|
||||
PluginUpdateStatus.LatestVersionInstalled ->
|
||||
form.updateStatusLabel.text = "You have the latest version of the plugin (${KotlinPluginUtil.getPluginVersion()}) installed."
|
||||
|
||||
is PluginUpdateStatus.Update -> {
|
||||
update = pluginUpdateStatus
|
||||
form.installButton.isVisible = true
|
||||
form.updateStatusLabel.text = "A new version ${pluginUpdateStatus.pluginDescriptor.version} is available"
|
||||
}
|
||||
|
||||
is PluginUpdateStatus.CheckFailed ->
|
||||
form.updateStatusLabel.text = "Update check failed: ${pluginUpdateStatus.message}"
|
||||
}
|
||||
|
||||
false // do not auto-retry update check
|
||||
}
|
||||
}
|
||||
|
||||
form.installButton.isVisible = false
|
||||
form.installButton.addActionListener {
|
||||
update?.let {
|
||||
KotlinPluginUpdater.getInstance().installPluginUpdate(it)
|
||||
}
|
||||
}
|
||||
|
||||
form.channelCombo.addActionListener {
|
||||
form.resetUpdateStatus()
|
||||
}
|
||||
|
||||
form.channelCombo.selectedIndex = savedChannel
|
||||
|
||||
return form.mainPanel
|
||||
}
|
||||
|
||||
private fun saveSettings() {
|
||||
savedChannel = form.channelCombo.selectedIndex
|
||||
saveSelectedChannel(savedChannel)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.idea.actions.ConfigurePluginUpdatesForm">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.idea.configuration.ui.ConfigurePluginUpdatesForm">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration.ui;
|
||||
|
||||
import com.intellij.util.ui.AsyncProcessIcon;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ConfigurePluginUpdatesForm {
|
||||
public JComboBox channelCombo;
|
||||
public JButton checkForUpdatesNowButton;
|
||||
public JPanel mainPanel;
|
||||
public AsyncProcessIcon updateCheckProgressIcon;
|
||||
public JLabel updateStatusLabel;
|
||||
public JButton installButton;
|
||||
|
||||
private void createUIComponents() {
|
||||
updateCheckProgressIcon = new AsyncProcessIcon("Plugin update check progress");
|
||||
}
|
||||
|
||||
public void resetUpdateStatus() {
|
||||
updateStatusLabel.setText(" ");
|
||||
installButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user