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.cpp199
1 files changed, 173 insertions, 26 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 2d65d73f21..e8a2a46dd2 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -37,16 +37,18 @@
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/templates/list.h"
-#include "editor_feature_profile.h"
-#include "editor_node.h"
-#include "editor_resource_preview.h"
-#include "editor_scale.h"
-#include "editor_settings.h"
-#include "import_dock.h"
+#include "editor/editor_feature_profile.h"
+#include "editor/editor_node.h"
+#include "editor/editor_resource_preview.h"
+#include "editor/editor_scale.h"
+#include "editor/editor_settings.h"
+#include "editor/import_dock.h"
+#include "editor/scene_tree_dock.h"
+#include "editor/shader_create_dialog.h"
+#include "scene/gui/label.h"
#include "scene/main/window.h"
#include "scene/resources/packed_scene.h"
#include "servers/display_server.h"
-#include "shader_create_dialog.h"
FileSystemDock *FileSystemDock::singleton = nullptr;
@@ -394,12 +396,25 @@ void FileSystemDock::_notification(int p_what) {
}
} else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) {
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN);
+ } else if ((String(dd["type"]) == "nodes")) {
+ holding_branch = true;
+ TreeItem *item = tree->get_next_selected(tree->get_root());
+ while (item) {
+ tree_items_selected_on_drag_begin.push_back(item);
+ item = tree->get_next_selected(item);
+ }
+ list_items_selected_on_drag_begin = files->get_selected_items();
}
}
} break;
case NOTIFICATION_DRAG_END: {
tree->set_drop_mode_flags(0);
+
+ if (holding_branch) {
+ holding_branch = false;
+ _reselect_items_selected_on_drag_begin(true);
+ }
} break;
case NOTIFICATION_THEME_CHANGED: {
@@ -510,7 +525,7 @@ void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_fa
if (target_path.ends_with("/")) {
target_path = target_path.substr(0, target_path.length() - 1);
}
- DirAccess *dirAccess = DirAccess::open("res://");
+ DirAccess *dirAccess = DirAccess::create(DirAccess::ACCESS_RESOURCES);
if (dirAccess->file_exists(p_path)) {
path = target_path;
} else if (dirAccess->dir_exists(p_path)) {
@@ -975,10 +990,10 @@ void FileSystemDock::_select_file(const String &p_path, bool p_select_in_favorit
if (is_imported) {
ResourceImporterScene::get_singleton()->show_advanced_options(fpath);
} else {
- editor->open_request(fpath);
+ EditorNode::get_singleton()->open_request(fpath);
}
} else {
- editor->load_resource(fpath);
+ EditorNode::get_singleton()->load_resource(fpath);
}
}
_navigate_to_path(fpath, p_select_in_favorites);
@@ -1171,12 +1186,12 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_
// Update scene if it is open.
for (int i = 0; i < file_changed_paths.size(); ++i) {
String new_item_path = p_item.is_file ? new_path : file_changed_paths[i].replace_first(old_path, new_path);
- if (ResourceLoader::get_resource_type(new_item_path) == "PackedScene" && editor->is_scene_open(file_changed_paths[i])) {
- EditorData *ed = &editor->get_editor_data();
+ if (ResourceLoader::get_resource_type(new_item_path) == "PackedScene" && EditorNode::get_singleton()->is_scene_open(file_changed_paths[i])) {
+ EditorData *ed = &EditorNode::get_singleton()->get_editor_data();
for (int j = 0; j < ed->get_edited_scene_count(); j++) {
if (ed->get_scene_path(j) == file_changed_paths[i]) {
ed->get_edited_scene_root(j)->set_scene_file_path(new_item_path);
- editor->save_layout();
+ EditorNode::get_singleton()->save_layout();
break;
}
}
@@ -1225,6 +1240,30 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin
if (err != OK) {
EditorNode::get_singleton()->add_io_error(TTR("Error duplicating:") + "\n" + old_path + ".import\n");
}
+
+ // Remove uid from .import file to avoid conflict.
+ Ref<ConfigFile> cfg;
+ cfg.instantiate();
+ cfg->load(new_path + ".import");
+ cfg->erase_section_key("remap", "uid");
+ cfg->save(new_path + ".import");
+ } else if (p_item.is_file && (old_path.get_extension() == "tscn" || old_path.get_extension() == "tres")) {
+ // FIXME: Quick hack to fix text resources. This should be fixed properly.
+ FileAccessRef file = FileAccess::open(old_path, FileAccess::READ, &err);
+ if (err == OK) {
+ PackedStringArray lines = file->get_as_utf8_string().split("\n");
+ String line = lines[0];
+
+ if (line.contains("uid")) {
+ line = line.substr(0, line.find(" uid")) + "]";
+ lines.write[0] = line;
+
+ FileAccessRef file2 = FileAccess::open(new_path, FileAccess::WRITE, &err);
+ if (err == OK) {
+ file2->store_string(String("\n").join(lines));
+ }
+ }
+ }
}
} else {
EditorNode::get_singleton()->add_io_error(TTR("Error duplicating:") + "\n" + old_path + "\n");
@@ -1290,7 +1329,7 @@ void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &
Error err = ResourceLoader::rename_dependencies(file, p_renames);
if (err == OK) {
if (ResourceLoader::get_resource_type(file) == "PackedScene") {
- editor->reload_scene(file);
+ EditorNode::get_singleton()->reload_scene(file);
}
} else {
EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + remaps[i] + "\n");
@@ -1359,7 +1398,7 @@ void FileSystemDock::_save_scenes_after_move(const Map<String, String> &p_rename
}
}
- editor->save_scene_list(new_filenames);
+ EditorNode::get_singleton()->save_scene_list(new_filenames);
}
void FileSystemDock::_make_dir_confirm() {
@@ -1433,8 +1472,8 @@ void FileSystemDock::_make_scene_confirm() {
}
memdelete(da);
- int idx = editor->new_scene();
- editor->get_editor_data().set_scene_path(idx, scene_name);
+ int idx = EditorNode::get_singleton()->new_scene();
+ EditorNode::get_singleton()->get_editor_data().set_scene_path(idx, scene_name);
}
void FileSystemDock::_file_removed(String p_file) {
@@ -1511,14 +1550,14 @@ void FileSystemDock::_rename_operation_confirm() {
Map<String, String> folder_renames;
_try_move_item(to_rename, new_path, file_renames, folder_renames);
- int current_tab = editor->get_current_tab();
+ int current_tab = EditorNode::get_singleton()->get_current_tab();
_save_scenes_after_move(file_renames); // save scenes before updating
_update_dependencies_after_move(file_renames);
_update_resource_paths_after_move(file_renames);
_update_project_settings_after_move(file_renames);
_update_favorites_list_after_move(file_renames, folder_renames);
- editor->set_current_tab(current_tab);
+ EditorNode::get_singleton()->set_current_tab(current_tab);
print_verbose("FileSystem: calling rescan.");
_rescan();
@@ -1622,14 +1661,14 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_ove
}
if (is_moved) {
- int current_tab = editor->get_current_tab();
+ int current_tab = EditorNode::get_singleton()->get_current_tab();
_save_scenes_after_move(file_renames); // Save scenes before updating.
_update_dependencies_after_move(file_renames);
_update_resource_paths_after_move(file_renames);
_update_project_settings_after_move(file_renames);
_update_favorites_list_after_move(file_renames, folder_renames);
- editor->set_current_tab(current_tab);
+ EditorNode::get_singleton()->set_current_tab(current_tab);
print_verbose("FileSystem: calling rescan.");
_rescan();
@@ -2001,8 +2040,8 @@ void FileSystemDock::_resource_created() {
memdelete(node);
}
- editor->push_item(r);
- editor->save_resource_as(RES(r), fpath);
+ EditorNode::get_singleton()->push_item(r);
+ EditorNode::get_singleton()->save_resource_as(RES(r), fpath);
}
void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) {
@@ -2621,8 +2660,79 @@ void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) {
call_deferred(SNAME("_update_import_dock"));
}
+void FileSystemDock::_tree_mouse_exited() {
+ if (holding_branch) {
+ _reselect_items_selected_on_drag_begin();
+ }
+}
+
+void FileSystemDock::_reselect_items_selected_on_drag_begin(bool reset) {
+ TreeItem *selected_item = tree->get_next_selected(tree->get_root());
+ if (selected_item) {
+ selected_item->deselect(0);
+ }
+ if (!tree_items_selected_on_drag_begin.is_empty()) {
+ bool reselected = false;
+ for (TreeItem *item : tree_items_selected_on_drag_begin) {
+ if (item->get_tree()) {
+ item->select(0);
+ reselected = true;
+ }
+ }
+
+ if (reset) {
+ tree_items_selected_on_drag_begin.clear();
+ }
+
+ if (!reselected) {
+ // If couldn't reselect the items selected on drag begin, select the "res://" item.
+ tree->get_root()->get_child(1)->select(0);
+ }
+ }
+
+ files->deselect_all();
+ if (!list_items_selected_on_drag_begin.is_empty()) {
+ for (const int idx : list_items_selected_on_drag_begin) {
+ files->select(idx, false);
+ }
+
+ if (reset) {
+ list_items_selected_on_drag_begin.clear();
+ }
+ }
+}
+
void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventKey> key = p_event;
+
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (mm.is_valid()) {
+ TreeItem *item = tree->get_item_at_position(mm->get_position());
+ if (item && holding_branch) {
+ String fpath = item->get_metadata(0);
+ while (!fpath.ends_with("/") && fpath != "res://" && item->get_parent()) { // Find the parent folder tree item.
+ item = item->get_parent();
+ fpath = item->get_metadata(0);
+ }
+
+ TreeItem *deselect_item = tree->get_next_selected(tree->get_root());
+ while (deselect_item) {
+ deselect_item->deselect(0);
+ deselect_item = tree->get_next_selected(deselect_item);
+ }
+ item->select(0);
+
+ if (display_mode == DisplayMode::DISPLAY_MODE_SPLIT) {
+ files->deselect_all();
+ // Try to select the corresponding file list item.
+ const int files_item_idx = files->find_metadata(fpath);
+ if (files_item_idx != -1) {
+ files->select(files_item_idx);
+ }
+ }
+ }
+ }
+
if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
if (ED_IS_SHORTCUT("filesystem_dock/duplicate", p_event)) {
_tree_rmb_option(FILE_DUPLICATE);
@@ -2643,6 +2753,43 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
}
void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (mm.is_valid() && holding_branch) {
+ const int item_idx = files->get_item_at_position(mm->get_position());
+ if (item_idx != -1) {
+ files->deselect_all();
+ String fpath = files->get_item_metadata(item_idx);
+ if (fpath.ends_with("/") || fpath == "res://") {
+ files->select(item_idx);
+ }
+
+ TreeItem *deselect_item = tree->get_next_selected(tree->get_root());
+ while (deselect_item) {
+ deselect_item->deselect(0);
+ deselect_item = tree->get_next_selected(deselect_item);
+ }
+
+ // Try to select the corresponding tree item.
+ TreeItem *tree_item = tree->get_item_with_text(files->get_item_text(item_idx));
+ if (tree_item) {
+ tree_item->select(0);
+ } else {
+ // Find parent folder.
+ fpath = fpath.substr(0, fpath.rfind("/") + 1);
+ if (fpath.size() > String("res://").size()) {
+ fpath = fpath.left(fpath.size() - 2); // Remove last '/'.
+ const int slash_idx = fpath.rfind("/");
+ fpath = fpath.substr(slash_idx + 1, fpath.size() - slash_idx - 1);
+ }
+
+ tree_item = tree->get_item_with_text(fpath);
+ if (tree_item) {
+ tree_item->select(0);
+ }
+ }
+ }
+ }
+
Ref<InputEventKey> key = p_event;
if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
if (ED_IS_SHORTCUT("filesystem_dock/duplicate", p_event)) {
@@ -2812,10 +2959,9 @@ void FileSystemDock::_bind_methods() {
ADD_SIGNAL(MethodInfo("display_mode_changed"));
}
-FileSystemDock::FileSystemDock(EditorNode *p_editor) {
+FileSystemDock::FileSystemDock() {
singleton = this;
set_name("FileSystem");
- editor = p_editor;
path = "res://";
// `KeyModifierMask::CMD | Key::C` conflicts with other editor shortcuts.
@@ -2907,6 +3053,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
tree->connect("empty_rmb", callable_mp(this, &FileSystemDock::_tree_rmb_empty));
tree->connect("nothing_selected", callable_mp(this, &FileSystemDock::_tree_empty_selected));
tree->connect("gui_input", callable_mp(this, &FileSystemDock::_tree_gui_input));
+ tree->connect("mouse_exited", callable_mp(this, &FileSystemDock::_tree_mouse_exited));
file_list_vb = memnew(VBoxContainer);
file_list_vb->set_v_size_flags(SIZE_EXPAND_FILL);
@@ -2955,7 +3102,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
deps_editor = memnew(DependencyEditor);
add_child(deps_editor);
- owners_editor = memnew(DependencyEditorOwners(editor));
+ owners_editor = memnew(DependencyEditorOwners());
add_child(owners_editor);
remove_dialog = memnew(DependencyRemoveDialog);