[gd_scene load_steps=3 format=2] [ext_resource path="res://ControlTree.tscn" type="PackedScene" id=1] [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: files = get_dir_contents(ProjectSettings.globalize_path(\"res://test_dir\")) construct_tree(files) 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 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_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"] anchor_right = 1.0 anchor_bottom = 1.0 script = SubResource( 1 ) [node name="ControlTree" parent="." instance=ExtResource( 1 )] [node name="Button" type="Button" parent="."] margin_left = 634.0 margin_top = 48.0 margin_right = 765.0 margin_bottom = 97.0 text = "Add item" [node name="Button2" type="Button" parent="."] margin_left = 634.0 margin_top = 117.0 margin_right = 765.0 margin_bottom = 166.0 text = "Add subitem" [node name="Button3" type="Button" parent="."] margin_left = 634.0 margin_top = 194.0 margin_right = 765.0 margin_bottom = 243.0 text = "Add subsubitem" [connection signal="pressed" from="Button" to="." method="_on_Button_pressed"] [connection signal="pressed" from="Button2" to="." method="_on_Button2_pressed"] [connection signal="pressed" from="Button3" to="." method="_on_Button3_pressed"]