Skip to content

Commit 6de959b

Browse files
committed
修改选择模块界面
Signed-off-by: dkinging <[email protected]>
1 parent 1ca2722 commit 6de959b

File tree

12 files changed

+598
-63
lines changed

12 files changed

+598
-63
lines changed

build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("java")
3-
id("org.jetbrains.kotlin.jvm") version "1.9.20"
3+
kotlin("jvm") version "1.9.22"
44
id("org.jetbrains.intellij") version "1.17.2"
55
id("com.github.johnrengelman.shadow") version "8.1.1"
66
}
@@ -43,7 +43,8 @@ kotlin {
4343

4444

4545
tasks {
46-
shadowJar {
46+
47+
shadowJar {
4748
archiveClassifier.set("all")
4849
relocate("org.freemarker", "org.tabooproject.intellij.freemarker")
4950
relocate("okhttp3", "org.tabooproject.intellij.okhttp3")

src/main/kotlin/org/tabooproject/intellij/FunctionTemplate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object FunctionTemplate {
1818
// 版本
1919
put("version", configProperty.version)
2020
// 模块列表
21-
put("modules", configProperty.modules.map { it })
21+
put("modules", configProperty.modules.map { it.id })
2222
// 从模块构建额外 imports
2323
put("extraPackages", configProperty.modules.map { "import io.izzel.taboolib.gradle.${it}" })
2424
val optionalProperty = OptionalPropertiesStep.property

src/main/kotlin/org/tabooproject/intellij/component/AddDeleteModuleListPanel.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.tabooproject.intellij.component
22

33
import com.intellij.ui.AddDeleteListPanel
4-
import org.jetbrains.kotlin.utils.addToStdlib.ifFalse
5-
import org.tabooproject.intellij.step.MODULES
64

5+
@Deprecated("Use CheckModulePanel")
76
class AddDeleteModuleListPanel(
87
title: String,
98
initial: List<String>,
@@ -18,12 +17,13 @@ class AddDeleteModuleListPanel(
1817
}
1918

2019
override fun findItemToAdd(): String? {
21-
val dialog = SelectBoxDialog("Add Module", "Choose a module:", MODULES
22-
.filter { it !in listItems }
23-
.toTypedArray()
24-
)
25-
dialog.showAndGet().ifFalse { return null }
26-
return MODULES.firstOrNull { it == dialog.getSelectedOption() }
20+
// val dialog = SelectBoxDialog("Add Module", "Choose a module:", MODULES
21+
// .filter { it !in listItems }
22+
// .toTypedArray()
23+
// )
24+
// dialog.showAndGet().ifFalse { return null }
25+
// return MODULES.firstOrNull { it == dialog.getSelectedOption() }
26+
return null
2727
}
2828

2929
fun export(): List<String> = listItems.map { it as String }
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.tabooproject.intellij.component
2+
3+
import com.intellij.packageDependencies.ui.TreeModel
4+
import com.intellij.ui.*
5+
import com.intellij.ui.CheckboxTree.CheckboxTreeCellRenderer
6+
import org.tabooproject.intellij.step.ConfigurationPropertiesStep
7+
import org.tabooproject.intellij.step.Module
8+
import javax.swing.JScrollPane
9+
import javax.swing.JTree
10+
import javax.swing.tree.DefaultMutableTreeNode
11+
12+
/**
13+
* @author 大阔
14+
* @since 2024/3/22 04:31
15+
*/
16+
class CheckModuleList(private val displayModuleList: DisplayModuleList) : JScrollPane() {
17+
18+
val root = CheckedTreeNode("Root").apply {
19+
isFocusable = false
20+
}
21+
22+
private val treeNode = TreeModel(root)
23+
24+
private val checkBoxList = CheckboxTreeBase(object : CheckboxTreeCellRenderer() {
25+
override fun customizeRenderer(
26+
tree: JTree?,
27+
value: Any?,
28+
selected: Boolean,
29+
expanded: Boolean,
30+
leaf: Boolean,
31+
row: Int,
32+
hasFocus: Boolean
33+
) {
34+
if (value is CheckedTreeNode) {
35+
if (value.userObject is Module) {
36+
val module = value.userObject as Module
37+
38+
textRenderer.append(
39+
ColoredText.singleFragment(
40+
module.name, SimpleTextAttributes(
41+
SimpleTextAttributes.STYLE_BOLD,
42+
JBColor.BLACK
43+
)
44+
)
45+
)
46+
47+
textRenderer.append(" ")
48+
49+
textRenderer.append(
50+
ColoredText.singleFragment(
51+
module.name, SimpleTextAttributes(
52+
SimpleTextAttributes.STYLE_PLAIN,
53+
JBColor.GRAY
54+
)
55+
)
56+
)
57+
}
58+
} else if (value is DefaultMutableTreeNode) {
59+
textRenderer.append((value as DefaultMutableTreeNode).userObject.toString())
60+
}
61+
}
62+
}, root)
63+
64+
init {
65+
checkBoxList.model = treeNode
66+
checkBoxList.isFocusable = false
67+
checkBoxList.addCheckboxTreeListener(object : CheckboxTreeListener {
68+
override fun nodeStateChanged(node: CheckedTreeNode) {
69+
if (node.userObject !is Module) return
70+
if (node.isChecked) {
71+
ConfigurationPropertiesStep.property.modules.add(node.userObject as Module)
72+
displayModuleList.addModule((node.userObject as Module).name)
73+
} else {
74+
ConfigurationPropertiesStep.property.modules.remove(node.userObject as Module)
75+
displayModuleList.removeModule((node.userObject as Module).name)
76+
}
77+
}
78+
})
79+
setFocusable(false)
80+
autoscrolls = true
81+
setViewportView(checkBoxList)
82+
}
83+
84+
override fun updateUI() {
85+
treeNode?.reload()
86+
super.updateUI()
87+
}
88+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.tabooproject.intellij.component
2+
3+
import com.intellij.ui.CheckedTreeNode
4+
import com.intellij.ui.components.JBLabel
5+
import com.intellij.ui.components.JBPanel
6+
import org.tabooproject.intellij.step.Module
7+
import java.awt.Dimension
8+
import java.awt.GridBagConstraints
9+
import java.awt.GridBagLayout
10+
import javax.swing.tree.DefaultMutableTreeNode
11+
12+
/**
13+
* @author 大阔
14+
* @since 2024/3/22 23:28
15+
*/
16+
class CheckModulePanel : JBPanel<CheckModulePanel>() {
17+
18+
private val displayModuleList = DisplayModuleList()
19+
private val moduleCheck = CheckModuleList(displayModuleList)
20+
21+
init {
22+
layout = GridBagLayout()
23+
24+
val gbc = GridBagConstraints()
25+
26+
27+
gbc.fill = GridBagConstraints.BOTH
28+
gbc.weightx = 0.1
29+
gbc.weighty = 0.1
30+
gbc.gridwidth = 1
31+
gbc.gridheight = 1
32+
gbc.gridx = 0
33+
gbc.gridy = 0
34+
add(JBLabel("Select Modules"), gbc)
35+
gbc.gridx = 1
36+
add(JBLabel("Selected Modules"), gbc)
37+
gbc.gridx = 0
38+
gbc.gridy = 1
39+
gbc.weightx = 0.9
40+
gbc.weighty = 0.9
41+
add(moduleCheck, gbc)
42+
43+
gbc.gridx = 1
44+
add(displayModuleList, gbc)
45+
preferredSize = Dimension(600, 350)
46+
minimumSize = Dimension(0, 0)
47+
}
48+
49+
// 回调
50+
fun setModules(modules: Map<String, List<Module>>) {
51+
modules.map {
52+
DefaultMutableTreeNode(it.key).apply {
53+
it.value.forEach {
54+
add(CheckedTreeNode(it).apply {
55+
// if (ConfigurationPropertiesStep.property.modules.contains(it.name)){
56+
// isChecked = true
57+
// }
58+
isChecked = false
59+
isFocusable = false
60+
})
61+
}
62+
isFocusable = false
63+
}
64+
}.forEach {
65+
moduleCheck.root.add(it)
66+
}
67+
moduleCheck.updateUI()
68+
}
69+
70+
71+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.tabooproject.intellij.component
2+
3+
import com.intellij.ui.CollectionListModel
4+
import com.intellij.ui.components.JBList
5+
import javax.swing.JScrollPane
6+
7+
/**
8+
* @author 大阔
9+
* @since 2024/3/22 05:28
10+
*/
11+
class DisplayModuleList : JScrollPane() {
12+
13+
private val listModule = CollectionListModel<String>()
14+
15+
init {
16+
isFocusable = false
17+
val jbList = JBList<String>()
18+
jbList.model = listModule
19+
20+
setViewportView(jbList)
21+
}
22+
23+
fun addModule(module: String) {
24+
listModule.add(module)
25+
updateUI()
26+
}
27+
28+
fun removeModule(module: String) {
29+
listModule.remove(module)
30+
updateUI()
31+
}
32+
33+
34+
}

src/main/kotlin/org/tabooproject/intellij/component/SelectBoxDialog.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import javax.swing.JComponent
77
import javax.swing.JLabel
88
import javax.swing.JPanel
99

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

1213
private val comboBox: JComboBox<String> = ComboBox(options)

0 commit comments

Comments
 (0)