diff options
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 81 |
1 files changed, 54 insertions, 27 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 5409ef65ea..5041441ac3 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 */ @@ -36,8 +36,12 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/project_settings.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 "scene/main/viewport.h" #include "scene/resources/packed_scene.h" @@ -52,7 +56,7 @@ Ref<Texture> FileSystemDock::_get_tree_item_icon(EditorFileSystemDirectory *p_di return file_icon; } -bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites) { +bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites, bool p_unfold_path) { bool parent_should_expand = false; // Create a tree item for the subdirectory. @@ -71,17 +75,22 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory subdirectory_item->select(0); } - subdirectory_item->set_collapsed(uncollapsed_paths.find(lpath) < 0); + if (p_unfold_path && path.begins_with(lpath) && path != lpath) { + subdirectory_item->set_collapsed(false); + } else { + subdirectory_item->set_collapsed(uncollapsed_paths.find(lpath) < 0); + } if (searched_string.length() > 0 && dname.to_lower().find(searched_string) >= 0) { parent_should_expand = true; } // Create items for all subdirectories. for (int i = 0; i < p_dir->get_subdir_count(); i++) - parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites) || parent_should_expand); + parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites, p_unfold_path) || parent_should_expand); // Create all items for the files in the subdirectory. if (display_mode == DISPLAY_MODE_TREE_ONLY) { + String main_scene = ProjectSettings::get_singleton()->get("application/run/main_scene"); for (int i = 0; i < p_dir->get_file_count(); i++) { String file_type = p_dir->get_file_type(i); @@ -111,7 +120,6 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory file_item->select(0); file_item->set_as_cursor(0); } - String main_scene = ProjectSettings::get_singleton()->get("application/run/main_scene"); if (main_scene == file_metadata) { file_item->set_custom_color(0, get_color("accent_color", "Editor")); } @@ -120,6 +128,11 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory udata.push_back(file_item); EditorResourcePreview::get_singleton()->queue_resource_preview(file_metadata, this, "_tree_thumbnail_done", udata); } + } else if (display_mode == DISPLAY_MODE_SPLIT) { + if (lpath.get_base_dir() == path.get_base_dir()) { + subdirectory_item->select(0); + subdirectory_item->set_as_cursor(0); + } } if (searched_string.length() > 0) { @@ -127,6 +140,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory subdirectory_item->set_collapsed(false); } else if (dname != "res://") { subdirectory_item->get_parent()->remove_child(subdirectory_item); + memdelete(subdirectory_item); } } @@ -164,7 +178,7 @@ Vector<String> FileSystemDock::_compute_uncollapsed_paths() { return uncollapsed_paths; } -void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, bool p_uncollapse_root, bool p_select_in_favorites) { +void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, bool p_uncollapse_root, bool p_select_in_favorites, bool p_unfold_path) { // Recreate the tree. tree->clear(); tree_update_id++; @@ -237,7 +251,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo } // Create the remaining of the tree. - _create_tree(root, EditorFileSystem::get_singleton()->get_filesystem(), uncollapsed_paths, p_select_in_favorites); + _create_tree(root, EditorFileSystem::get_singleton()->get_filesystem(), uncollapsed_paths, p_select_in_favorites, p_unfold_path); tree->ensure_cursor_is_visible(); updating_tree = false; } @@ -459,7 +473,7 @@ void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_fa _set_current_path_text(path); _push_to_history(); - _update_tree(_compute_uncollapsed_paths(), false, p_select_in_favorites); + _update_tree(_compute_uncollapsed_paths(), false, p_select_in_favorites, true); if (display_mode == DISPLAY_MODE_SPLIT) { _update_file_list(false); files->get_v_scroll()->set_value(0); @@ -737,6 +751,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } // Fills the ItemList control node from the FileInfos. + String main_scene = ProjectSettings::get_singleton()->get("application/run/main_scene"); String oi = "Object"; for (List<FileInfo>::Element *E = filelist.front(); E; E = E->next()) { FileInfo *finfo = &(E->get()); @@ -773,6 +788,10 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->set_item_metadata(item_index, fpath); } + if (fpath == main_scene) { + files->set_item_custom_fg_color(item_index, get_color("accent_color", "Editor")); + } + // Generate the preview. if (!finfo->import_broken) { Array udata; @@ -1394,17 +1413,13 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overw if (!can_move) { // Ask to do something. overwrite_dialog->popup_centered_minsize(); - overwrite_dialog->grab_focus(); return; } } // Check groups. for (int i = 0; i < to_move.size(); i++) { - - print_line("is group: " + to_move[i].path + ": " + itos(EditorFileSystem::get_singleton()->is_group_file(to_move[i].path))); if (to_move[i].is_file && EditorFileSystem::get_singleton()->is_group_file(to_move[i].path)) { - print_line("move to: " + p_to_path.plus_file(to_move[i].path.get_file())); EditorFileSystem::get_singleton()->move_group_file(to_move[i].path, p_to_path.plus_file(to_move[i].path.get_file())); } } @@ -1423,7 +1438,7 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overw if (is_moved) { int current_tab = editor->get_current_tab(); - _save_scenes_after_move(file_renames); //save scenes before updating + _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); @@ -1571,6 +1586,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected ProjectSettings::get_singleton()->set("application/run/main_scene", p_selected[0]); ProjectSettings::get_singleton()->save(); _update_tree(_compute_uncollapsed_paths()); + _update_file_list(true); } } break; @@ -1742,8 +1758,8 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected if (!fpath.ends_with("/")) { fpath = fpath.get_base_dir(); } - make_script_dialog_text->config("Node", fpath.plus_file("new_script.gd"), false); - make_script_dialog_text->popup_centered(Size2(300, 300) * EDSCALE); + make_script_dialog->config("Node", fpath.plus_file("new_script.gd"), false, false); + make_script_dialog->popup_centered(); } break; case FILE_COPY_PATH: { @@ -1780,7 +1796,7 @@ void FileSystemDock::_resource_created() const { } void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) { - if (searched_string.length() == 0 && p_text.length() > 0) { + if (searched_string.length() == 0) { // Register the uncollapsed paths before they change. uncollapsed_paths_before_search = _compute_uncollapsed_paths(); } @@ -1792,13 +1808,14 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from else // File_list_search_box. tree_search_box->set_text(searched_string); + bool unfold_path = (p_text == String() && path != String()); switch (display_mode) { case DISPLAY_MODE_TREE_ONLY: { - _update_tree(searched_string.length() == 0 ? uncollapsed_paths_before_search : Vector<String>()); + _update_tree(searched_string.length() == 0 ? uncollapsed_paths_before_search : Vector<String>(), false, false, unfold_path); } break; case DISPLAY_MODE_SPLIT: { _update_file_list(false); - _update_tree(searched_string.length() == 0 ? uncollapsed_paths_before_search : Vector<String>()); + _update_tree(searched_string.length() == 0 ? uncollapsed_paths_before_search : Vector<String>(), false, false, unfold_path); } break; } } @@ -1927,7 +1944,7 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da return false; // Attempting to move a folder into itself will fail later, - // rather than bring up a message don't try to do it in the first place + // rather than bring up a message don't try to do it in the first place. to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/"); Vector<String> fnames = drag_data["files"]; for (int i = 0; i < fnames.size(); ++i) { @@ -2029,11 +2046,15 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Vector<String> fnames = drag_data["files"]; to_move.clear(); for (int i = 0; i < fnames.size(); i++) { - to_move.push_back(FileOrFolder(fnames[i], !fnames[i].ends_with("/"))); + if (fnames[i].get_base_dir() != to_dir) { + to_move.push_back(FileOrFolder(fnames[i], !fnames[i].ends_with("/"))); + } + } + if (!to_move.empty()) { + _move_operation_confirm(to_dir); } - _move_operation_confirm(to_dir); } else if (favorite) { - // Add the files from favorites + // Add the files from favorites. Vector<String> fnames = drag_data["files"]; Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < fnames.size(); i++) { @@ -2082,6 +2103,10 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori // We drop on a folder. target = fpath; return; + } else { + // We drop on the folder that the target file is in. + target = fpath.get_base_dir(); + return; } } else { if (ti->get_parent() != tree->get_root()->get_children()) { @@ -2147,7 +2172,9 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str if (filenames.size() == 1) { p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open Scene"), FILE_OPEN); p_popup->add_icon_item(get_icon("CreateNewSceneFrom", "EditorIcons"), TTR("New Inherited Scene"), FILE_INHERIT); - p_popup->add_item(TTR("Set As Main Scene"), FILE_MAIN_SCENE); + if (ProjectSettings::get_singleton()->get("application/run/main_scene") != filenames[0]) { + p_popup->add_icon_item(get_icon("PlayScene", "EditorIcons"), TTR("Set As Main Scene"), FILE_MAIN_SCENE); + } } else { p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open Scenes"), FILE_OPEN); } @@ -2675,9 +2702,9 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { make_scene_dialog->register_text_enter(make_scene_dialog_text); make_scene_dialog->connect("confirmed", this, "_make_scene_confirm"); - make_script_dialog_text = memnew(ScriptCreateDialog); - make_script_dialog_text->set_title(TTR("Create Script")); - add_child(make_script_dialog_text); + make_script_dialog = memnew(ScriptCreateDialog); + make_script_dialog->set_title(TTR("Create Script")); + add_child(make_script_dialog); new_resource_dialog = memnew(CreateDialog); add_child(new_resource_dialog); |