dependency_editor.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /*************************************************************************/
  2. /* dependency_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "dependency_editor.h"
  31. #include "editor_node.h"
  32. #include "io/resource_loader.h"
  33. #include "os/file_access.h"
  34. #include "scene/gui/margin_container.h"
  35. void DependencyEditor::_notification(int p_what) {
  36. }
  37. void DependencyEditor::_searched(const String &p_path) {
  38. Map<String, String> dep_rename;
  39. dep_rename[replacing] = p_path;
  40. ResourceLoader::rename_dependencies(editing, dep_rename);
  41. _update_list();
  42. _update_file();
  43. }
  44. void DependencyEditor::_load_pressed(Object *p_item, int p_cell, int p_button) {
  45. TreeItem *ti = p_item->cast_to<TreeItem>();
  46. String fname = ti->get_text(0);
  47. replacing = ti->get_text(1);
  48. search->set_title(TTR("Search Replacement For:") + " " + replacing.get_file());
  49. search->clear_filters();
  50. List<String> ext;
  51. ResourceLoader::get_recognized_extensions_for_type(ti->get_metadata(0), &ext);
  52. for (List<String>::Element *E = ext.front(); E; E = E->next()) {
  53. search->add_filter("*" + E->get());
  54. }
  55. search->popup_centered_ratio();
  56. }
  57. void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String, Map<String, String> > &candidates) {
  58. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  59. _fix_and_find(efsd->get_subdir(i), candidates);
  60. }
  61. for (int i = 0; i < efsd->get_file_count(); i++) {
  62. String file = efsd->get_file(i);
  63. if (!candidates.has(file))
  64. continue;
  65. String path = efsd->get_file_path(i);
  66. for (Map<String, String>::Element *E = candidates[file].front(); E; E = E->next()) {
  67. if (E->get() == String()) {
  68. E->get() = path;
  69. continue;
  70. }
  71. //must match the best, using subdirs
  72. String existing = E->get().replace_first("res://", "");
  73. String current = path.replace_first("res://", "");
  74. String lost = E->key().replace_first("res://", "");
  75. Vector<String> existingv = existing.split("/");
  76. existingv.invert();
  77. Vector<String> currentv = current.split("/");
  78. currentv.invert();
  79. Vector<String> lostv = lost.split("/");
  80. lostv.invert();
  81. int existing_score = 0;
  82. int current_score = 0;
  83. for (int j = 0; j < lostv.size(); j++) {
  84. if (j < existingv.size() && lostv[j] == existingv[j]) {
  85. existing_score++;
  86. }
  87. if (j < currentv.size() && lostv[j] == currentv[j]) {
  88. current_score++;
  89. }
  90. }
  91. if (current_score > existing_score) {
  92. //if it was the same, could track distance to new path but..
  93. E->get() = path; //replace by more accurate
  94. }
  95. }
  96. }
  97. }
  98. void DependencyEditor::_fix_all() {
  99. if (!EditorFileSystem::get_singleton()->get_filesystem())
  100. return;
  101. Map<String, Map<String, String> > candidates;
  102. for (List<String>::Element *E = missing.front(); E; E = E->next()) {
  103. String base = E->get().get_file();
  104. if (!candidates.has(base)) {
  105. candidates[base] = Map<String, String>();
  106. }
  107. candidates[base][E->get()] = "";
  108. }
  109. _fix_and_find(EditorFileSystem::get_singleton()->get_filesystem(), candidates);
  110. Map<String, String> remaps;
  111. for (Map<String, Map<String, String> >::Element *E = candidates.front(); E; E = E->next()) {
  112. for (Map<String, String>::Element *F = E->get().front(); F; F = F->next()) {
  113. if (F->get() != String()) {
  114. remaps[F->key()] = F->get();
  115. }
  116. }
  117. }
  118. if (remaps.size()) {
  119. ResourceLoader::rename_dependencies(editing, remaps);
  120. _update_list();
  121. _update_file();
  122. }
  123. }
  124. void DependencyEditor::_update_file() {
  125. EditorFileSystem::get_singleton()->update_file(editing);
  126. }
  127. void DependencyEditor::_update_list() {
  128. List<String> deps;
  129. ResourceLoader::get_dependencies(editing, &deps, true);
  130. tree->clear();
  131. missing.clear();
  132. TreeItem *root = tree->create_item();
  133. Ref<Texture> folder = get_icon("folder", "FileDialog");
  134. bool broken = false;
  135. for (List<String>::Element *E = deps.front(); E; E = E->next()) {
  136. TreeItem *item = tree->create_item(root);
  137. String n = E->get();
  138. String path;
  139. String type;
  140. if (n.find("::") != -1) {
  141. path = n.get_slice("::", 0);
  142. type = n.get_slice("::", 1);
  143. } else {
  144. path = n;
  145. type = "Resource";
  146. }
  147. String name = path.get_file();
  148. Ref<Texture> icon;
  149. if (has_icon(type, "EditorIcons")) {
  150. icon = get_icon(type, "EditorIcons");
  151. } else {
  152. icon = get_icon("Object", "EditorIcons");
  153. }
  154. item->set_text(0, name);
  155. item->set_icon(0, icon);
  156. item->set_metadata(0, type);
  157. item->set_text(1, path);
  158. if (!FileAccess::exists(path)) {
  159. item->set_custom_color(1, Color(1, 0.4, 0.3));
  160. missing.push_back(path);
  161. broken = true;
  162. }
  163. item->add_button(1, folder, 0);
  164. }
  165. fixdeps->set_disabled(!broken);
  166. }
  167. void DependencyEditor::edit(const String &p_path) {
  168. editing = p_path;
  169. set_title(TTR("Dependencies For:") + " " + p_path.get_file());
  170. _update_list();
  171. popup_centered_ratio();
  172. if (EditorNode::get_singleton()->is_scene_open(p_path)) {
  173. EditorNode::get_singleton()->show_warning(vformat(TTR("Scene '%s' is currently being edited.\nChanges will not take effect unless reloaded."), p_path.get_file()));
  174. } else if (ResourceCache::has(p_path)) {
  175. EditorNode::get_singleton()->show_warning(vformat(TTR("Resource '%s' is in use.\nChanges will take effect when reloaded."), p_path.get_file()));
  176. }
  177. }
  178. void DependencyEditor::_bind_methods() {
  179. ObjectTypeDB::bind_method(_MD("_searched"), &DependencyEditor::_searched);
  180. ObjectTypeDB::bind_method(_MD("_load_pressed"), &DependencyEditor::_load_pressed);
  181. ObjectTypeDB::bind_method(_MD("_fix_all"), &DependencyEditor::_fix_all);
  182. }
  183. DependencyEditor::DependencyEditor() {
  184. VBoxContainer *vb = memnew(VBoxContainer);
  185. vb->set_name(TTR("Dependencies"));
  186. add_child(vb);
  187. set_child_rect(vb);
  188. tree = memnew(Tree);
  189. tree->set_columns(2);
  190. tree->set_column_titles_visible(true);
  191. tree->set_column_title(0, TTR("Resource"));
  192. tree->set_column_title(1, TTR("Path"));
  193. tree->set_hide_root(true);
  194. tree->connect("button_pressed", this, "_load_pressed");
  195. HBoxContainer *hbc = memnew(HBoxContainer);
  196. Label *label = memnew(Label(TTR("Dependencies:")));
  197. hbc->add_child(label);
  198. hbc->add_spacer();
  199. fixdeps = memnew(Button(TTR("Fix Broken")));
  200. hbc->add_child(fixdeps);
  201. fixdeps->connect("pressed", this, "_fix_all");
  202. vb->add_child(hbc);
  203. MarginContainer *mc = memnew(MarginContainer);
  204. mc->set_v_size_flags(SIZE_EXPAND_FILL);
  205. mc->add_child(tree);
  206. vb->add_child(mc);
  207. set_title(TTR("Dependency Editor"));
  208. search = memnew(EditorFileDialog);
  209. search->connect("file_selected", this, "_searched");
  210. search->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  211. search->set_title(TTR("Search Replacement Resource:"));
  212. add_child(search);
  213. }
  214. /////////////////////////////////////
  215. void DependencyEditorOwners::_list_rmb_select(int p_item, const Vector2 &p_pos) {
  216. file_options->clear();
  217. file_options->set_size(Size2(1, 1));
  218. if (p_item >= 0) {
  219. file_options->add_item(TTR("Open"), FILE_OPEN);
  220. }
  221. file_options->set_pos(owners->get_global_pos() + p_pos);
  222. file_options->popup();
  223. }
  224. void DependencyEditorOwners::_select_file(int p_idx) {
  225. String fpath = owners->get_item_text(p_idx);
  226. if (ResourceLoader::get_resource_type(fpath) == "PackedScene") {
  227. editor->open_request(fpath);
  228. hide();
  229. emit_signal("confirmed");
  230. }
  231. }
  232. void DependencyEditorOwners::_file_option(int p_option) {
  233. switch (p_option) {
  234. case FILE_OPEN: {
  235. int idx = owners->get_current();
  236. if (idx < 0 || idx >= owners->get_item_count())
  237. break;
  238. _select_file(idx);
  239. } break;
  240. }
  241. }
  242. void DependencyEditorOwners::_bind_methods() {
  243. ObjectTypeDB::bind_method(_MD("_list_rmb_select"), &DependencyEditorOwners::_list_rmb_select);
  244. ObjectTypeDB::bind_method(_MD("_file_option"), &DependencyEditorOwners::_file_option);
  245. ObjectTypeDB::bind_method(_MD("_select_file"), &DependencyEditorOwners::_select_file);
  246. }
  247. void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) {
  248. if (!efsd)
  249. return;
  250. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  251. _fill_owners(efsd->get_subdir(i));
  252. }
  253. for (int i = 0; i < efsd->get_file_count(); i++) {
  254. Vector<String> deps = efsd->get_file_deps(i);
  255. //print_line(":::"+efsd->get_file_path(i));
  256. bool found = false;
  257. for (int j = 0; j < deps.size(); j++) {
  258. //print_line("\t"+deps[j]+" vs "+editing);
  259. if (deps[j] == editing) {
  260. //print_line("found");
  261. found = true;
  262. break;
  263. }
  264. }
  265. if (!found)
  266. continue;
  267. Ref<Texture> icon;
  268. String type = efsd->get_file_type(i);
  269. if (!has_icon(type, "EditorIcons")) {
  270. icon = get_icon("Object", "EditorIcons");
  271. } else {
  272. icon = get_icon(type, "EditorIcons");
  273. }
  274. owners->add_item(efsd->get_file_path(i), icon);
  275. }
  276. }
  277. void DependencyEditorOwners::show(const String &p_path) {
  278. editing = p_path;
  279. owners->clear();
  280. _fill_owners(EditorFileSystem::get_singleton()->get_filesystem());
  281. popup_centered_ratio();
  282. set_title(TTR("Owners Of:") + " " + p_path.get_file());
  283. }
  284. DependencyEditorOwners::DependencyEditorOwners(EditorNode *p_editor) {
  285. editor = p_editor;
  286. file_options = memnew(PopupMenu);
  287. add_child(file_options);
  288. file_options->connect("item_pressed", this, "_file_option");
  289. owners = memnew(ItemList);
  290. owners->set_select_mode(ItemList::SELECT_SINGLE);
  291. owners->connect("item_rmb_selected", this, "_list_rmb_select");
  292. owners->connect("item_activated", this, "_select_file");
  293. owners->set_allow_rmb_select(true);
  294. add_child(owners);
  295. set_child_rect(owners);
  296. }
  297. ///////////////////////
  298. void DependencyRemoveDialog::_fill_owners(EditorFileSystemDirectory *efsd) {
  299. if (!efsd)
  300. return;
  301. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  302. _fill_owners(efsd->get_subdir(i));
  303. }
  304. for (int i = 0; i < efsd->get_file_count(); i++) {
  305. Vector<String> deps = efsd->get_file_deps(i);
  306. //print_line(":::"+efsd->get_file_path(i));
  307. Set<String> met;
  308. for (int j = 0; j < deps.size(); j++) {
  309. if (files.has(deps[j])) {
  310. met.insert(deps[j]);
  311. }
  312. }
  313. if (!met.size())
  314. continue;
  315. exist = true;
  316. Ref<Texture> icon;
  317. String type = efsd->get_file_type(i);
  318. if (!has_icon(type, "EditorIcons")) {
  319. icon = get_icon("Object", "EditorIcons");
  320. } else {
  321. icon = get_icon(type, "EditorIcons");
  322. }
  323. for (Set<String>::Element *E = met.front(); E; E = E->next()) {
  324. String which = E->get();
  325. if (!files[which]) {
  326. TreeItem *ti = owners->create_item(owners->get_root());
  327. ti->set_text(0, which.get_file());
  328. files[which] = ti;
  329. }
  330. TreeItem *ti = owners->create_item(files[which]);
  331. ti->set_text(0, efsd->get_file_path(i));
  332. ti->set_icon(0, icon);
  333. }
  334. }
  335. }
  336. void DependencyRemoveDialog::show(const Vector<String> &to_erase) {
  337. exist = false;
  338. owners->clear();
  339. files.clear();
  340. owners->create_item(); // root
  341. for (int i = 0; i < to_erase.size(); i++) {
  342. files[to_erase[i]] = NULL;
  343. }
  344. _fill_owners(EditorFileSystem::get_singleton()->get_filesystem());
  345. if (exist) {
  346. owners->show();
  347. text->set_text(TTR("The files being removed are required by other resources in order for them to work.\nRemove them anyway? (no undo)"));
  348. popup_centered_minsize(Size2(500, 220));
  349. } else {
  350. owners->hide();
  351. text->set_text(TTR("Remove selected files from the project? (no undo)"));
  352. popup_centered_minsize(Size2(400, 100));
  353. }
  354. }
  355. void DependencyRemoveDialog::ok_pressed() {
  356. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  357. for (Map<String, TreeItem *>::Element *E = files.front(); E; E = E->next()) {
  358. if (da->dir_exists(E->key())) {
  359. String path = OS::get_singleton()->get_resource_dir() + E->key().replace_first("res://", "/");
  360. OS::get_singleton()->move_path_to_trash(path);
  361. EditorFileSystem::get_singleton()->scan();
  362. } else {
  363. if (ResourceCache::has(E->key())) {
  364. Resource *res = ResourceCache::get(E->key());
  365. res->set_path(""); //clear reference to path
  366. }
  367. da->remove(E->key());
  368. EditorFileSystem::get_singleton()->update_file(E->key());
  369. }
  370. }
  371. memdelete(da);
  372. }
  373. DependencyRemoveDialog::DependencyRemoveDialog() {
  374. VBoxContainer *vb = memnew(VBoxContainer);
  375. add_child(vb);
  376. set_child_rect(vb);
  377. text = memnew(Label);
  378. vb->add_child(text);
  379. owners = memnew(Tree);
  380. owners->set_hide_root(true);
  381. vb->add_child(owners);
  382. owners->set_v_size_flags(SIZE_EXPAND_FILL);
  383. get_ok()->set_text(TTR("Remove"));
  384. }
  385. //////////////
  386. void DependencyErrorDialog::show(const String &p_for_file, const Vector<String> &report) {
  387. for_file = p_for_file;
  388. set_title(TTR("Error loading:") + " " + p_for_file.get_file());
  389. files->clear();
  390. TreeItem *root = files->create_item(NULL);
  391. for (int i = 0; i < report.size(); i++) {
  392. String dep;
  393. String type = "Object";
  394. dep = report[i].get_slice("::", 0);
  395. if (report[i].get_slice_count("::") > 0)
  396. type = report[i].get_slice("::", 1);
  397. Ref<Texture> icon;
  398. if (!has_icon(type, "EditorIcons")) {
  399. icon = get_icon("Object", "EditorIcons");
  400. } else {
  401. icon = get_icon(type, "EditorIcons");
  402. }
  403. TreeItem *ti = files->create_item(root);
  404. ti->set_text(0, dep);
  405. ti->set_icon(0, icon);
  406. }
  407. popup_centered_minsize(Size2(500, 220));
  408. }
  409. void DependencyErrorDialog::ok_pressed() {
  410. EditorNode::get_singleton()->load_scene(for_file, true);
  411. }
  412. void DependencyErrorDialog::custom_action(const String &) {
  413. EditorNode::get_singleton()->fix_dependencies(for_file);
  414. }
  415. DependencyErrorDialog::DependencyErrorDialog() {
  416. VBoxContainer *vb = memnew(VBoxContainer);
  417. add_child(vb);
  418. set_child_rect(vb);
  419. files = memnew(Tree);
  420. files->set_hide_root(true);
  421. vb->add_margin_child(TTR("Scene failed to load due to missing dependencies:"), files, true);
  422. files->set_v_size_flags(SIZE_EXPAND_FILL);
  423. get_ok()->set_text(TTR("Open Anyway"));
  424. text = memnew(Label);
  425. vb->add_child(text);
  426. text->set_text(TTR("Which action should be taken?"));
  427. fdep = add_button(TTR("Fix Dependencies"), true, "fixdeps");
  428. set_title(TTR("Errors loading!"));
  429. }
  430. //////////////////////////////////////////////////////////////////////
  431. void OrphanResourcesDialog::ok_pressed() {
  432. paths.clear();
  433. _find_to_delete(files->get_root(), paths);
  434. if (paths.empty())
  435. return;
  436. delete_confirm->set_text(vformat(TTR("Permanently delete %d item(s)? (No undo!)"), paths.size()));
  437. delete_confirm->popup_centered_minsize();
  438. }
  439. bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent) {
  440. if (!efsd)
  441. return false;
  442. bool has_childs = false;
  443. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  444. TreeItem *dir_item = NULL;
  445. if (p_parent) {
  446. dir_item = files->create_item(p_parent);
  447. dir_item->set_text(0, efsd->get_subdir(i)->get_name());
  448. dir_item->set_icon(0, get_icon("folder", "FileDialog"));
  449. }
  450. bool children = _fill_owners(efsd->get_subdir(i), refs, dir_item);
  451. if (p_parent) {
  452. if (!children) {
  453. memdelete(dir_item);
  454. } else {
  455. has_childs = true;
  456. }
  457. }
  458. }
  459. for (int i = 0; i < efsd->get_file_count(); i++) {
  460. if (!p_parent) {
  461. Vector<String> deps = efsd->get_file_deps(i);
  462. //print_line(":::"+efsd->get_file_path(i));
  463. for (int j = 0; j < deps.size(); j++) {
  464. if (!refs.has(deps[j])) {
  465. refs[deps[j]] = 1;
  466. }
  467. }
  468. } else {
  469. String path = efsd->get_file_path(i);
  470. if (!refs.has(path)) {
  471. TreeItem *ti = files->create_item(p_parent);
  472. ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  473. ti->set_text(0, efsd->get_file(i));
  474. ti->set_editable(0, true);
  475. String type = efsd->get_file_type(i);
  476. Ref<Texture> icon;
  477. if (has_icon(type, "EditorIcons")) {
  478. icon = get_icon(type, "EditorIcons");
  479. } else {
  480. icon = get_icon("Object", "EditorIcons");
  481. }
  482. ti->set_icon(0, icon);
  483. int ds = efsd->get_file_deps(i).size();
  484. ti->set_text(1, itos(ds));
  485. if (ds) {
  486. ti->add_button(1, get_icon("Visible", "EditorIcons"));
  487. }
  488. ti->set_metadata(0, path);
  489. has_childs = true;
  490. }
  491. }
  492. }
  493. return has_childs;
  494. }
  495. void OrphanResourcesDialog::refresh() {
  496. HashMap<String, int> refs;
  497. _fill_owners(EditorFileSystem::get_singleton()->get_filesystem(), refs, NULL);
  498. files->clear();
  499. TreeItem *root = files->create_item();
  500. _fill_owners(EditorFileSystem::get_singleton()->get_filesystem(), refs, root);
  501. }
  502. void OrphanResourcesDialog::show() {
  503. refresh();
  504. popup_centered_ratio();
  505. }
  506. void OrphanResourcesDialog::_find_to_delete(TreeItem *p_item, List<String> &paths) {
  507. while (p_item) {
  508. if (p_item->get_cell_mode(0) == TreeItem::CELL_MODE_CHECK && p_item->is_checked(0)) {
  509. paths.push_back(p_item->get_metadata(0));
  510. }
  511. if (p_item->get_children()) {
  512. _find_to_delete(p_item->get_children(), paths);
  513. }
  514. p_item = p_item->get_next();
  515. }
  516. }
  517. void OrphanResourcesDialog::_delete_confirm() {
  518. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  519. for (List<String>::Element *E = paths.front(); E; E = E->next()) {
  520. da->remove(E->get());
  521. EditorFileSystem::get_singleton()->update_file(E->get());
  522. }
  523. memdelete(da);
  524. refresh();
  525. }
  526. void OrphanResourcesDialog::_button_pressed(Object *p_item, int p_column, int p_id) {
  527. TreeItem *ti = p_item->cast_to<TreeItem>();
  528. String path = ti->get_metadata(0);
  529. dep_edit->edit(path);
  530. }
  531. void OrphanResourcesDialog::_bind_methods() {
  532. ObjectTypeDB::bind_method(_MD("_delete_confirm"), &OrphanResourcesDialog::_delete_confirm);
  533. ObjectTypeDB::bind_method(_MD("_button_pressed"), &OrphanResourcesDialog::_button_pressed);
  534. }
  535. OrphanResourcesDialog::OrphanResourcesDialog() {
  536. VBoxContainer *vbc = memnew(VBoxContainer);
  537. add_child(vbc);
  538. set_child_rect(vbc);
  539. files = memnew(Tree);
  540. files->set_columns(2);
  541. files->set_column_titles_visible(true);
  542. files->set_column_min_width(1, 100);
  543. files->set_column_expand(0, true);
  544. files->set_column_expand(1, false);
  545. files->set_column_title(0, TTR("Resource"));
  546. files->set_column_title(1, TTR("Owns"));
  547. files->set_hide_root(true);
  548. vbc->add_margin_child(TTR("Resources Without Explicit Ownership:"), files, true);
  549. set_title(TTR("Orphan Resource Explorer"));
  550. delete_confirm = memnew(ConfirmationDialog);
  551. delete_confirm->set_text(TTR("Delete selected files?"));
  552. get_ok()->set_text(TTR("Delete"));
  553. add_child(delete_confirm);
  554. dep_edit = memnew(DependencyEditor);
  555. add_child(dep_edit);
  556. files->connect("button_pressed", this, "_button_pressed");
  557. delete_confirm->connect("confirmed", this, "_delete_confirm");
  558. set_hide_on_ok(false);
  559. }