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 {
|
companion object {
|
||||||
const val ID = "preferences.language.Kotlin"
|
const val ID = "preferences.language.Kotlin"
|
||||||
|
|
||||||
private fun saveSelectedChannel(channel: Int) {
|
private fun saveSelectedChannel(channelOrdinal: Int) {
|
||||||
val hosts = UpdateSettings.getInstance().storedPluginHosts
|
val hosts = UpdateSettings.getInstance().storedPluginHosts
|
||||||
hosts.removeIf {
|
hosts.removeIf {
|
||||||
it.startsWith("https://plugins.jetbrains.com/plugins/") &&
|
it.startsWith("https://plugins.jetbrains.com/plugins/") &&
|
||||||
(it.endsWith("/6954") || it.endsWith(KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString))
|
(it.endsWith("/6954") || it.endsWith(KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString))
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPChannels.values().find { it.uiIndex == channel }?.let { eapChannel ->
|
UpdateChannel.values().find { it.ordinal == channelOrdinal }?.let { eapChannel ->
|
||||||
hosts.add(eapChannel.url)
|
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) {
|
enum class UpdateChannel(val url: String?, val title: String) {
|
||||||
EAP("https://plugins.jetbrains.com/plugins/eap/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 1),
|
STABLE(null, "Stable"),
|
||||||
EAP_NEXT("https://plugins.jetbrains.com/plugins/eap-next/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 2);
|
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.selectedIndex = savedChannel
|
||||||
|
|
||||||
form.channelCombo.addActionListener {
|
form.channelCombo.addActionListener {
|
||||||
|
|||||||
@@ -80,13 +80,7 @@
|
|||||||
<children>
|
<children>
|
||||||
<component id="ca1a9" class="javax.swing.JComboBox" binding="channelCombo">
|
<component id="ca1a9" class="javax.swing.JComboBox" binding="channelCombo">
|
||||||
<constraints/>
|
<constraints/>
|
||||||
<properties>
|
<properties/>
|
||||||
<model>
|
|
||||||
<item value="Stable"/>
|
|
||||||
<item value="Early Access Preview 1.3.x"/>
|
|
||||||
<item value="Early Access Preview 1.4.x"/>
|
|
||||||
</model>
|
|
||||||
</properties>
|
|
||||||
</component>
|
</component>
|
||||||
<component id="c7546" class="javax.swing.JButton" binding="reCheckButton">
|
<component id="c7546" class="javax.swing.JButton" binding="reCheckButton">
|
||||||
<constraints/>
|
<constraints/>
|
||||||
|
|||||||
+11
-2
@@ -10,6 +10,7 @@ import com.intellij.util.ui.AsyncProcessIcon;
|
|||||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil;
|
import org.jetbrains.kotlin.idea.KotlinPluginUtil;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigurePluginUpdatesForm {
|
public class ConfigurePluginUpdatesForm {
|
||||||
public JComboBox<String> channelCombo;
|
public JComboBox<String> channelCombo;
|
||||||
@@ -23,6 +24,16 @@ public class ConfigurePluginUpdatesForm {
|
|||||||
private JTextPane currentVersion;
|
private JTextPane currentVersion;
|
||||||
|
|
||||||
public ConfigurePluginUpdatesForm() {
|
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();
|
int size = channelCombo.getModel().getSize();
|
||||||
String maxLengthItem = "";
|
String maxLengthItem = "";
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
@@ -32,8 +43,6 @@ public class ConfigurePluginUpdatesForm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
channelCombo.setPrototypeDisplayValue(maxLengthItem + " ");
|
channelCombo.setPrototypeDisplayValue(maxLengthItem + " ");
|
||||||
showVerifierDisabledStatus();
|
|
||||||
currentVersion.setText(KotlinPluginUtil.getPluginVersion());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createUIComponents() {
|
private void createUIComponents() {
|
||||||
|
|||||||
Reference in New Issue
Block a user