Skip to content

Commit

Permalink
Migrate setting and NBT toolbar to Kotlin UI DSL
Browse files Browse the repository at this point in the history
Also remove the old unused facet editor
  • Loading branch information
RedNesto committed Jan 1, 2024
1 parent bd640fe commit 0f6dd78
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 1,117 deletions.
117 changes: 0 additions & 117 deletions src/main/kotlin/MinecraftConfigurable.form

This file was deleted.

120 changes: 60 additions & 60 deletions src/main/kotlin/MinecraftConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,80 +20,80 @@

package com.demonwav.mcdev

import com.demonwav.mcdev.asset.MCDevBundle
import com.demonwav.mcdev.asset.PlatformAssets
import com.demonwav.mcdev.update.ConfigurePluginUpdatesDialog
import com.intellij.ide.projectView.ProjectView
import com.intellij.openapi.options.Configurable
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JComboBox
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.EnumComboBoxModel
import com.intellij.ui.components.Label
import com.intellij.ui.dsl.builder.AlignX
import com.intellij.ui.dsl.builder.BottomGap
import com.intellij.ui.dsl.builder.bindItem
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.panel
import com.intellij.util.IconUtil
import javax.swing.JComponent
import javax.swing.JPanel
import org.jetbrains.annotations.Nls

class MinecraftConfigurable : Configurable {

private lateinit var panel: JPanel
private lateinit var showProjectPlatformIconsCheckBox: JCheckBox
private lateinit var showEventListenerGutterCheckBox: JCheckBox
private lateinit var showChatColorUnderlinesCheckBox: JCheckBox
private lateinit var chatColorUnderlinesComboBox: JComboBox<MinecraftSettings.UnderlineType>
private lateinit var showChatGutterIconsCheckBox: JCheckBox
private lateinit var changePluginUpdateChannelButton: JButton
private lateinit var panel: DialogPanel

@Nls
override fun getDisplayName() = "Minecraft Development"

override fun getHelpTopic(): String? = null

override fun createComponent(): JComponent {
showChatColorUnderlinesCheckBox.addActionListener { setUnderlineBox() }

return panel
}

private fun init() {
for (type in MinecraftSettings.UnderlineType.values()) {
chatColorUnderlinesComboBox.addItem(type)
}
override fun getDisplayName() = MCDevBundle("minecraft.settings.display_name")

override fun createComponent(): JComponent = panel {
row(
Label(MCDevBundle("minecraft.settings.title"), bold = true).apply {
font = font.deriveFont(font.size * 1.5f)
icon = IconUtil.scale(PlatformAssets.MINECRAFT_ICON_2X, null, 1.5f)
}
) {
button(MCDevBundle("minecraft.settings.change_update_channel")) {
ConfigurePluginUpdatesDialog().show()
}.align(AlignX.RIGHT)
}.bottomGap(BottomGap.MEDIUM)

val settings = MinecraftSettings.instance

showProjectPlatformIconsCheckBox.isSelected = settings.isShowProjectPlatformIcons
showEventListenerGutterCheckBox.isSelected = settings.isShowEventListenerGutterIcons
showChatGutterIconsCheckBox.isSelected = settings.isShowChatColorGutterIcons
showChatColorUnderlinesCheckBox.isSelected = settings.isShowChatColorUnderlines

chatColorUnderlinesComboBox.selectedIndex = settings.underlineTypeIndex
setUnderlineBox()

changePluginUpdateChannelButton.addActionListener { ConfigurePluginUpdatesDialog().show() }
}

private fun setUnderlineBox() {
chatColorUnderlinesComboBox.isEnabled = showChatColorUnderlinesCheckBox.isSelected
}

override fun isModified(): Boolean {
val settings = MinecraftSettings.instance
row {
checkBox(MCDevBundle("minecraft.settings.show_project_platform_icons"))
.bindSelected(settings::isShowProjectPlatformIcons)
}
row {
checkBox(MCDevBundle("minecraft.settings.show_event_listener_gutter_icons"))
.bindSelected(settings::isShowEventListenerGutterIcons)
}
row {
checkBox(MCDevBundle("minecraft.settings.show_chat_color_gutter_icons"))
.bindSelected(settings::isShowChatColorGutterIcons)
}
row {
checkBox(MCDevBundle("minecraft.settings.show_chat_color_underlines"))
.bindSelected(settings::isShowChatColorUnderlines)
}.bottomGap(BottomGap.SMALL)

group(indent = false) {
row(MCDevBundle("minecraft.settings.chat_color_underline_style")) {
comboBox(EnumComboBoxModel(MinecraftSettings.UnderlineType::class.java))
.bindItem(settings::underlineType) { settings.underlineType = it!! }
.align(AlignX.LEFT)
}
}

return showProjectPlatformIconsCheckBox.isSelected != settings.isShowProjectPlatformIcons ||
showEventListenerGutterCheckBox.isSelected != settings.isShowEventListenerGutterIcons ||
showChatGutterIconsCheckBox.isSelected != settings.isShowChatColorGutterIcons ||
showChatColorUnderlinesCheckBox.isSelected != settings.isShowChatColorUnderlines ||
chatColorUnderlinesComboBox.selectedItem !== settings.underlineType
}
onApply {
for (project in ProjectManager.getInstance().openProjects) {
ProjectView.getInstance(project).refresh()
}
}
}.also { panel = it }

override fun apply() {
val settings = MinecraftSettings.instance
override fun isModified(): Boolean = panel.isModified()

settings.isShowProjectPlatformIcons = showProjectPlatformIconsCheckBox.isSelected
settings.isShowEventListenerGutterIcons = showEventListenerGutterCheckBox.isSelected
settings.isShowChatColorGutterIcons = showChatGutterIconsCheckBox.isSelected
settings.isShowChatColorUnderlines = showChatColorUnderlinesCheckBox.isSelected
settings.underlineType = chatColorUnderlinesComboBox.selectedItem as? MinecraftSettings.UnderlineType
?: MinecraftSettings.UnderlineType.DOTTED
}
override fun apply() = panel.apply()

override fun reset() {
init()
}
override fun reset() = panel.reset()
}
6 changes: 0 additions & 6 deletions src/main/kotlin/MinecraftSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ class MinecraftSettings : PersistentStateComponent<MinecraftSettings.State> {
state.underlineType = underlineType
}

val underlineTypeIndex: Int
get() {
val type = underlineType
return UnderlineType.values().indices.firstOrNull { type == UnderlineType.values()[it] } ?: 0
}

enum class UnderlineType(private val regular: String, val effectType: EffectType) {

NORMAL("Normal", EffectType.LINE_UNDERSCORE),
Expand Down
Loading

0 comments on commit 0f6dd78

Please sign in to comment.