From d46ab53b41e6339b67686b2f43818107bc5ab153 Mon Sep 17 00:00:00 2001 From: Tomasz Chabora Date: Fri, 5 Jun 2020 01:53:35 +0200 Subject: [PATCH] Allow duplicating files when holding Control (cherry picked from commit b426d11d8617daa79ccc5fa8c644abb8c8dfecd0) --- editor/filesystem_dock.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index ccb8fcf1f6f..8bfddfd6834 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -33,6 +33,7 @@ #include "core/io/resource_loader.h" #include "core/os/dir_access.h" #include "core/os/file_access.h" +#include "core/os/input.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -2059,7 +2060,32 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } } if (!to_move.empty()) { - _move_operation_confirm(to_dir); + if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + for (int i = 0; i < to_move.size(); i++) { + String new_path; + String new_path_base; + + if (to_move[i].is_file) { + new_path = to_dir.plus_file(to_move[i].path.get_file()); + new_path_base = new_path.get_basename() + " (%d)." + new_path.get_extension(); + } else { + Vector path_split = to_move[i].path.split("/"); + new_path = to_dir.plus_file(path_split[path_split.size() - 2]); + new_path_base = new_path + " (%d)"; + } + + int exist_counter = 1; + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + while (da->file_exists(new_path) || da->dir_exists(new_path)) { + exist_counter++; + new_path = vformat(new_path_base, exist_counter); + } + _try_duplicate_item(to_move[i], new_path); + } + _rescan(); + } else { + _move_operation_confirm(to_dir); + } } } else if (favorite) { // Add the files from favorites.