From 90768f1f7f6ad8e8bee53ae6c7addf011a2a94d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Fri, 8 Sep 2023 08:23:44 +0800 Subject: [PATCH] Fix unexpected behaviors of using Duplicate To on folders Fix folder not being copied when empty. Fix Keep Both would generate wrong paths when copying folders. --- editor/filesystem_dock.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index c5feb71c9e0..a1a0f687789 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1528,6 +1528,8 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin } } } else { + da->make_dir(new_path); + // Recursively duplicate all files inside the folder. Ref old_dir = DirAccess::open(old_path); ERR_FAIL_COND(old_dir.is_null()); @@ -1894,22 +1896,15 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop if (p_overwrite == OVERWRITE_RENAME) { new_paths.write[i] = _get_unique_name(to_move[i], p_to_path); } else { - new_paths.write[i] = p_to_path.path_join(to_move[i].path.get_file()); + new_paths.write[i] = p_to_path.path_join(to_move[i].path.trim_suffix("/").get_file()); } } if (p_copy) { bool is_copied = false; for (int i = 0; i < to_move.size(); i++) { - String old_path = to_move[i].path; - String new_path = new_paths[i]; - - if (!to_move[i].is_file) { - new_path = new_path.path_join(old_path.trim_suffix("/").get_file()); - } - - if (old_path != new_path) { - _try_duplicate_item(to_move[i], new_path); + if (to_move[i].path != new_paths[i]) { + _try_duplicate_item(to_move[i], new_paths[i]); is_copied = true; } } @@ -1934,15 +1929,8 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop HashMap folder_renames; for (int i = 0; i < to_move.size(); i++) { - String old_path = to_move[i].path; - String new_path = new_paths[i]; - - if (!to_move[i].is_file) { - new_path = new_path.path_join(old_path.trim_suffix("/").get_file()); - } - - if (old_path != new_path) { - _try_move_item(to_move[i], new_path, file_renames, folder_renames); + if (to_move[i].path != new_paths[i]) { + _try_move_item(to_move[i], new_paths[i], file_renames, folder_renames); is_moved = true; } }