Refactoring: move channels titles and urls to single place
This commit is contained in:
@@ -19,23 +19,32 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
|
||||
companion object {
|
||||
const val ID = "preferences.language.Kotlin"
|
||||
|
||||
private fun saveSelectedChannel(channel: Int) {
|
||||
private fun saveSelectedChannel(channelOrdinal: 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))
|
||||
}
|
||||
|
||||
EAPChannels.values().find { it.uiIndex == channel }?.let { eapChannel ->
|
||||
hosts.add(eapChannel.url)
|
||||
UpdateChannel.values().find { it.ordinal == channelOrdinal }?.let { eapChannel ->
|
||||
if (eapChannel != UpdateChannel.STABLE) {
|
||||
hosts.add(eapChannel.url ?: error("Shouldn't add null urls to custom repositories"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class EAPChannels(val url: String, val uiIndex: Int) {
|
||||
EAP("https://plugins.jetbrains.com/plugins/eap/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 1),
|
||||
EAP_NEXT("https://plugins.jetbrains.com/plugins/eap-next/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 2);
|
||||
enum class UpdateChannel(val url: String?, val title: String) {
|
||||
STABLE(null, "Stable"),
|
||||
EAP("https://plugins.jetbrains.com/plugins/eap/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", "Early Access Preview 1.3.x"),
|
||||
EAP_NEXT(
|
||||
"https://plugins.jetbrains.com/plugins/eap-next/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}",
|
||||
"Early Access Preview 1.4.x"
|
||||
);
|
||||
|
||||
fun isInHosts() = url in UpdateSettings.getInstance().pluginHosts
|
||||
fun isInHosts(): Boolean {
|
||||
if (this == STABLE) return false
|
||||
return url in UpdateSettings.getInstance().pluginHosts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +117,9 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
|
||||
}
|
||||
}
|
||||
|
||||
savedChannel = EAPChannels.values().find { it.isInHosts() }?.uiIndex ?: 0
|
||||
form.initChannels(UpdateChannel.values().map { it.title })
|
||||
|
||||
savedChannel = UpdateChannel.values().find { it.isInHosts() }?.ordinal ?: 0
|
||||
form.channelCombo.selectedIndex = savedChannel
|
||||
|
||||
form.channelCombo.addActionListener {
|
||||
|
||||
@@ -80,13 +80,7 @@
|
||||
<children>
|
||||
<component id="ca1a9" class="javax.swing.JComboBox" binding="channelCombo">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Stable"/>
|
||||
<item value="Early Access Preview 1.3.x"/>
|
||||
<item value="Early Access Preview 1.4.x"/>
|
||||
</model>
|
||||
</properties>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c7546" class="javax.swing.JButton" binding="reCheckButton">
|
||||
<constraints/>
|
||||
|
||||
+11
-2
@@ -10,6 +10,7 @@ import com.intellij.util.ui.AsyncProcessIcon;
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigurePluginUpdatesForm {
|
||||
public JComboBox<String> channelCombo;
|
||||
@@ -23,6 +24,16 @@ public class ConfigurePluginUpdatesForm {
|
||||
private JTextPane currentVersion;
|
||||
|
||||
public ConfigurePluginUpdatesForm() {
|
||||
showVerifierDisabledStatus();
|
||||
currentVersion.setText(KotlinPluginUtil.getPluginVersion());
|
||||
}
|
||||
|
||||
public void initChannels(List<String> channels) {
|
||||
channelCombo.removeAllItems();
|
||||
for (String channel : channels) {
|
||||
channelCombo.addItem(channel);
|
||||
}
|
||||
|
||||
int size = channelCombo.getModel().getSize();
|
||||
String maxLengthItem = "";
|
||||
for (int i = 0; i < size; i++) {
|
||||
@@ -32,8 +43,6 @@ public class ConfigurePluginUpdatesForm {
|
||||
}
|
||||
}
|
||||
channelCombo.setPrototypeDisplayValue(maxLengthItem + " ");
|
||||
showVerifierDisabledStatus();
|
||||
currentVersion.setText(KotlinPluginUtil.getPluginVersion());
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
|
||||
Reference in New Issue
Block a user