Skip to content

Commit 6fd0f66

Browse files
committed
expand dirs from path
1 parent 7281ab5 commit 6fd0f66

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,43 +235,43 @@ open class FileTreeNode() {
235235
}
236236

237237
fun isRoot(): Boolean {
238-
return this == parent
238+
return this == parent || parent == null
239239
}
240240

241241
fun build() {
242242

243243
name = getRealName()
244-
var r = sPathSplitPattern.matcher(name)
245-
val dirs = mutableListOf<String>()
246-
while (r.find()) {
247-
dirs.add(r.group(1))
244+
if (!isDir) {
245+
return
246+
}
247+
if (!isRoot()) {
248+
val dir = name.split(sPathSplitPattern).toMutableList()
249+
expandDirs(dir)
250+
}
251+
children.forEach {
252+
it.build()
248253
}
249-
traversal({ fileTreeNode: FileTreeNode, _: Int ->
250-
fileTreeNode.name = fileTreeNode.getRealName()
251-
r = sPathSplitPattern.matcher(fileTreeNode.name)
252-
dirs.clear()
253-
while (r.find()) {
254-
dirs.add(r.group(1))
255-
}
256-
expandDirs(dirs)
257-
})
258254
}
259255

260256
private fun expandDirs(dirs: List<String>) {
261-
if (dirs.isEmpty()) {
257+
if (dirs.isEmpty() || dirs.size == 1) {
262258
return
263259
}
264260
this.name = dirs.first()
265261
dirs.drop(0)
266262

267-
var parent: FileTreeNode = this
263+
var node: FileTreeNode? = null
264+
var preNode: FileTreeNode = this
268265
var newChild: FileTreeNode
269266
dirs.forEach {
270-
newChild = FileTreeNode(parent, it, true)
271-
parent.addChild(newChild)
272-
parent = newChild
267+
newChild = FileTreeNode(preNode, it, true)
268+
if (node == null) {
269+
node = newChild
270+
}
271+
preNode.addChild(newChild)
272+
preNode = newChild
273273
}
274-
parent.children.addAll(children)
274+
preNode.children = children
275275
children.clear()
276276
labeledChildren.clear()
277277
realChildren.clear()

test/AucTemplateTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ class AucTemplateTest {
1515
println(app.getAllPlaceholderInTree())
1616
println(app.getTreeGraph())
1717

18+
app.build()
19+
println(app)
20+
println(app.getTreeGraph())
1821
}
1922
}

0 commit comments

Comments
 (0)