diff options
Diffstat (limited to 'editor/dependency_editor.cpp')
-rw-r--r-- | editor/dependency_editor.cpp | 168 |
1 files changed, 63 insertions, 105 deletions
diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index df957611cf..cbf39c209a 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -37,7 +37,6 @@ #include "scene/gui/margin_container.h" void DependencyEditor::_searched(const String &p_path) { - Map<String, String> dep_rename; dep_rename[replacing] = p_path; @@ -48,7 +47,6 @@ void DependencyEditor::_searched(const String &p_path) { } void DependencyEditor::_load_pressed(Object *p_item, int p_cell, int p_button) { - TreeItem *ti = Object::cast_to<TreeItem>(p_item); replacing = ti->get_text(1); @@ -60,25 +58,23 @@ void DependencyEditor::_load_pressed(Object *p_item, int p_cell, int p_button) { for (List<String>::Element *E = ext.front(); E; E = E->next()) { search->add_filter("*" + E->get()); } - search->popup_centered_ratio(0.65); // So it doesn't completely cover the dialog below it. + search->popup_file_dialog(); } -void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String, Map<String, String> > &candidates) { - +void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String, Map<String, String>> &candidates) { for (int i = 0; i < efsd->get_subdir_count(); i++) { _fix_and_find(efsd->get_subdir(i), candidates); } for (int i = 0; i < efsd->get_file_count(); i++) { - String file = efsd->get_file(i); - if (!candidates.has(file)) + if (!candidates.has(file)) { continue; + } String path = efsd->get_file_path(i); for (Map<String, String>::Element *E = candidates[file].front(); E; E = E->next()) { - if (E->get() == String()) { E->get() = path; continue; @@ -100,7 +96,6 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String int current_score = 0; for (int j = 0; j < lostv.size(); j++) { - if (j < existingv.size() && lostv[j] == existingv[j]) { existing_score++; } @@ -110,7 +105,6 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String } if (current_score > existing_score) { - //if it was the same, could track distance to new path but.. E->get() = path; //replace by more accurate @@ -120,14 +114,13 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String } void DependencyEditor::_fix_all() { - - if (!EditorFileSystem::get_singleton()->get_filesystem()) + if (!EditorFileSystem::get_singleton()->get_filesystem()) { return; + } - Map<String, Map<String, String> > candidates; + Map<String, Map<String, String>> candidates; for (List<String>::Element *E = missing.front(); E; E = E->next()) { - String base = E->get().get_file(); if (!candidates.has(base)) { candidates[base] = Map<String, String>(); @@ -140,10 +133,8 @@ void DependencyEditor::_fix_all() { Map<String, String> remaps; - for (Map<String, Map<String, String> >::Element *E = candidates.front(); E; E = E->next()) { - + for (Map<String, Map<String, String>>::Element *E = candidates.front(); E; E = E->next()) { for (Map<String, String>::Element *F = E->get().front(); F; F = F->next()) { - if (F->get() != String()) { remaps[F->key()] = F->get(); } @@ -151,7 +142,6 @@ void DependencyEditor::_fix_all() { } if (remaps.size()) { - ResourceLoader::rename_dependencies(editing, remaps); _update_list(); @@ -160,12 +150,10 @@ void DependencyEditor::_fix_all() { } void DependencyEditor::_update_file() { - EditorFileSystem::get_singleton()->update_file(editing); } void DependencyEditor::_update_list() { - List<String> deps; ResourceLoader::get_dependencies(editing, &deps, true); @@ -174,12 +162,11 @@ void DependencyEditor::_update_list() { TreeItem *root = tree->create_item(); - Ref<Texture> folder = get_icon("folder", "FileDialog"); + Ref<Texture2D> folder = tree->get_theme_icon("folder", "FileDialog"); bool broken = false; for (List<String>::Element *E = deps.front(); E; E = E->next()) { - TreeItem *item = tree->create_item(root); String n = E->get(); @@ -195,7 +182,7 @@ void DependencyEditor::_update_list() { } String name = path.get_file(); - Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type); item->set_text(0, name); item->set_icon(0, icon); item->set_metadata(0, type); @@ -214,12 +201,11 @@ void DependencyEditor::_update_list() { } void DependencyEditor::edit(const String &p_path) { - editing = p_path; set_title(TTR("Dependencies For:") + " " + p_path.get_file()); _update_list(); - popup_centered_ratio(0.7); // So it doesn't completely cover the dialog below it. + popup_centered_ratio(0.4); if (EditorNode::get_singleton()->is_scene_open(p_path)) { EditorNode::get_singleton()->show_warning(vformat(TTR("Scene '%s' is currently being edited.\nChanges will only take effect when reloaded."), p_path.get_file())); @@ -229,14 +215,9 @@ void DependencyEditor::edit(const String &p_path) { } void DependencyEditor::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_searched"), &DependencyEditor::_searched); - ClassDB::bind_method(D_METHOD("_load_pressed"), &DependencyEditor::_load_pressed); - ClassDB::bind_method(D_METHOD("_fix_all"), &DependencyEditor::_fix_all); } DependencyEditor::DependencyEditor() { - VBoxContainer *vb = memnew(VBoxContainer); vb->set_name(TTR("Dependencies")); add_child(vb); @@ -247,7 +228,7 @@ DependencyEditor::DependencyEditor() { tree->set_column_title(0, TTR("Resource")); tree->set_column_title(1, TTR("Path")); tree->set_hide_root(true); - tree->connect("button_pressed", this, "_load_pressed"); + tree->connect("button_pressed", callable_mp(this, &DependencyEditor::_load_pressed)); HBoxContainer *hbc = memnew(HBoxContainer); Label *label = memnew(Label(TTR("Dependencies:"))); @@ -255,27 +236,26 @@ DependencyEditor::DependencyEditor() { hbc->add_spacer(); fixdeps = memnew(Button(TTR("Fix Broken"))); hbc->add_child(fixdeps); - fixdeps->connect("pressed", this, "_fix_all"); + fixdeps->connect("pressed", callable_mp(this, &DependencyEditor::_fix_all)); vb->add_child(hbc); MarginContainer *mc = memnew(MarginContainer); - mc->set_v_size_flags(SIZE_EXPAND_FILL); + mc->set_v_size_flags(Control::SIZE_EXPAND_FILL); mc->add_child(tree); vb->add_child(mc); set_title(TTR("Dependency Editor")); search = memnew(EditorFileDialog); - search->connect("file_selected", this, "_searched"); - search->set_mode(EditorFileDialog::MODE_OPEN_FILE); + search->connect("file_selected", callable_mp(this, &DependencyEditor::_searched)); + search->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); search->set_title(TTR("Search Replacement Resource:")); add_child(search); } ///////////////////////////////////// void DependencyEditorOwners::_list_rmb_select(int p_item, const Vector2 &p_pos) { - file_options->clear(); file_options->set_size(Size2(1, 1)); if (p_item >= 0) { @@ -287,7 +267,6 @@ void DependencyEditorOwners::_list_rmb_select(int p_item, const Vector2 &p_pos) } void DependencyEditorOwners::_select_file(int p_idx) { - String fpath = owners->get_item_text(p_idx); if (ResourceLoader::get_resource_type(fpath) == "PackedScene") { @@ -298,35 +277,30 @@ void DependencyEditorOwners::_select_file(int p_idx) { } void DependencyEditorOwners::_file_option(int p_option) { - switch (p_option) { case FILE_OPEN: { int idx = owners->get_current(); - if (idx < 0 || idx >= owners->get_item_count()) + if (idx < 0 || idx >= owners->get_item_count()) { break; + } _select_file(idx); } break; } } void DependencyEditorOwners::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_list_rmb_select"), &DependencyEditorOwners::_list_rmb_select); - ClassDB::bind_method(D_METHOD("_file_option"), &DependencyEditorOwners::_file_option); - ClassDB::bind_method(D_METHOD("_select_file"), &DependencyEditorOwners::_select_file); } void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) { - - if (!efsd) + if (!efsd) { return; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { _fill_owners(efsd->get_subdir(i)); } for (int i = 0; i < efsd->get_file_count(); i++) { - Vector<String> deps = efsd->get_file_deps(i); bool found = false; for (int j = 0; j < deps.size(); j++) { @@ -335,37 +309,36 @@ void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) { break; } } - if (!found) + if (!found) { continue; + } - Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(efsd->get_file_type(i)); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(efsd->get_file_type(i)); owners->add_item(efsd->get_file_path(i), icon); } } void DependencyEditorOwners::show(const String &p_path) { - editing = p_path; owners->clear(); _fill_owners(EditorFileSystem::get_singleton()->get_filesystem()); - popup_centered_ratio(); + popup_centered_ratio(0.3); set_title(TTR("Owners Of:") + " " + p_path.get_file()); } DependencyEditorOwners::DependencyEditorOwners(EditorNode *p_editor) { - editor = p_editor; file_options = memnew(PopupMenu); add_child(file_options); - file_options->connect("id_pressed", this, "_file_option"); + file_options->connect("id_pressed", callable_mp(this, &DependencyEditorOwners::_file_option)); owners = memnew(ItemList); owners->set_select_mode(ItemList::SELECT_SINGLE); - owners->connect("item_rmb_selected", this, "_list_rmb_select"); - owners->connect("item_activated", this, "_select_file"); + owners->connect("item_rmb_selected", callable_mp(this, &DependencyEditorOwners::_list_rmb_select)); + owners->connect("item_activated", callable_mp(this, &DependencyEditorOwners::_select_file)); owners->set_allow_rmb_select(true); add_child(owners); } @@ -373,8 +346,9 @@ DependencyEditorOwners::DependencyEditorOwners(EditorNode *p_editor) { /////////////////////// void DependencyRemoveDialog::_find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder) { - if (!efsd) + if (!efsd) { return; + } for (int i = 0; i < efsd->get_subdir_count(); ++i) { _find_files_in_removed_folder(efsd->get_subdir(i), p_folder); @@ -387,8 +361,9 @@ void DependencyRemoveDialog::_find_files_in_removed_folder(EditorFileSystemDirec } void DependencyRemoveDialog::_find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed) { - if (!efsd) + if (!efsd) { return; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { _find_all_removed_dependencies(efsd->get_subdir(i), p_removed); @@ -398,8 +373,9 @@ void DependencyRemoveDialog::_find_all_removed_dependencies(EditorFileSystemDire const String path = efsd->get_file_path(i); //It doesn't matter if a file we are about to delete will have some of its dependencies removed too - if (all_remove_files.has(path)) + if (all_remove_files.has(path)) { continue; + } Vector<String> all_deps = efsd->get_file_deps(i); for (int j = 0; j < all_deps.size(); ++j) { @@ -430,23 +406,23 @@ void DependencyRemoveDialog::_build_removed_dependency_tree(const Vector<Removed if (!tree_items.has(rd.dependency_folder)) { TreeItem *folder_item = owners->create_item(owners->get_root()); folder_item->set_text(0, rd.dependency_folder); - folder_item->set_icon(0, get_icon("Folder", "EditorIcons")); + folder_item->set_icon(0, owners->get_theme_icon("Folder", "EditorIcons")); tree_items[rd.dependency_folder] = folder_item; } TreeItem *dependency_item = owners->create_item(tree_items[rd.dependency_folder]); dependency_item->set_text(0, rd.dependency); - dependency_item->set_icon(0, get_icon("Warning", "EditorIcons")); + dependency_item->set_icon(0, owners->get_theme_icon("Warning", "EditorIcons")); tree_items[rd.dependency] = dependency_item; } else { TreeItem *dependency_item = owners->create_item(owners->get_root()); dependency_item->set_text(0, rd.dependency); - dependency_item->set_icon(0, get_icon("Warning", "EditorIcons")); + dependency_item->set_icon(0, owners->get_theme_icon("Warning", "EditorIcons")); tree_items[rd.dependency] = dependency_item; } } //List this file under this dependency - Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(rd.file_type); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(rd.file_type); TreeItem *file_item = owners->create_item(tree_items[rd.dependency]); file_item->set_text(0, rd.file); file_item->set_icon(0, icon); @@ -487,7 +463,6 @@ void DependencyRemoveDialog::show(const Vector<String> &p_folders, const Vector< } void DependencyRemoveDialog::ok_pressed() { - for (int i = 0; i < files_to_delete.size(); ++i) { if (ResourceCache::has(files_to_delete[i])) { Resource *res = ResourceCache::get(files_to_delete[i]); @@ -533,10 +508,10 @@ void DependencyRemoveDialog::ok_pressed() { if (dirs_to_delete.size() == 0) { // If we only deleted files we should only need to tell the file system about the files we touched. - for (int i = 0; i < files_to_delete.size(); ++i) + for (int i = 0; i < files_to_delete.size(); ++i) { EditorFileSystem::get_singleton()->update_file(files_to_delete[i]); + } } else { - for (int i = 0; i < dirs_to_delete.size(); ++i) { String path = OS::get_singleton()->get_resource_dir() + dirs_to_delete[i].replace_first("res://", "/"); print_verbose("Moving to trash: " + path); @@ -557,11 +532,13 @@ void DependencyRemoveDialog::ok_pressed() { for (int i = 0; i < previous_favorites.size(); ++i) { if (previous_favorites[i].ends_with("/")) { - if (dirs_to_delete.find(previous_favorites[i]) < 0) + if (dirs_to_delete.find(previous_favorites[i]) < 0) { new_favorites.push_back(previous_favorites[i]); + } } else { - if (files_to_delete.find(previous_favorites[i]) < 0) + if (files_to_delete.find(previous_favorites[i]) < 0) { new_favorites.push_back(previous_favorites[i]); + } } } @@ -576,7 +553,6 @@ void DependencyRemoveDialog::_bind_methods() { } DependencyRemoveDialog::DependencyRemoveDialog() { - get_ok()->set_text(TTR("Remove")); VBoxContainer *vb = memnew(VBoxContainer); @@ -588,28 +564,27 @@ DependencyRemoveDialog::DependencyRemoveDialog() { owners = memnew(Tree); owners->set_hide_root(true); vb->add_child(owners); - owners->set_v_size_flags(SIZE_EXPAND_FILL); + owners->set_v_size_flags(Control::SIZE_EXPAND_FILL); } ////////////// void DependencyErrorDialog::show(Mode p_mode, const String &p_for_file, const Vector<String> &report) { - mode = p_mode; for_file = p_for_file; set_title(TTR("Error loading:") + " " + p_for_file.get_file()); files->clear(); - TreeItem *root = files->create_item(NULL); + TreeItem *root = files->create_item(nullptr); for (int i = 0; i < report.size(); i++) { - String dep; String type = "Object"; dep = report[i].get_slice("::", 0); - if (report[i].get_slice_count("::") > 0) + if (report[i].get_slice_count("::") > 0) { type = report[i].get_slice("::", 1); + } - Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type); TreeItem *ti = files->create_item(root); ti->set_text(0, dep); @@ -620,7 +595,6 @@ void DependencyErrorDialog::show(Mode p_mode, const String &p_for_file, const Ve } void DependencyErrorDialog::ok_pressed() { - switch (mode) { case MODE_SCENE: EditorNode::get_singleton()->load_scene(for_file, true); @@ -632,21 +606,19 @@ void DependencyErrorDialog::ok_pressed() { } void DependencyErrorDialog::custom_action(const String &) { - EditorNode::get_singleton()->fix_dependencies(for_file); } DependencyErrorDialog::DependencyErrorDialog() { - VBoxContainer *vb = memnew(VBoxContainer); add_child(vb); files = memnew(Tree); files->set_hide_root(true); vb->add_margin_child(TTR("Load failed due to missing dependencies:"), files, true); - files->set_v_size_flags(SIZE_EXPAND_FILL); + files->set_v_size_flags(Control::SIZE_EXPAND_FILL); - set_custom_minimum_size(Size2(500, 220) * EDSCALE); + set_min_size(Size2(500, 220) * EDSCALE); get_ok()->set_text(TTR("Open Anyway")); get_cancel()->set_text(TTR("Close")); @@ -662,31 +634,30 @@ DependencyErrorDialog::DependencyErrorDialog() { ////////////////////////////////////////////////////////////////////// void OrphanResourcesDialog::ok_pressed() { - paths.clear(); _find_to_delete(files->get_root(), paths); - if (paths.empty()) + if (paths.empty()) { return; + } delete_confirm->set_text(vformat(TTR("Permanently delete %d item(s)? (No undo!)"), paths.size())); - delete_confirm->popup_centered_clamped(delete_confirm->get_minimum_size()); + delete_confirm->popup_centered(); } bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent) { - - if (!efsd) + if (!efsd) { return false; + } bool has_children = false; for (int i = 0; i < efsd->get_subdir_count(); i++) { - - TreeItem *dir_item = NULL; + TreeItem *dir_item = nullptr; if (p_parent) { dir_item = files->create_item(p_parent); dir_item->set_text(0, efsd->get_subdir(i)->get_name()); - dir_item->set_icon(0, get_icon("folder", "FileDialog")); + dir_item->set_icon(0, files->get_theme_icon("folder", "FileDialog")); } bool children = _fill_owners(efsd->get_subdir(i), refs, dir_item); @@ -700,17 +671,14 @@ bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMa } for (int i = 0; i < efsd->get_file_count(); i++) { - if (!p_parent) { Vector<String> deps = efsd->get_file_deps(i); for (int j = 0; j < deps.size(); j++) { - if (!refs.has(deps[j])) { refs[deps[j]] = 1; } } } else { - String path = efsd->get_file_path(i); if (!refs.has(path)) { TreeItem *ti = files->create_item(p_parent); @@ -720,12 +688,12 @@ bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMa String type = efsd->get_file_type(i); - Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(type); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type); ti->set_icon(0, icon); int ds = efsd->get_file_deps(i).size(); ti->set_text(1, itos(ds)); if (ds) { - ti->add_button(1, get_icon("GuiVisibilityVisible", "EditorIcons"), -1, false, TTR("Show Dependencies")); + ti->add_button(1, files->get_theme_icon("GuiVisibilityVisible", "EditorIcons"), -1, false, TTR("Show Dependencies")); } ti->set_metadata(0, path); has_children = true; @@ -738,22 +706,19 @@ bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMa void OrphanResourcesDialog::refresh() { HashMap<String, int> refs; - _fill_owners(EditorFileSystem::get_singleton()->get_filesystem(), refs, NULL); + _fill_owners(EditorFileSystem::get_singleton()->get_filesystem(), refs, nullptr); files->clear(); TreeItem *root = files->create_item(); _fill_owners(EditorFileSystem::get_singleton()->get_filesystem(), refs, root); } void OrphanResourcesDialog::show() { - refresh(); - popup_centered_ratio(); + popup_centered_ratio(0.4); } void OrphanResourcesDialog::_find_to_delete(TreeItem *p_item, List<String> &paths) { - while (p_item) { - if (p_item->get_cell_mode(0) == TreeItem::CELL_MODE_CHECK && p_item->is_checked(0)) { paths.push_back(p_item->get_metadata(0)); } @@ -767,10 +732,8 @@ void OrphanResourcesDialog::_find_to_delete(TreeItem *p_item, List<String> &path } void OrphanResourcesDialog::_delete_confirm() { - DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); for (List<String>::Element *E = paths.front(); E; E = E->next()) { - da->remove(E->get()); EditorFileSystem::get_singleton()->update_file(E->get()); } @@ -779,7 +742,6 @@ void OrphanResourcesDialog::_delete_confirm() { } void OrphanResourcesDialog::_button_pressed(Object *p_item, int p_column, int p_id) { - TreeItem *ti = Object::cast_to<TreeItem>(p_item); String path = ti->get_metadata(0); @@ -787,20 +749,16 @@ void OrphanResourcesDialog::_button_pressed(Object *p_item, int p_column, int p_ } void OrphanResourcesDialog::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_delete_confirm"), &OrphanResourcesDialog::_delete_confirm); - ClassDB::bind_method(D_METHOD("_button_pressed"), &OrphanResourcesDialog::_button_pressed); } OrphanResourcesDialog::OrphanResourcesDialog() { - set_title(TTR("Orphan Resource Explorer")); delete_confirm = memnew(ConfirmationDialog); get_ok()->set_text(TTR("Delete")); add_child(delete_confirm); dep_edit = memnew(DependencyEditor); add_child(dep_edit); - delete_confirm->connect("confirmed", this, "_delete_confirm"); + delete_confirm->connect("confirmed", callable_mp(this, &OrphanResourcesDialog::_delete_confirm)); set_hide_on_ok(false); VBoxContainer *vbc = memnew(VBoxContainer); @@ -816,5 +774,5 @@ OrphanResourcesDialog::OrphanResourcesDialog() { files->set_column_title(1, TTR("Owns")); files->set_hide_root(true); vbc->add_margin_child(TTR("Resources Without Explicit Ownership:"), files, true); - files->connect("button_pressed", this, "_button_pressed"); + files->connect("button_pressed", callable_mp(this, &OrphanResourcesDialog::_button_pressed)); } |