Skip to content

Commit c9d6737

Browse files
committed
ref: convert to kotlin
1 parent 63e0464 commit c9d6737

13 files changed

Lines changed: 537 additions & 556 deletions

src/com/dengzii/plugin/template/TemplateConfigurable.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.dengzii.plugin.template
22

33
import com.dengzii.plugin.template.ui.ConfigurePanel
4+
import com.dengzii.plugin.template.ui.RealConfigurePanel
45
import com.intellij.openapi.options.SearchableConfigurable
56
import org.jetbrains.annotations.Nls
67
import javax.swing.JComponent
@@ -16,7 +17,7 @@ import javax.swing.JComponent
1617
*/
1718
class TemplateConfigurable() : SearchableConfigurable {
1819

19-
private lateinit var panelConfig: ConfigurePanel
20+
private lateinit var panelConfig: RealConfigurePanel
2021
private var onApplyListener: OnApplyListener? = null
2122

2223
constructor(onApplyListener: OnApplyListener) : this() {
@@ -34,7 +35,7 @@ class TemplateConfigurable() : SearchableConfigurable {
3435
}
3536

3637
override fun createComponent(): JComponent? {
37-
panelConfig = ConfigurePanel()
38+
panelConfig = RealConfigurePanel()
3839
return panelConfig
3940
}
4041

src/com/dengzii/plugin/template/model/FileTreeDsl.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.dengzii.plugin.template.model
22

3-
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
4-
53
class FileTreeDsl() : FileTreeNode() {
64

75
constructor(block: FileTreeDsl.() -> Unit) : this() {
@@ -37,8 +35,8 @@ class FileTreeDsl() : FileTreeNode() {
3735

3836
fun FileTreeNode.file(name: String) {
3937
if (!isDir) return
40-
name.getPlaceholder().ifNotEmpty {
41-
allPlaceholder.addAll(this)
38+
if (name.getPlaceholder().isNotEmpty()) {
39+
allPlaceholder.addAll(name.getPlaceholder())
4240
}
4341
addChild(FileTreeNode(this, name, false))
4442
}

src/com/dengzii/plugin/template/model/FileTreeNode.kt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package com.dengzii.plugin.template.model
44

55
import com.dengzii.plugin.template.utils.Logger
6-
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
76
import java.io.File
87
import java.util.*
98
import java.util.regex.Pattern
@@ -29,6 +28,7 @@ open class FileTreeNode() {
2928
get() = realChildren
3029

3130
var placeholders: MutableMap<String, String>? = null
31+
3232
// all placeholder in tree node name
3333
val allPlaceholder = mutableListOf<String>()
3434

@@ -43,6 +43,7 @@ open class FileTreeNode() {
4343
// the label composed by 'name' and 'isDir'.
4444
@Transient
4545
private val labeledChildren = mutableMapOf<String, FileTreeNode>()
46+
4647
@Transient
4748
var parent: FileTreeNode? = null
4849

@@ -69,9 +70,17 @@ open class FileTreeNode() {
6970
this.name = name
7071
this.parent = parent
7172
this.isDir = isDir
72-
name.getPlaceholder().ifNotEmpty {
73-
allPlaceholder.addAll(this)
73+
if (name.getPlaceholder().isNotEmpty()) {
74+
allPlaceholder.addAll(name.getPlaceholder())
75+
}
76+
}
77+
78+
fun getTreeNodeCount(): Int {
79+
var count = realChildren.size
80+
realChildren.forEach {
81+
count += it.getTreeNodeCount()
7482
}
83+
return count
7584
}
7685

7786
fun removeFromParent(): Boolean {
@@ -137,6 +146,17 @@ open class FileTreeNode() {
137146
}
138147
}
139148

149+
fun getNodeHasTemplateInTree(): List<FileTreeNode> {
150+
val nodes = mutableListOf<FileTreeNode>()
151+
if (fileTemplates != null) {
152+
nodes.add(this)
153+
}
154+
realChildren.forEach {
155+
nodes.addAll(it.getNodeHasTemplateInTree())
156+
}
157+
return nodes
158+
}
159+
140160
fun getFileTemplateInherit(): MutableMap<String, String>? {
141161
return fileTemplates ?: parent?.getFileTemplateInherit()
142162
}

src/com/dengzii/plugin/template/ui/ConfigurePanel.form

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
<children>
1717
<component id="9661f" class="com.dengzii.plugin.template.ui.EditToolbar" binding="actionbar">
1818
<constraints/>
19-
<properties/>
19+
<properties>
20+
<enabled value="true"/>
21+
</properties>
2022
</component>
2123
<grid id="699a3" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
2224
<margin top="0" left="100" bottom="0" right="0"/>
@@ -61,7 +63,7 @@
6163
<border type="none"/>
6264
<children>
6365
<grid id="6e9e7" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
64-
<margin top="6" left="6" bottom="6" right="6"/>
66+
<margin top="6" left="6" bottom="6" right="0"/>
6567
<constraints border-constraint="West"/>
6668
<properties/>
6769
<border type="empty"/>
@@ -99,7 +101,7 @@
99101
</border>
100102
<children>
101103
<grid id="6d154" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
102-
<margin top="0" left="6" bottom="6" right="6"/>
104+
<margin top="0" left="0" bottom="0" right="0"/>
103105
<constraints border-constraint="Center"/>
104106
<properties/>
105107
<border type="none"/>

0 commit comments

Comments
 (0)