diff options
author | Tomasz Chabora <kobewi4e@gmail.com> | 2019-03-25 22:39:45 +0100 |
---|---|---|
committer | Tomasz Chabora <kobewi4e@gmail.com> | 2019-03-26 13:33:38 +0100 |
commit | c0da243f04d0df831134cce1b49471d42689d2ba (patch) | |
tree | f5cbce9f67a32773982ee412c16a9110677e383a /editor | |
parent | 9c3ddf05cb9c59817d885e9daca6e8f61c89dc97 (diff) |
Allow to drop folders onto editor
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 40 | ||||
-rw-r--r-- | editor/editor_node.h | 1 |
2 files changed, 38 insertions, 3 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6140412a32..55955813c7 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4537,19 +4537,53 @@ void EditorNode::remove_tool_menu_item(const String &p_name) { void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) { String to_path = ProjectSettings::get_singleton()->globalize_path(get_filesystem_dock()->get_selected_path()); - DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + _add_dropped_files_recursive(p_files, to_path); + + EditorFileSystem::get_singleton()->scan_changes(); +} + +void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, String to_path) { + + DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Vector<String> just_copy = String("ttf,otf").split(","); + for (int i = 0; i < p_files.size(); i++) { String from = p_files[i]; + String to = to_path.plus_file(from.get_file()); + + if (dir->dir_exists(from)) { + + Vector<String> sub_files; + + DirAccessRef sub_dir = DirAccess::open(from); + sub_dir->list_dir_begin(); + + String next_file = sub_dir->get_next(); + while (next_file != "") { + if (next_file == "." || next_file == "..") { + next_file = sub_dir->get_next(); + continue; + } + + sub_files.push_back(from.plus_file(next_file)); + next_file = sub_dir->get_next(); + } + + if (!sub_files.empty()) { + dir->make_dir(to); + _add_dropped_files_recursive(sub_files, to); + } + + continue; + } + if (!ResourceFormatImporter::get_singleton()->can_be_imported(from) && (just_copy.find(from.get_extension().to_lower()) == -1)) { continue; } - String to = to_path.plus_file(from.get_file()); dir->copy(from, to); } - EditorFileSystem::get_singleton()->scan_changes(); } void EditorNode::_file_access_close_error_notify(const String &p_str) { diff --git a/editor/editor_node.h b/editor/editor_node.h index 267c70c773..48cbe97677 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -468,6 +468,7 @@ private: void _update_recent_scenes(); void _open_recent_scene(int p_idx); void _dropped_files(const Vector<String> &p_files, int p_screen); + void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path); String _recent_scene; void _exit_editor(); |