Allow recursive folder opening

This commit is contained in:
don-tnowe 2023-08-24 22:19:01 +03:00
parent 7411cb27d4
commit 9b826b5539
2 changed files with 34 additions and 13 deletions

View File

@ -51,9 +51,19 @@ func _ready():
func _on_filesystem_changed():
var path = editor_interface.get_resource_filesystem().get_filesystem_path(current_path)
var editor_fs := editor_interface.get_resource_filesystem()
var path := editor_fs.get_filesystem_path(current_path)
if !path: return
if path.get_file_count() != remembered_paths.size():
var file_total_count := 0
var folder_stack : Array[EditorFileSystemDirectory] = [path]
while folder_stack.size() > 0:
path = folder_stack.pop_back()
file_total_count += path.get_file_count()
for i in path.get_subdir_count():
folder_stack.append(path.get_subdir(i))
if file_total_count != remembered_paths.size():
refresh()
else:
@ -202,7 +212,8 @@ func _update_row_range(first : int, last : int, color_rows : bool):
func _update_row(row_index : int, color_rows : bool = true):
var current_node : Control
var next_color := Color.WHITE
var column_editors = _selection.column_editors
var column_editors : Array = _selection.column_editors
var res_path : String = rows[row_index].resource_path.get_basename().substr(current_path.length())
for i in columns.size():
if node_table_root.get_child_count() <= (row_index - first_row) * columns.size() + i:
current_node = column_editors[i].create_cell(self)
@ -214,12 +225,12 @@ func _update_row(row_index : int, color_rows : bool = true):
current_node.tooltip_text = (
columns[i].capitalize()
+ "\n---\n"
+ "Of " + rows[row_index].resource_path.get_file().get_basename()
+ "Of " + res_path
)
column_editors[i].set_value(current_node, io.get_value(rows[row_index], columns[i]))
if columns[i] == "resource_path":
column_editors[i].set_value(current_node, current_node.text.get_file().get_basename())
column_editors[i].set_value(current_node, res_path)
if color_rows and column_types[i] == TYPE_COLOR:
next_color = io.get_value(rows[row_index], columns[i])

View File

@ -56,19 +56,30 @@ func import_from_path(folderpath : String, insert_func : Callable, sort_by : Str
var rows := []
var dir := DirAccess.open(folderpath)
if dir == null: return []
dir.list_dir_begin()
editor_view.remembered_paths.clear()
var cur_dir_script : Script = null
var filepath = dir.get_next()
var file_stack : Array[String] = []
var folder_stack : Array[String] = [folderpath]
var res : Resource
while filepath != "":
while folder_stack.size() > 0:
folderpath = folder_stack.pop_back()
for x in DirAccess.get_files_at(folderpath):
file_stack.append(folderpath.path_join(x))
for x in DirAccess.get_directories_at(folderpath):
folder_stack.append(folderpath.path_join(x))
for x in file_stack:
res = null
filepath = folderpath + filepath
if filepath.ends_with(".tres"):
res = load(filepath)
if x.ends_with(".tres"):
res = load(x)
if res.get_script() == null:
continue
if !is_instance_valid(cur_dir_script):
editor_view.fill_property_data(res)
cur_dir_script = res.get_script()
@ -78,7 +89,6 @@ func import_from_path(folderpath : String, insert_func : Callable, sort_by : Str
if res.get_script() == cur_dir_script:
insert_func.call(res, rows, sort_by, sort_reverse)
editor_view.remembered_paths[filepath] = res
filepath = dir.get_next()
editor_view.remembered_paths[x] = res
return rows