summaryrefslogtreecommitdiff
path: root/editor/filesystem_dock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r--editor/filesystem_dock.cpp86
1 files changed, 70 insertions, 16 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index c30f077888..b18cd6b747 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -147,7 +147,7 @@ void FileSystemDock::_notification(int p_what) {
if (low_height_mode) {
- file_list_vb->hide();
+ tree->hide();
tree->set_v_size_flags(SIZE_EXPAND_FILL);
button_tree->show();
} else {
@@ -158,6 +158,7 @@ void FileSystemDock::_notification(int p_what) {
button_favorite->show();
_update_tree(true);
}
+ tree->ensure_cursor_is_visible();
if (!file_list_vb->is_visible()) {
file_list_vb->show();
@@ -345,11 +346,7 @@ void FileSystemDock::navigate_to_path(const String &p_path) {
_update_tree(true);
_update_files(false);
} else {
- if (file_name.empty()) {
- _go_to_tree();
- } else {
- _go_to_file_list();
- }
+ _go_to_file_list();
}
if (!file_name.empty()) {
@@ -406,12 +403,12 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *
_search(p_path->get_subdir(i), matches, p_max_items);
}
- String match = search_box->get_text();
+ String match = search_box->get_text().to_lower();
for (int i = 0; i < p_path->get_file_count(); i++) {
String file = p_path->get_file(i);
- if (file.find(match) != -1) {
+ if (file.to_lower().find(match) != -1) {
FileInfo fi;
fi.name = file;
@@ -822,7 +819,7 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
print_line("Duplicating " + old_path + " -> " + new_path);
- Error err = da->copy(old_path, new_path);
+ Error err = p_item.is_file ? da->copy(old_path, new_path) : da->copy_dir(old_path, new_path);
if (err == OK) {
//Move/Rename any corresponding import settings too
if (p_item.is_file && FileAccess::exists(old_path + ".import")) {
@@ -837,6 +834,58 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin
memdelete(da);
}
+void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> &p_renames) const {
+
+ //Rename all resources loaded, be it subresources or actual resources
+ List<Ref<Resource> > cached;
+ ResourceCache::get_cached_resources(&cached);
+
+ for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
+
+ Ref<Resource> r = E->get();
+
+ String base_path = r->get_path();
+ String extra_path;
+ int sep_pos = r->get_path().find("::");
+ if (sep_pos >= 0) {
+ extra_path = base_path.substr(sep_pos, base_path.length());
+ base_path = base_path.substr(0, sep_pos);
+ }
+
+ if (p_renames.has(base_path)) {
+ base_path = p_renames[base_path];
+ }
+
+ r->set_path(base_path + extra_path);
+ }
+
+ for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
+
+ String path;
+ if (i == EditorNode::get_editor_data().get_edited_scene()) {
+ if (!get_tree()->get_edited_scene_root())
+ continue;
+
+ path = get_tree()->get_edited_scene_root()->get_filename();
+ } else {
+
+ path = EditorNode::get_editor_data().get_scene_path(i);
+ }
+
+ if (p_renames.has(path)) {
+ path = p_renames[path];
+ }
+
+ if (i == EditorNode::get_editor_data().get_edited_scene()) {
+
+ get_tree()->get_edited_scene_root()->set_filename(path);
+ } else {
+
+ EditorNode::get_editor_data().set_scene_path(i, path);
+ }
+ }
+}
+
void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &p_renames) const {
//The following code assumes that the following holds:
// 1) EditorFileSystem contains the old paths/folder structure from before the rename/move.
@@ -913,6 +962,7 @@ void FileSystemDock::_rename_operation_confirm() {
Map<String, String> renames;
_try_move_item(to_rename, new_path, renames);
_update_dependencies_after_move(renames);
+ _update_resource_paths_after_move(renames);
//Rescan everything
print_line("call rescan!");
@@ -930,10 +980,12 @@ void FileSystemDock::_duplicate_operation_confirm() {
return;
}
- String old_path = to_duplicate.path.ends_with("/") ? to_duplicate.path.substr(0, to_duplicate.path.length() - 1) : to_rename.path;
- String new_path = old_path.get_base_dir().plus_file(new_name);
- if (old_path == new_path) {
- return;
+ String new_path;
+ String base_dir = to_duplicate.path.get_base_dir();
+ if (to_duplicate.is_file) {
+ new_path = base_dir.plus_file(new_name);
+ } else {
+ new_path = base_dir.substr(0, base_dir.find_last("/")) + "/" + new_name;
}
//Present a more user friendly warning for name conflict
@@ -945,7 +997,7 @@ void FileSystemDock::_duplicate_operation_confirm() {
}
memdelete(da);
- _try_duplicate_item(to_duplicate, new_name);
+ _try_duplicate_item(to_duplicate, new_path);
//Rescan everything
print_line("call rescan!");
@@ -962,6 +1014,8 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path) {
}
_update_dependencies_after_move(renames);
+ _update_resource_paths_after_move(renames);
+
print_line("call rescan!");
_rescan();
}