add a few things:
* test case with folders/subfolders * renaming items by double-clicking them * naive drag test
This commit is contained in:
@@ -5,23 +5,60 @@
|
||||
[sub_resource type="GDScript" id=1]
|
||||
script/source = "extends Control
|
||||
|
||||
onready var control_tree: ControlTree = $ControlTree
|
||||
|
||||
var i
|
||||
var j
|
||||
|
||||
var files: Array = [] # Array[FileDef]
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
files = get_dir_contents(ProjectSettings.globalize_path(\"res://test_dir\"))
|
||||
construct_tree(files)
|
||||
|
||||
|
||||
func _on_Button_pressed() -> void:
|
||||
i = $ControlTree.add_item('test')
|
||||
func get_dir_contents(path: String) -> Array:
|
||||
var res = []
|
||||
var dir = Directory.new()
|
||||
if dir.open(path) == OK:
|
||||
dir.list_dir_begin(true)
|
||||
var fname = dir.get_next()
|
||||
while fname != \"\":
|
||||
var f = FileDef.new()
|
||||
f.path = fname
|
||||
# print(f.path)
|
||||
if dir.current_is_dir():
|
||||
var a = get_dir_contents(path.plus_file(fname))
|
||||
f.contains.append_array(a)
|
||||
|
||||
res.append(f)
|
||||
fname = dir.get_next()
|
||||
dir.list_dir_end()
|
||||
return res
|
||||
|
||||
|
||||
func _on_Button2_pressed() -> void:
|
||||
j = $ControlTree.add_item('test2', i)
|
||||
func construct_tree(from: Array, parent: ControlTreeItem = null):
|
||||
for f in from:
|
||||
var item = control_tree.add_item(f.path, parent)
|
||||
if f.contains:
|
||||
item.editable = false
|
||||
construct_tree(f.contains, item)
|
||||
|
||||
|
||||
func _on_Button3_pressed() -> void:
|
||||
$ControlTree.add_item('test3', j)
|
||||
#func _on_Button_pressed() -> void:
|
||||
# i = $ControlTree.add_item('test')
|
||||
#
|
||||
#
|
||||
#func _on_Button2_pressed() -> void:
|
||||
# j = $ControlTree.add_item('test2', i)
|
||||
#
|
||||
#
|
||||
#func _on_Button3_pressed() -> void:
|
||||
# $ControlTree.add_item('test3', j)
|
||||
|
||||
class FileDef:
|
||||
var path: String
|
||||
var contains: Array # Array[FileDef]
|
||||
"
|
||||
|
||||
[node name="TestArea" type="Control"]
|
||||
|
||||
Reference in New Issue
Block a user