Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "1.9.20"
kotlin("jvm") version "1.9.22"
id("org.jetbrains.intellij") version "1.17.2"
id("com.github.johnrengelman.shadow") version "8.1.1"
}
Expand Down Expand Up @@ -42,7 +42,8 @@ kotlin {


tasks {
shadowJar {

shadowJar {
archiveClassifier.set("all")
relocate("org.freemarker", "org.tabooproject.intellij.freemarker")
relocate("okhttp3", "org.tabooproject.intellij.okhttp3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object FunctionTemplate {
// 版本
put("version", configProperty.version)
// 模块列表
put("modules", configProperty.modules.map { it })
put("modules", configProperty.modules.map { it.id })
// 从模块构建额外 imports
put("extraPackages", configProperty.modules.map { "import io.izzel.taboolib.gradle.${it}" })
val optionalProperty = OptionalPropertiesStep.property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.tabooproject.intellij.component

import com.intellij.ui.AddDeleteListPanel
import org.jetbrains.kotlin.utils.addToStdlib.ifFalse
import org.tabooproject.intellij.step.MODULES

@Deprecated("Use CheckModulePanel")
class AddDeleteModuleListPanel(
title: String,
initial: List<String>,
Expand All @@ -18,12 +17,13 @@ class AddDeleteModuleListPanel(
}

override fun findItemToAdd(): String? {
val dialog = SelectBoxDialog("Add Module", "Choose a module:", MODULES
.filter { it !in listItems }
.toTypedArray()
)
dialog.showAndGet().ifFalse { return null }
return MODULES.firstOrNull { it == dialog.getSelectedOption() }
// val dialog = SelectBoxDialog("Add Module", "Choose a module:", MODULES
// .filter { it !in listItems }
// .toTypedArray()
// )
// dialog.showAndGet().ifFalse { return null }
// return MODULES.firstOrNull { it == dialog.getSelectedOption() }
return null
}

fun export(): List<String> = listItems.map { it as String }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.tabooproject.intellij.component

import com.intellij.packageDependencies.ui.TreeModel
import com.intellij.ui.*
import com.intellij.ui.CheckboxTree.CheckboxTreeCellRenderer
import org.tabooproject.intellij.step.ConfigurationPropertiesStep
import org.tabooproject.intellij.step.Module
import javax.swing.JScrollPane
import javax.swing.JTree
import javax.swing.tree.DefaultMutableTreeNode

/**
* @author 大阔
* @since 2024/3/22 04:31
*/
class CheckModuleList(private val displayModuleList: DisplayModuleList) : JScrollPane() {

val root = CheckedTreeNode("Root").apply {
isFocusable = false
}

private val treeNode = TreeModel(root)

private val checkBoxList = CheckboxTreeBase(object : CheckboxTreeCellRenderer() {
override fun customizeRenderer(
tree: JTree?,
value: Any?,
selected: Boolean,
expanded: Boolean,
leaf: Boolean,
row: Int,
hasFocus: Boolean
) {
if (value is CheckedTreeNode) {
if (value.userObject is Module) {
val module = value.userObject as Module

textRenderer.append(
ColoredText.singleFragment(
module.name, SimpleTextAttributes(
SimpleTextAttributes.STYLE_BOLD,
JBColor.BLACK
)
)
)

textRenderer.append(" ")

textRenderer.append(
ColoredText.singleFragment(
module.name, SimpleTextAttributes(
SimpleTextAttributes.STYLE_PLAIN,
JBColor.GRAY
)
)
)
}
} else if (value is DefaultMutableTreeNode) {
textRenderer.append((value as DefaultMutableTreeNode).userObject.toString())
}
}
}, root)

init {
checkBoxList.model = treeNode
checkBoxList.isFocusable = false
checkBoxList.addCheckboxTreeListener(object : CheckboxTreeListener {
override fun nodeStateChanged(node: CheckedTreeNode) {
if (node.userObject !is Module) return
if (node.isChecked) {
ConfigurationPropertiesStep.property.modules.add(node.userObject as Module)
displayModuleList.addModule((node.userObject as Module).name)
} else {
ConfigurationPropertiesStep.property.modules.remove(node.userObject as Module)
displayModuleList.removeModule((node.userObject as Module).name)
}
}
})
setFocusable(false)
autoscrolls = true
setViewportView(checkBoxList)
}

override fun updateUI() {
treeNode?.reload()
super.updateUI()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.tabooproject.intellij.component

import com.intellij.ui.CheckedTreeNode
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBPanel
import org.tabooproject.intellij.step.Module
import java.awt.Dimension
import java.awt.GridBagConstraints
import java.awt.GridBagLayout
import javax.swing.tree.DefaultMutableTreeNode

/**
* @author 大阔
* @since 2024/3/22 23:28
*/
class CheckModulePanel : JBPanel<CheckModulePanel>() {

private val displayModuleList = DisplayModuleList()
private val moduleCheck = CheckModuleList(displayModuleList)

init {
layout = GridBagLayout()

val gbc = GridBagConstraints()


gbc.fill = GridBagConstraints.BOTH
gbc.weightx = 0.1
gbc.weighty = 0.1
gbc.gridwidth = 1
gbc.gridheight = 1
gbc.gridx = 0
gbc.gridy = 0
add(JBLabel("Select Modules"), gbc)
gbc.gridx = 1
add(JBLabel("Selected Modules"), gbc)
gbc.gridx = 0
gbc.gridy = 1
gbc.weightx = 0.9
gbc.weighty = 0.9
add(moduleCheck, gbc)

gbc.gridx = 1
add(displayModuleList, gbc)
preferredSize = Dimension(600, 350)
minimumSize = Dimension(0, 0)
}

// 回调
fun setModules(modules: Map<String, List<Module>>) {
modules.map {
DefaultMutableTreeNode(it.key).apply {
it.value.forEach {
add(CheckedTreeNode(it).apply {
// if (ConfigurationPropertiesStep.property.modules.contains(it.name)){
// isChecked = true
// }
isChecked = false
isFocusable = false
})
}
isFocusable = false
}
}.forEach {
moduleCheck.root.add(it)
}
moduleCheck.updateUI()
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.tabooproject.intellij.component

import com.intellij.ui.CollectionListModel
import com.intellij.ui.components.JBList
import javax.swing.JScrollPane

/**
* @author 大阔
* @since 2024/3/22 05:28
*/
class DisplayModuleList : JScrollPane() {

private val listModule = CollectionListModel<String>()

init {
isFocusable = false
val jbList = JBList<String>()
jbList.model = listModule

setViewportView(jbList)
}

fun addModule(module: String) {
listModule.add(module)
updateUI()
}

fun removeModule(module: String) {
listModule.remove(module)
updateUI()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel

@Deprecated("Use CheckModulePanel")
class SelectBoxDialog(inputTitle: String, private val inputMessage: String, options: Array<String>) : DialogWrapper(true) {

private val comboBox: JComboBox<String> = ComboBox(options)
Expand Down
Loading