filesystem_dock.cpp 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707
  1. /*************************************************************************/
  2. /* filesystem_dock.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "filesystem_dock.h"
  31. #include "core/io/resource_loader.h"
  32. #include "core/os/dir_access.h"
  33. #include "core/os/file_access.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/os/os.h"
  36. #include "core/project_settings.h"
  37. #include "editor_node.h"
  38. #include "editor_settings.h"
  39. #include "scene/main/viewport.h"
  40. #include "scene/resources/packed_scene.h"
  41. Ref<Texture> FileSystemDock::_get_tree_item_icon(EditorFileSystemDirectory *p_dir, int p_idx) {
  42. Ref<Texture> file_icon;
  43. if (!p_dir->get_file_import_is_valid(p_idx)) {
  44. file_icon = get_icon("ImportFail", "EditorIcons");
  45. } else {
  46. String file_type = p_dir->get_file_type(p_idx);
  47. file_icon = (has_icon(file_type, "EditorIcons")) ? get_icon(file_type, "EditorIcons") : get_icon("File", "EditorIcons");
  48. }
  49. return file_icon;
  50. }
  51. bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites) {
  52. bool parent_should_expand = false;
  53. // Create a tree item for the subdirectory.
  54. TreeItem *subdirectory_item = tree->create_item(p_parent);
  55. String dname = p_dir->get_name();
  56. if (dname == "")
  57. dname = "res://";
  58. subdirectory_item->set_text(0, dname);
  59. subdirectory_item->set_icon(0, get_icon("Folder", "EditorIcons"));
  60. subdirectory_item->set_icon_modulate(0, get_color("folder_icon_modulate", "FileDialog"));
  61. subdirectory_item->set_selectable(0, true);
  62. String lpath = p_dir->get_path();
  63. subdirectory_item->set_metadata(0, lpath);
  64. if (!p_select_in_favorites && (path == lpath || ((display_mode == DISPLAY_MODE_SPLIT) && path.get_base_dir() == lpath))) {
  65. subdirectory_item->select(0);
  66. }
  67. subdirectory_item->set_collapsed(uncollapsed_paths.find(lpath) < 0);
  68. if (searched_string.length() > 0 && dname.to_lower().find(searched_string) >= 0) {
  69. parent_should_expand = true;
  70. }
  71. // Create items for all subdirectories.
  72. for (int i = 0; i < p_dir->get_subdir_count(); i++)
  73. parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites) || parent_should_expand);
  74. // Create all items for the files in the subdirectory.
  75. if (display_mode == DISPLAY_MODE_TREE_ONLY) {
  76. for (int i = 0; i < p_dir->get_file_count(); i++) {
  77. String file_type = p_dir->get_file_type(i);
  78. if (_is_file_type_disabled_by_feature_profile(file_type)) {
  79. // If type is disabled, file won't be displayed.
  80. continue;
  81. }
  82. String file_name = p_dir->get_file(i);
  83. if (searched_string.length() > 0) {
  84. if (file_name.to_lower().find(searched_string) < 0) {
  85. // The searched string is not in the file name, we skip it.
  86. continue;
  87. } else {
  88. // We expand all parents.
  89. parent_should_expand = true;
  90. }
  91. }
  92. TreeItem *file_item = tree->create_item(subdirectory_item);
  93. file_item->set_text(0, file_name);
  94. file_item->set_icon(0, _get_tree_item_icon(p_dir, i));
  95. String file_metadata = lpath.plus_file(file_name);
  96. file_item->set_metadata(0, file_metadata);
  97. if (!p_select_in_favorites && path == file_metadata) {
  98. file_item->select(0);
  99. file_item->set_as_cursor(0);
  100. }
  101. String main_scene = ProjectSettings::get_singleton()->get("application/run/main_scene");
  102. if (main_scene == file_metadata) {
  103. file_item->set_custom_color(0, get_color("accent_color", "Editor"));
  104. }
  105. Array udata;
  106. udata.push_back(tree_update_id);
  107. udata.push_back(file_item);
  108. EditorResourcePreview::get_singleton()->queue_resource_preview(file_metadata, this, "_tree_thumbnail_done", udata);
  109. }
  110. }
  111. if (searched_string.length() > 0) {
  112. if (parent_should_expand) {
  113. subdirectory_item->set_collapsed(false);
  114. } else if (dname != "res://") {
  115. subdirectory_item->get_parent()->remove_child(subdirectory_item);
  116. }
  117. }
  118. return parent_should_expand;
  119. }
  120. Vector<String> FileSystemDock::_compute_uncollapsed_paths() {
  121. // Register currently collapsed paths.
  122. Vector<String> uncollapsed_paths;
  123. TreeItem *root = tree->get_root();
  124. if (root) {
  125. TreeItem *favorites_item = root->get_children();
  126. if (!favorites_item->is_collapsed()) {
  127. uncollapsed_paths.push_back(favorites_item->get_metadata(0));
  128. }
  129. TreeItem *resTree = root->get_children()->get_next();
  130. if (resTree) {
  131. Vector<TreeItem *> needs_check;
  132. needs_check.push_back(resTree);
  133. while (needs_check.size()) {
  134. if (!needs_check[0]->is_collapsed()) {
  135. uncollapsed_paths.push_back(needs_check[0]->get_metadata(0));
  136. TreeItem *child = needs_check[0]->get_children();
  137. while (child) {
  138. needs_check.push_back(child);
  139. child = child->get_next();
  140. }
  141. }
  142. needs_check.remove(0);
  143. }
  144. }
  145. }
  146. return uncollapsed_paths;
  147. }
  148. void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, bool p_uncollapse_root, bool p_select_in_favorites) {
  149. // Recreate the tree.
  150. tree->clear();
  151. tree_update_id++;
  152. updating_tree = true;
  153. TreeItem *root = tree->create_item();
  154. // Handles the favorites.
  155. TreeItem *favorites = tree->create_item(root);
  156. favorites->set_icon(0, get_icon("Favorites", "EditorIcons"));
  157. favorites->set_text(0, TTR("Favorites:"));
  158. favorites->set_metadata(0, "Favorites");
  159. favorites->set_collapsed(p_uncollapsed_paths.find("Favorites") < 0);
  160. Vector<String> favorite_paths = EditorSettings::get_singleton()->get_favorites();
  161. for (int i = 0; i < favorite_paths.size(); i++) {
  162. String fave = favorite_paths[i];
  163. if (!fave.begins_with("res://"))
  164. continue;
  165. Ref<Texture> folder_icon = get_icon("Folder", "EditorIcons");
  166. const Color folder_color = get_color("folder_icon_modulate", "FileDialog");
  167. String text;
  168. Ref<Texture> icon;
  169. Color color;
  170. if (fave == "res://") {
  171. text = "/";
  172. icon = folder_icon;
  173. color = folder_color;
  174. } else if (fave.ends_with("/")) {
  175. text = fave.substr(0, fave.length() - 1).get_file();
  176. icon = folder_icon;
  177. color = folder_color;
  178. } else {
  179. text = fave.get_file();
  180. int index;
  181. EditorFileSystemDirectory *dir = EditorFileSystem::get_singleton()->find_file(fave, &index);
  182. if (dir) {
  183. icon = _get_tree_item_icon(dir, index);
  184. } else {
  185. icon = get_icon("File", "EditorIcons");
  186. }
  187. color = Color(1, 1, 1);
  188. }
  189. if (searched_string.length() == 0 || text.to_lower().find(searched_string) >= 0) {
  190. TreeItem *ti = tree->create_item(favorites);
  191. ti->set_text(0, text);
  192. ti->set_icon(0, icon);
  193. ti->set_icon_modulate(0, color);
  194. ti->set_tooltip(0, fave);
  195. ti->set_selectable(0, true);
  196. ti->set_metadata(0, fave);
  197. if (p_select_in_favorites && fave == path) {
  198. ti->select(0);
  199. ti->set_as_cursor(0);
  200. }
  201. if (!fave.ends_with("/")) {
  202. Array udata;
  203. udata.push_back(tree_update_id);
  204. udata.push_back(ti);
  205. EditorResourcePreview::get_singleton()->queue_resource_preview(fave, this, "_tree_thumbnail_done", udata);
  206. }
  207. }
  208. }
  209. Vector<String> uncollapsed_paths = p_uncollapsed_paths;
  210. if (p_uncollapse_root) {
  211. uncollapsed_paths.push_back("res://");
  212. }
  213. // Create the remaining of the tree.
  214. _create_tree(root, EditorFileSystem::get_singleton()->get_filesystem(), uncollapsed_paths, p_select_in_favorites);
  215. tree->ensure_cursor_is_visible();
  216. updating_tree = false;
  217. }
  218. void FileSystemDock::set_display_mode(DisplayMode p_display_mode) {
  219. display_mode = p_display_mode;
  220. _update_display_mode(false);
  221. }
  222. void FileSystemDock::_update_display_mode(bool p_force) {
  223. // Compute the new display mode.
  224. if (p_force || old_display_mode != display_mode) {
  225. button_toggle_display_mode->set_pressed(display_mode == DISPLAY_MODE_SPLIT);
  226. switch (display_mode) {
  227. case DISPLAY_MODE_TREE_ONLY:
  228. tree->show();
  229. tree->set_v_size_flags(SIZE_EXPAND_FILL);
  230. if (display_mode == DISPLAY_MODE_TREE_ONLY) {
  231. tree_search_box->show();
  232. } else {
  233. tree_search_box->hide();
  234. }
  235. _update_tree(_compute_uncollapsed_paths());
  236. file_list_vb->hide();
  237. break;
  238. case DISPLAY_MODE_SPLIT:
  239. tree->show();
  240. tree->set_v_size_flags(SIZE_EXPAND_FILL);
  241. tree->ensure_cursor_is_visible();
  242. tree_search_box->hide();
  243. _update_tree(_compute_uncollapsed_paths());
  244. file_list_vb->show();
  245. _update_file_list(true);
  246. break;
  247. }
  248. old_display_mode = display_mode;
  249. }
  250. }
  251. void FileSystemDock::_notification(int p_what) {
  252. switch (p_what) {
  253. case NOTIFICATION_ENTER_TREE: {
  254. if (initialized)
  255. return;
  256. initialized = true;
  257. EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
  258. EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_fs_changed");
  259. EditorResourcePreview::get_singleton()->connect("preview_invalidated", this, "_preview_invalidated");
  260. String ei = "EditorIcons";
  261. button_reload->set_icon(get_icon("Reload", ei));
  262. button_toggle_display_mode->set_icon(get_icon("Panels2", ei));
  263. button_file_list_display_mode->connect("pressed", this, "_toggle_file_display");
  264. files->connect("item_activated", this, "_file_list_activate_file");
  265. button_hist_next->connect("pressed", this, "_fw_history");
  266. button_hist_prev->connect("pressed", this, "_bw_history");
  267. tree_search_box->set_right_icon(get_icon("Search", ei));
  268. tree_search_box->set_clear_button_enabled(true);
  269. file_list_search_box->set_right_icon(get_icon("Search", ei));
  270. file_list_search_box->set_clear_button_enabled(true);
  271. button_hist_next->set_icon(get_icon("Forward", ei));
  272. button_hist_prev->set_icon(get_icon("Back", ei));
  273. file_list_popup->connect("id_pressed", this, "_file_list_rmb_option");
  274. tree_popup->connect("id_pressed", this, "_tree_rmb_option");
  275. current_path->connect("text_entered", this, "_navigate_to_path");
  276. always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders"));
  277. set_file_list_display_mode(FileSystemDock::FILE_LIST_DISPLAY_LIST);
  278. _update_display_mode();
  279. if (EditorFileSystem::get_singleton()->is_scanning()) {
  280. _set_scanning_mode();
  281. } else {
  282. _update_tree(Vector<String>(), true);
  283. }
  284. } break;
  285. case NOTIFICATION_PROCESS: {
  286. if (EditorFileSystem::get_singleton()->is_scanning()) {
  287. scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100);
  288. }
  289. } break;
  290. case NOTIFICATION_DRAG_BEGIN: {
  291. Dictionary dd = get_viewport()->gui_get_drag_data();
  292. if (tree->is_visible_in_tree() && dd.has("type")) {
  293. if (dd.has("favorite")) {
  294. if ((String(dd["favorite"]) == "all"))
  295. tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  296. } else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) {
  297. tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN);
  298. }
  299. }
  300. } break;
  301. case NOTIFICATION_DRAG_END: {
  302. tree->set_drop_mode_flags(0);
  303. } break;
  304. case NOTIFICATION_THEME_CHANGED: {
  305. if (is_visible_in_tree()) {
  306. _update_display_mode(true);
  307. }
  308. } break;
  309. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  310. // Update icons.
  311. String ei = "EditorIcons";
  312. button_reload->set_icon(get_icon("Reload", ei));
  313. button_toggle_display_mode->set_icon(get_icon("Panels2", ei));
  314. button_hist_next->set_icon(get_icon("Forward", ei));
  315. button_hist_prev->set_icon(get_icon("Back", ei));
  316. if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) {
  317. button_file_list_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons"));
  318. } else {
  319. button_file_list_display_mode->set_icon(get_icon("FileList", "EditorIcons"));
  320. }
  321. tree_search_box->set_right_icon(get_icon("Search", ei));
  322. tree_search_box->set_clear_button_enabled(true);
  323. file_list_search_box->set_right_icon(get_icon("Search", ei));
  324. file_list_search_box->set_clear_button_enabled(true);
  325. // Update always show folders.
  326. bool new_always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders"));
  327. if (new_always_show_folders != always_show_folders) {
  328. always_show_folders = new_always_show_folders;
  329. _update_file_list(true);
  330. }
  331. // Change full tree mode.
  332. _update_display_mode();
  333. } break;
  334. }
  335. }
  336. void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_selected) {
  337. // Update the import dock.
  338. import_dock_needs_update = true;
  339. call_deferred("_update_import_dock");
  340. // Return if we don't select something new.
  341. if (!p_selected)
  342. return;
  343. // Tree item selected.
  344. TreeItem *selected = tree->get_selected();
  345. if (!selected)
  346. return;
  347. TreeItem *favorites_item = tree->get_root()->get_children();
  348. if (selected->get_parent() == favorites_item && !String(selected->get_metadata(0)).ends_with("/")) {
  349. // Go to the favorites if we click in the favorites and the path has changed.
  350. path = "Favorites";
  351. } else {
  352. path = selected->get_metadata(0);
  353. // Note: the "Favorites" item also leads to this path.
  354. }
  355. // Set the current path.
  356. _set_current_path_text(path);
  357. _push_to_history();
  358. // Update the file list.
  359. if (!updating_tree && display_mode == DISPLAY_MODE_SPLIT) {
  360. _update_file_list(false);
  361. }
  362. }
  363. String FileSystemDock::get_selected_path() const {
  364. if (path.ends_with("/"))
  365. return path;
  366. else
  367. return path.get_base_dir();
  368. }
  369. String FileSystemDock::get_current_path() const {
  370. return path;
  371. }
  372. void FileSystemDock::_set_current_path_text(const String &p_path) {
  373. if (p_path == "Favorites") {
  374. current_path->set_text(TTR("Favorites"));
  375. } else {
  376. current_path->set_text(path);
  377. }
  378. }
  379. void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_favorites) {
  380. if (p_path == "Favorites") {
  381. path = p_path;
  382. } else {
  383. String target_path = p_path;
  384. // If the path is a file, do not only go to the directory in the tree, also select the file in the file list.
  385. if (target_path.ends_with("/")) {
  386. target_path = target_path.substr(0, target_path.length() - 1);
  387. }
  388. DirAccess *dirAccess = DirAccess::open("res://");
  389. if (dirAccess->file_exists(p_path)) {
  390. path = target_path;
  391. } else if (dirAccess->dir_exists(p_path)) {
  392. path = target_path + "/";
  393. } else {
  394. memdelete(dirAccess);
  395. ERR_FAIL_MSG(vformat("Cannot navigate to '%s' as it has not been found in the file system!", p_path));
  396. }
  397. memdelete(dirAccess);
  398. }
  399. _set_current_path_text(path);
  400. _push_to_history();
  401. _update_tree(_compute_uncollapsed_paths(), false, p_select_in_favorites);
  402. if (display_mode == DISPLAY_MODE_SPLIT) {
  403. _update_file_list(false);
  404. files->get_v_scroll()->set_value(0);
  405. }
  406. String file_name = p_path.get_file();
  407. if (!file_name.empty()) {
  408. for (int i = 0; i < files->get_item_count(); i++) {
  409. if (files->get_item_text(i) == file_name) {
  410. files->select(i, true);
  411. files->ensure_current_is_visible();
  412. break;
  413. }
  414. }
  415. }
  416. }
  417. void FileSystemDock::navigate_to_path(const String &p_path) {
  418. file_list_search_box->clear();
  419. _navigate_to_path(p_path);
  420. }
  421. void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
  422. if ((file_list_vb->is_visible_in_tree() || path == p_path.get_base_dir()) && p_preview.is_valid()) {
  423. Array uarr = p_udata;
  424. int idx = uarr[0];
  425. String file = uarr[1];
  426. if (idx < files->get_item_count() && files->get_item_text(idx) == file && files->get_item_metadata(idx) == p_path) {
  427. if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) {
  428. if (p_small_preview.is_valid())
  429. files->set_item_icon(idx, p_small_preview);
  430. } else {
  431. files->set_item_icon(idx, p_preview);
  432. }
  433. }
  434. }
  435. }
  436. void FileSystemDock::_tree_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
  437. if (p_small_preview.is_valid()) {
  438. Array uarr = p_udata;
  439. if (tree_update_id == (int)uarr[0]) {
  440. TreeItem *file_item = Object::cast_to<TreeItem>(uarr[1]);
  441. if (file_item) {
  442. file_item->set_icon(0, p_small_preview);
  443. }
  444. }
  445. }
  446. }
  447. void FileSystemDock::_toggle_file_display() {
  448. _set_file_display(file_list_display_mode != FILE_LIST_DISPLAY_LIST);
  449. emit_signal("display_mode_changed");
  450. }
  451. void FileSystemDock::_set_file_display(bool p_active) {
  452. if (p_active) {
  453. file_list_display_mode = FILE_LIST_DISPLAY_LIST;
  454. button_file_list_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons"));
  455. button_file_list_display_mode->set_tooltip(TTR("View items as a grid of thumbnails."));
  456. } else {
  457. file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS;
  458. button_file_list_display_mode->set_icon(get_icon("FileList", "EditorIcons"));
  459. button_file_list_display_mode->set_tooltip(TTR("View items as a list."));
  460. }
  461. _update_file_list(true);
  462. }
  463. bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName &p_class) {
  464. Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
  465. if (profile.is_null()) {
  466. return false;
  467. }
  468. StringName class_name = p_class;
  469. while (class_name != StringName()) {
  470. if (profile->is_class_disabled(class_name)) {
  471. return true;
  472. }
  473. class_name = ClassDB::get_parent_class(class_name);
  474. }
  475. return false;
  476. }
  477. void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) {
  478. if (matches->size() > p_max_items)
  479. return;
  480. for (int i = 0; i < p_path->get_subdir_count(); i++) {
  481. _search(p_path->get_subdir(i), matches, p_max_items);
  482. }
  483. for (int i = 0; i < p_path->get_file_count(); i++) {
  484. String file = p_path->get_file(i);
  485. if (file.to_lower().find(searched_string) != -1) {
  486. FileInfo fi;
  487. fi.name = file;
  488. fi.type = p_path->get_file_type(i);
  489. fi.path = p_path->get_file_path(i);
  490. fi.import_broken = !p_path->get_file_import_is_valid(i);
  491. if (_is_file_type_disabled_by_feature_profile(fi.type)) {
  492. // This type is disabled, will not appear here.
  493. continue;
  494. }
  495. matches->push_back(fi);
  496. if (matches->size() > p_max_items)
  497. return;
  498. }
  499. }
  500. }
  501. void FileSystemDock::_update_file_list(bool p_keep_selection) {
  502. // Register the previously selected items.
  503. Set<String> cselection;
  504. if (p_keep_selection) {
  505. for (int i = 0; i < files->get_item_count(); i++) {
  506. if (files->is_selected(i))
  507. cselection.insert(files->get_item_text(i));
  508. }
  509. }
  510. files->clear();
  511. _set_current_path_text(path);
  512. String directory = path;
  513. String file = "";
  514. String ei = "EditorIcons";
  515. int thumbnail_size = EditorSettings::get_singleton()->get("docks/filesystem/thumbnail_size");
  516. thumbnail_size *= EDSCALE;
  517. Ref<Texture> folder_thumbnail;
  518. Ref<Texture> file_thumbnail;
  519. Ref<Texture> file_thumbnail_broken;
  520. bool use_thumbnails = (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS);
  521. if (use_thumbnails) {
  522. // Thumbnails mode.
  523. files->set_max_columns(0);
  524. files->set_icon_mode(ItemList::ICON_MODE_TOP);
  525. files->set_fixed_column_width(thumbnail_size * 3 / 2);
  526. files->set_max_text_lines(2);
  527. files->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size));
  528. if (thumbnail_size < 64) {
  529. folder_thumbnail = get_icon("FolderMediumThumb", ei);
  530. file_thumbnail = get_icon("FileMediumThumb", ei);
  531. file_thumbnail_broken = get_icon("FileDeadMediumThumb", ei);
  532. } else {
  533. folder_thumbnail = get_icon("FolderBigThumb", ei);
  534. file_thumbnail = get_icon("FileBigThumb", ei);
  535. file_thumbnail_broken = get_icon("FileDeadBigThumb", ei);
  536. }
  537. } else {
  538. // No thumbnails.
  539. files->set_icon_mode(ItemList::ICON_MODE_LEFT);
  540. files->set_max_columns(1);
  541. files->set_max_text_lines(1);
  542. files->set_fixed_column_width(0);
  543. files->set_fixed_icon_size(Size2());
  544. }
  545. Ref<Texture> folder_icon = (use_thumbnails) ? folder_thumbnail : get_icon("folder", "FileDialog");
  546. const Color folder_color = get_color("folder_icon_modulate", "FileDialog");
  547. // Build the FileInfo list.
  548. List<FileInfo> filelist;
  549. if (path == "Favorites") {
  550. // Display the favorites.
  551. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
  552. for (int i = 0; i < favorites.size(); i++) {
  553. String favorite = favorites[i];
  554. String text;
  555. Ref<Texture> icon;
  556. if (favorite == "res://") {
  557. text = "/";
  558. icon = folder_icon;
  559. if (searched_string.length() == 0 || text.to_lower().find(searched_string) >= 0) {
  560. files->add_item(text, icon, true);
  561. files->set_item_metadata(files->get_item_count() - 1, favorite);
  562. }
  563. } else if (favorite.ends_with("/")) {
  564. text = favorite.substr(0, favorite.length() - 1).get_file();
  565. icon = folder_icon;
  566. if (searched_string.length() == 0 || text.to_lower().find(searched_string) >= 0) {
  567. files->add_item(text, icon, true);
  568. files->set_item_metadata(files->get_item_count() - 1, favorite);
  569. }
  570. } else {
  571. int index;
  572. EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->find_file(favorite, &index);
  573. FileInfo fi;
  574. fi.name = favorite.get_file();
  575. fi.path = favorite;
  576. if (efd) {
  577. fi.type = efd->get_file_type(index);
  578. fi.import_broken = !efd->get_file_import_is_valid(index);
  579. } else {
  580. fi.type = "";
  581. fi.import_broken = true;
  582. }
  583. if (searched_string.length() == 0 || fi.name.to_lower().find(searched_string) >= 0) {
  584. filelist.push_back(fi);
  585. }
  586. }
  587. }
  588. } else {
  589. // Get infos on the directory + file.
  590. if (directory.ends_with("/") && directory != "res://") {
  591. directory = directory.substr(0, directory.length() - 1);
  592. }
  593. EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_filesystem_path(directory);
  594. if (!efd) {
  595. directory = path.get_base_dir();
  596. file = path.get_file();
  597. efd = EditorFileSystem::get_singleton()->get_filesystem_path(directory);
  598. }
  599. if (!efd)
  600. return;
  601. if (searched_string.length() > 0) {
  602. // Display the search results.
  603. _search(EditorFileSystem::get_singleton()->get_filesystem(), &filelist, 128);
  604. } else {
  605. if (display_mode == DISPLAY_MODE_TREE_ONLY || always_show_folders) {
  606. // Display folders in the list.
  607. if (directory != "res://") {
  608. files->add_item("..", folder_icon, true);
  609. String bd = directory.get_base_dir();
  610. if (bd != "res://" && !bd.ends_with("/"))
  611. bd += "/";
  612. files->set_item_metadata(files->get_item_count() - 1, bd);
  613. files->set_item_selectable(files->get_item_count() - 1, false);
  614. files->set_item_icon_modulate(files->get_item_count() - 1, folder_color);
  615. }
  616. for (int i = 0; i < efd->get_subdir_count(); i++) {
  617. String dname = efd->get_subdir(i)->get_name();
  618. files->add_item(dname, folder_icon, true);
  619. files->set_item_metadata(files->get_item_count() - 1, directory.plus_file(dname) + "/");
  620. files->set_item_icon_modulate(files->get_item_count() - 1, folder_color);
  621. if (cselection.has(dname)) {
  622. files->select(files->get_item_count() - 1, false);
  623. }
  624. }
  625. }
  626. // Display the folder content.
  627. for (int i = 0; i < efd->get_file_count(); i++) {
  628. FileInfo fi;
  629. fi.name = efd->get_file(i);
  630. fi.path = directory.plus_file(fi.name);
  631. fi.type = efd->get_file_type(i);
  632. fi.import_broken = !efd->get_file_import_is_valid(i);
  633. filelist.push_back(fi);
  634. }
  635. }
  636. filelist.sort();
  637. }
  638. // Fills the ItemList control node from the FileInfos.
  639. String oi = "Object";
  640. for (List<FileInfo>::Element *E = filelist.front(); E; E = E->next()) {
  641. FileInfo *finfo = &(E->get());
  642. String fname = finfo->name;
  643. String fpath = finfo->path;
  644. String ftype = finfo->type;
  645. Ref<Texture> type_icon;
  646. Ref<Texture> big_icon;
  647. String tooltip = fpath;
  648. // Select the icons.
  649. if (!finfo->import_broken) {
  650. type_icon = (has_icon(ftype, ei)) ? get_icon(ftype, ei) : get_icon(oi, ei);
  651. big_icon = file_thumbnail;
  652. } else {
  653. type_icon = get_icon("ImportFail", ei);
  654. big_icon = file_thumbnail_broken;
  655. tooltip += "\n" + TTR("Status: Import of file failed. Please fix file and reimport manually.");
  656. }
  657. // Add the item to the ItemList.
  658. int item_index;
  659. if (use_thumbnails) {
  660. files->add_item(fname, big_icon, true);
  661. item_index = files->get_item_count() - 1;
  662. files->set_item_metadata(item_index, fpath);
  663. files->set_item_tag_icon(item_index, type_icon);
  664. } else {
  665. files->add_item(fname, type_icon, true);
  666. item_index = files->get_item_count() - 1;
  667. files->set_item_metadata(item_index, fpath);
  668. }
  669. // Generate the preview.
  670. if (!finfo->import_broken) {
  671. Array udata;
  672. udata.resize(2);
  673. udata[0] = item_index;
  674. udata[1] = fname;
  675. EditorResourcePreview::get_singleton()->queue_resource_preview(fpath, this, "_file_list_thumbnail_done", udata);
  676. }
  677. // Select the items.
  678. if (cselection.has(fname))
  679. files->select(item_index, false);
  680. if (!p_keep_selection && file != "" && fname == file) {
  681. files->select(item_index, true);
  682. files->ensure_current_is_visible();
  683. }
  684. // Tooltip.
  685. if (finfo->sources.size()) {
  686. for (int j = 0; j < finfo->sources.size(); j++) {
  687. tooltip += "\nSource: " + finfo->sources[j];
  688. }
  689. }
  690. files->set_item_tooltip(item_index, tooltip);
  691. }
  692. }
  693. void FileSystemDock::_select_file(const String &p_path, bool p_select_in_favorites) {
  694. String fpath = p_path;
  695. if (fpath.ends_with("/")) {
  696. if (fpath != "res://") {
  697. fpath = fpath.substr(0, fpath.length() - 1);
  698. }
  699. } else if (fpath != "Favorites") {
  700. if (ResourceLoader::get_resource_type(fpath) == "PackedScene") {
  701. editor->open_request(fpath);
  702. } else {
  703. editor->load_resource(fpath);
  704. }
  705. }
  706. _navigate_to_path(fpath, p_select_in_favorites);
  707. }
  708. void FileSystemDock::_tree_activate_file() {
  709. TreeItem *selected = tree->get_selected();
  710. if (selected) {
  711. String path = selected->get_metadata(0);
  712. TreeItem *parent = selected->get_parent();
  713. bool is_favorite = parent != NULL && parent->get_metadata(0) == "Favorites";
  714. if ((!is_favorite && path.ends_with("/")) || path == "Favorites") {
  715. bool collapsed = selected->is_collapsed();
  716. selected->set_collapsed(!collapsed);
  717. } else {
  718. _select_file(path, is_favorite && !path.ends_with("/"));
  719. }
  720. }
  721. }
  722. void FileSystemDock::_file_list_activate_file(int p_idx) {
  723. _select_file(files->get_item_metadata(p_idx));
  724. }
  725. void FileSystemDock::_preview_invalidated(const String &p_path) {
  726. if (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && searched_string.length() == 0 && file_list_vb->is_visible_in_tree()) {
  727. for (int i = 0; i < files->get_item_count(); i++) {
  728. if (files->get_item_metadata(i) == p_path) {
  729. // Re-request preview.
  730. Array udata;
  731. udata.resize(2);
  732. udata[0] = i;
  733. udata[1] = files->get_item_text(i);
  734. EditorResourcePreview::get_singleton()->queue_resource_preview(p_path, this, "_file_list_thumbnail_done", udata);
  735. break;
  736. }
  737. }
  738. }
  739. }
  740. void FileSystemDock::_fs_changed() {
  741. button_hist_prev->set_disabled(history_pos == 0);
  742. button_hist_next->set_disabled(history_pos == history.size() - 1);
  743. scanning_vb->hide();
  744. split_box->show();
  745. if (tree->is_visible()) {
  746. _update_tree(_compute_uncollapsed_paths());
  747. }
  748. if (file_list_vb->is_visible()) {
  749. _update_file_list(true);
  750. }
  751. set_process(false);
  752. }
  753. void FileSystemDock::_set_scanning_mode() {
  754. button_hist_prev->set_disabled(true);
  755. button_hist_next->set_disabled(true);
  756. split_box->hide();
  757. scanning_vb->show();
  758. set_process(true);
  759. if (EditorFileSystem::get_singleton()->is_scanning()) {
  760. scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100);
  761. } else {
  762. scanning_progress->set_value(0);
  763. }
  764. }
  765. void FileSystemDock::_fw_history() {
  766. if (history_pos < history.size() - 1)
  767. history_pos++;
  768. _update_history();
  769. }
  770. void FileSystemDock::_bw_history() {
  771. if (history_pos > 0)
  772. history_pos--;
  773. _update_history();
  774. }
  775. void FileSystemDock::_update_history() {
  776. path = history[history_pos];
  777. _set_current_path_text(path);
  778. if (tree->is_visible()) {
  779. _update_tree(_compute_uncollapsed_paths());
  780. tree->grab_focus();
  781. tree->ensure_cursor_is_visible();
  782. }
  783. if (file_list_vb->is_visible()) {
  784. _update_file_list(false);
  785. }
  786. button_hist_prev->set_disabled(history_pos == 0);
  787. button_hist_next->set_disabled(history_pos == history.size() - 1);
  788. }
  789. void FileSystemDock::_push_to_history() {
  790. if (history[history_pos] != path) {
  791. history.resize(history_pos + 1);
  792. history.push_back(path);
  793. history_pos++;
  794. if (history.size() > history_max_size) {
  795. history.remove(0);
  796. history_pos = history_max_size - 1;
  797. }
  798. }
  799. button_hist_prev->set_disabled(history_pos == 0);
  800. button_hist_next->set_disabled(history_pos == history.size() - 1);
  801. }
  802. void FileSystemDock::_get_all_items_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files, Vector<String> &folders) const {
  803. if (efsd == NULL)
  804. return;
  805. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  806. folders.push_back(efsd->get_subdir(i)->get_path());
  807. _get_all_items_in_dir(efsd->get_subdir(i), files, folders);
  808. }
  809. for (int i = 0; i < efsd->get_file_count(); i++) {
  810. files.push_back(efsd->get_file_path(i));
  811. }
  812. }
  813. void FileSystemDock::_find_remaps(EditorFileSystemDirectory *efsd, const Map<String, String> &renames, Vector<String> &to_remaps) const {
  814. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  815. _find_remaps(efsd->get_subdir(i), renames, to_remaps);
  816. }
  817. for (int i = 0; i < efsd->get_file_count(); i++) {
  818. Vector<String> deps = efsd->get_file_deps(i);
  819. for (int j = 0; j < deps.size(); j++) {
  820. if (renames.has(deps[j])) {
  821. to_remaps.push_back(efsd->get_file_path(i));
  822. break;
  823. }
  824. }
  825. }
  826. }
  827. void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_new_path,
  828. Map<String, String> &p_file_renames, Map<String, String> &p_folder_renames) {
  829. // Ensure folder paths end with "/".
  830. String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/");
  831. String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/");
  832. if (new_path == old_path) {
  833. return;
  834. } else if (old_path == "res://") {
  835. EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root."));
  836. return;
  837. } else if (!p_item.is_file && new_path.begins_with(old_path)) {
  838. // This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/".
  839. EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.") + "\n" + old_path + "\n");
  840. return;
  841. }
  842. // Build a list of files which will have new paths as a result of this operation.
  843. Vector<String> file_changed_paths;
  844. Vector<String> folder_changed_paths;
  845. if (p_item.is_file) {
  846. file_changed_paths.push_back(old_path);
  847. } else {
  848. folder_changed_paths.push_back(old_path);
  849. _get_all_items_in_dir(EditorFileSystem::get_singleton()->get_filesystem_path(old_path), file_changed_paths, folder_changed_paths);
  850. }
  851. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  852. print_verbose("Moving " + old_path + " -> " + new_path);
  853. Error err = da->rename(old_path, new_path);
  854. if (err == OK) {
  855. // Move/Rename any corresponding import settings too.
  856. if (p_item.is_file && FileAccess::exists(old_path + ".import")) {
  857. err = da->rename(old_path + ".import", new_path + ".import");
  858. if (err != OK) {
  859. EditorNode::get_singleton()->add_io_error(TTR("Error moving:") + "\n" + old_path + ".import\n");
  860. }
  861. }
  862. // Update scene if it is open.
  863. for (int i = 0; i < file_changed_paths.size(); ++i) {
  864. String new_item_path = p_item.is_file ? new_path : file_changed_paths[i].replace_first(old_path, new_path);
  865. if (ResourceLoader::get_resource_type(new_item_path) == "PackedScene" && editor->is_scene_open(file_changed_paths[i])) {
  866. EditorData *ed = &editor->get_editor_data();
  867. for (int j = 0; j < ed->get_edited_scene_count(); j++) {
  868. if (ed->get_scene_path(j) == file_changed_paths[i]) {
  869. ed->get_edited_scene_root(j)->set_filename(new_item_path);
  870. editor->save_layout();
  871. break;
  872. }
  873. }
  874. }
  875. }
  876. // Only treat as a changed dependency if it was successfully moved.
  877. for (int i = 0; i < file_changed_paths.size(); ++i) {
  878. p_file_renames[file_changed_paths[i]] = file_changed_paths[i].replace_first(old_path, new_path);
  879. print_verbose(" Remap: " + file_changed_paths[i] + " -> " + p_file_renames[file_changed_paths[i]]);
  880. emit_signal("files_moved", file_changed_paths[i], p_file_renames[file_changed_paths[i]]);
  881. }
  882. for (int i = 0; i < folder_changed_paths.size(); ++i) {
  883. p_folder_renames[folder_changed_paths[i]] = folder_changed_paths[i].replace_first(old_path, new_path);
  884. emit_signal("folder_moved", folder_changed_paths[i], p_folder_renames[folder_changed_paths[i]].substr(0, p_folder_renames[folder_changed_paths[i]].length() - 1));
  885. }
  886. } else {
  887. EditorNode::get_singleton()->add_io_error(TTR("Error moving:") + "\n" + old_path + "\n");
  888. }
  889. memdelete(da);
  890. }
  891. void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const {
  892. // Ensure folder paths end with "/".
  893. String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/");
  894. String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/");
  895. if (new_path == old_path) {
  896. return;
  897. } else if (old_path == "res://") {
  898. EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root."));
  899. return;
  900. } else if (!p_item.is_file && new_path.begins_with(old_path)) {
  901. // This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/".
  902. EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.") + "\n" + old_path + "\n");
  903. return;
  904. }
  905. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  906. print_verbose("Duplicating " + old_path + " -> " + new_path);
  907. Error err = p_item.is_file ? da->copy(old_path, new_path) : da->copy_dir(old_path, new_path);
  908. if (err == OK) {
  909. // Move/Rename any corresponding import settings too.
  910. if (p_item.is_file && FileAccess::exists(old_path + ".import")) {
  911. err = da->copy(old_path + ".import", new_path + ".import");
  912. if (err != OK) {
  913. EditorNode::get_singleton()->add_io_error(TTR("Error duplicating:") + "\n" + old_path + ".import\n");
  914. }
  915. }
  916. } else {
  917. EditorNode::get_singleton()->add_io_error(TTR("Error duplicating:") + "\n" + old_path + "\n");
  918. }
  919. memdelete(da);
  920. }
  921. void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> &p_renames) const {
  922. // Rename all resources loaded, be it subresources or actual resources.
  923. List<Ref<Resource> > cached;
  924. ResourceCache::get_cached_resources(&cached);
  925. for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
  926. Ref<Resource> r = E->get();
  927. String base_path = r->get_path();
  928. String extra_path;
  929. int sep_pos = r->get_path().find("::");
  930. if (sep_pos >= 0) {
  931. extra_path = base_path.substr(sep_pos, base_path.length());
  932. base_path = base_path.substr(0, sep_pos);
  933. }
  934. if (p_renames.has(base_path)) {
  935. base_path = p_renames[base_path];
  936. }
  937. r->set_path(base_path + extra_path);
  938. }
  939. for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
  940. String path;
  941. if (i == EditorNode::get_editor_data().get_edited_scene()) {
  942. if (!get_tree()->get_edited_scene_root())
  943. continue;
  944. path = get_tree()->get_edited_scene_root()->get_filename();
  945. } else {
  946. path = EditorNode::get_editor_data().get_scene_path(i);
  947. }
  948. if (p_renames.has(path)) {
  949. path = p_renames[path];
  950. }
  951. if (i == EditorNode::get_editor_data().get_edited_scene()) {
  952. get_tree()->get_edited_scene_root()->set_filename(path);
  953. } else {
  954. EditorNode::get_editor_data().set_scene_path(i, path);
  955. }
  956. }
  957. }
  958. void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &p_renames) const {
  959. // The following code assumes that the following holds:
  960. // 1) EditorFileSystem contains the old paths/folder structure from before the rename/move.
  961. // 2) ResourceLoader can use the new paths without needing to call rescan.
  962. Vector<String> remaps;
  963. _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps);
  964. for (int i = 0; i < remaps.size(); ++i) {
  965. // Because we haven't called a rescan yet the found remap might still be an old path itself.
  966. String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i];
  967. print_verbose("Remapping dependencies for: " + file);
  968. Error err = ResourceLoader::rename_dependencies(file, p_renames);
  969. if (err == OK) {
  970. if (ResourceLoader::get_resource_type(file) == "PackedScene")
  971. editor->reload_scene(file);
  972. } else {
  973. EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + remaps[i] + "\n");
  974. }
  975. }
  976. }
  977. void FileSystemDock::_update_project_settings_after_move(const Map<String, String> &p_renames) const {
  978. // Find all project settings of type FILE and replace them if needed.
  979. const Map<StringName, PropertyInfo> prop_info = ProjectSettings::get_singleton()->get_custom_property_info();
  980. for (const Map<StringName, PropertyInfo>::Element *E = prop_info.front(); E; E = E->next()) {
  981. if (E->get().hint == PROPERTY_HINT_FILE) {
  982. String old_path = GLOBAL_GET(E->key());
  983. if (p_renames.has(old_path)) {
  984. ProjectSettings::get_singleton()->set_setting(E->key(), p_renames[old_path]);
  985. }
  986. };
  987. }
  988. // Also search for the file in autoload, as they are stored differently from normal files.
  989. List<PropertyInfo> property_list;
  990. ProjectSettings::get_singleton()->get_property_list(&property_list);
  991. for (const List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
  992. if (E->get().name.begins_with("autoload/")) {
  993. // If the autoload resource paths has a leading "*", it indicates that it is a Singleton,
  994. // so we have to handle both cases when updating.
  995. String autoload = GLOBAL_GET(E->get().name);
  996. String autoload_singleton = autoload.substr(1, autoload.length());
  997. if (p_renames.has(autoload)) {
  998. ProjectSettings::get_singleton()->set_setting(E->get().name, p_renames[autoload]);
  999. } else if (autoload.begins_with("*") && p_renames.has(autoload_singleton)) {
  1000. ProjectSettings::get_singleton()->set_setting(E->get().name, "*" + p_renames[autoload_singleton]);
  1001. }
  1002. }
  1003. }
  1004. ProjectSettings::get_singleton()->save();
  1005. }
  1006. void FileSystemDock::_update_favorites_list_after_move(const Map<String, String> &p_files_renames, const Map<String, String> &p_folders_renames) const {
  1007. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
  1008. Vector<String> new_favorites;
  1009. for (int i = 0; i < favorites.size(); i++) {
  1010. String old_path = favorites[i];
  1011. if (p_folders_renames.has(old_path)) {
  1012. new_favorites.push_back(p_folders_renames[old_path]);
  1013. } else if (p_files_renames.has(old_path)) {
  1014. new_favorites.push_back(p_files_renames[old_path]);
  1015. } else {
  1016. new_favorites.push_back(old_path);
  1017. }
  1018. }
  1019. EditorSettings::get_singleton()->set_favorites(new_favorites);
  1020. }
  1021. void FileSystemDock::_save_scenes_after_move(const Map<String, String> &p_renames) const {
  1022. Vector<String> remaps;
  1023. _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps);
  1024. Vector<String> new_filenames;
  1025. for (int i = 0; i < remaps.size(); ++i) {
  1026. String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i];
  1027. if (ResourceLoader::get_resource_type(file) == "PackedScene") {
  1028. new_filenames.push_back(file);
  1029. }
  1030. }
  1031. editor->save_scene_list(new_filenames);
  1032. }
  1033. void FileSystemDock::_make_dir_confirm() {
  1034. String dir_name = make_dir_dialog_text->get_text().strip_edges();
  1035. if (dir_name.length() == 0) {
  1036. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  1037. return;
  1038. } else if (dir_name.find("/") != -1 || dir_name.find("\\") != -1 || dir_name.find(":") != -1 || dir_name.find("*") != -1 ||
  1039. dir_name.find("|") != -1 || dir_name.find(">") != -1 || dir_name.ends_with(".") || dir_name.ends_with(" ")) {
  1040. EditorNode::get_singleton()->show_warning(TTR("Provided name contains invalid characters."));
  1041. return;
  1042. }
  1043. String directory = path;
  1044. if (!directory.ends_with("/")) {
  1045. directory = directory.get_base_dir();
  1046. }
  1047. print_verbose("Making folder " + dir_name + " in " + directory);
  1048. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1049. Error err = da->change_dir(directory);
  1050. if (err == OK) {
  1051. err = da->make_dir(dir_name);
  1052. }
  1053. memdelete(da);
  1054. if (err == OK) {
  1055. print_verbose("FileSystem: calling rescan.");
  1056. _rescan();
  1057. } else {
  1058. EditorNode::get_singleton()->show_warning(TTR("Could not create folder."));
  1059. }
  1060. }
  1061. void FileSystemDock::_make_scene_confirm() {
  1062. String scene_name = make_scene_dialog_text->get_text().strip_edges();
  1063. if (scene_name.length() == 0) {
  1064. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  1065. return;
  1066. }
  1067. String directory = path;
  1068. if (!directory.ends_with("/")) {
  1069. directory = directory.get_base_dir();
  1070. }
  1071. String extension = scene_name.get_extension();
  1072. List<String> extensions;
  1073. Ref<PackedScene> sd = memnew(PackedScene);
  1074. ResourceSaver::get_recognized_extensions(sd, &extensions);
  1075. bool extension_correct = false;
  1076. for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
  1077. if (E->get() == extension) {
  1078. extension_correct = true;
  1079. break;
  1080. }
  1081. }
  1082. if (!extension_correct)
  1083. scene_name = scene_name.get_basename() + ".tscn";
  1084. scene_name = directory.plus_file(scene_name);
  1085. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1086. if (da->file_exists(scene_name)) {
  1087. EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
  1088. memdelete(da);
  1089. return;
  1090. }
  1091. memdelete(da);
  1092. int idx = editor->new_scene();
  1093. editor->get_editor_data().set_scene_path(idx, scene_name);
  1094. }
  1095. void FileSystemDock::_file_deleted(String p_file) {
  1096. emit_signal("file_deleted", p_file);
  1097. }
  1098. void FileSystemDock::_folder_deleted(String p_folder) {
  1099. emit_signal("folder_deleted", p_folder);
  1100. }
  1101. void FileSystemDock::_rename_operation_confirm() {
  1102. String new_name = rename_dialog_text->get_text().strip_edges();
  1103. if (new_name.length() == 0) {
  1104. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  1105. return;
  1106. } else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
  1107. EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
  1108. return;
  1109. }
  1110. String old_path = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1) : to_rename.path;
  1111. String new_path = old_path.get_base_dir().plus_file(new_name);
  1112. if (old_path == new_path) {
  1113. return;
  1114. }
  1115. if (EditorFileSystem::get_singleton()->is_group_file(old_path)) {
  1116. EditorFileSystem::get_singleton()->move_group_file(old_path, new_path);
  1117. }
  1118. // Present a more user friendly warning for name conflict.
  1119. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1120. #if defined(WINDOWS_ENABLED) || defined(UWP_ENABLED)
  1121. // Workaround case insensitivity on Windows.
  1122. if ((da->file_exists(new_path) || da->dir_exists(new_path)) && new_path.to_lower() != old_path.to_lower()) {
  1123. #else
  1124. if (da->file_exists(new_path) || da->dir_exists(new_path)) {
  1125. #endif
  1126. EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
  1127. memdelete(da);
  1128. return;
  1129. }
  1130. memdelete(da);
  1131. Map<String, String> file_renames;
  1132. Map<String, String> folder_renames;
  1133. _try_move_item(to_rename, new_path, file_renames, folder_renames);
  1134. int current_tab = editor->get_current_tab();
  1135. _save_scenes_after_move(file_renames); // save scenes before updating
  1136. _update_dependencies_after_move(file_renames);
  1137. _update_resource_paths_after_move(file_renames);
  1138. _update_project_settings_after_move(file_renames);
  1139. _update_favorites_list_after_move(file_renames, folder_renames);
  1140. editor->set_current_tab(current_tab);
  1141. print_verbose("FileSystem: calling rescan.");
  1142. _rescan();
  1143. print_verbose("FileSystem: saving moved scenes.");
  1144. _save_scenes_after_move(file_renames);
  1145. }
  1146. void FileSystemDock::_duplicate_operation_confirm() {
  1147. String new_name = duplicate_dialog_text->get_text().strip_edges();
  1148. if (new_name.length() == 0) {
  1149. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  1150. return;
  1151. } else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
  1152. EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
  1153. return;
  1154. }
  1155. String base_dir = to_duplicate.path.get_base_dir();
  1156. // get_base_dir() returns "some/path" if the original path was "some/path/", so work it around.
  1157. if (to_duplicate.path.ends_with("/")) {
  1158. base_dir = base_dir.get_base_dir();
  1159. }
  1160. String new_path = base_dir.plus_file(new_name);
  1161. // Present a more user friendly warning for name conflict
  1162. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1163. if (da->file_exists(new_path) || da->dir_exists(new_path)) {
  1164. EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
  1165. memdelete(da);
  1166. return;
  1167. }
  1168. memdelete(da);
  1169. _try_duplicate_item(to_duplicate, new_path);
  1170. // Rescan everything.
  1171. print_verbose("FileSystem: calling rescan.");
  1172. _rescan();
  1173. }
  1174. void FileSystemDock::_move_with_overwrite() {
  1175. _move_operation_confirm(to_move_path, true);
  1176. }
  1177. bool FileSystemDock::_check_existing() {
  1178. String &p_to_path = to_move_path;
  1179. for (int i = 0; i < to_move.size(); i++) {
  1180. String ol_pth = to_move[i].path.ends_with("/") ? to_move[i].path.substr(0, to_move[i].path.length() - 1) : to_move[i].path;
  1181. String p_new_path = p_to_path.plus_file(ol_pth.get_file());
  1182. FileOrFolder p_item = to_move[i];
  1183. String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/");
  1184. String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/");
  1185. if (p_item.is_file && FileAccess::exists(new_path)) {
  1186. return false;
  1187. } else if (!p_item.is_file && DirAccess::exists(new_path)) {
  1188. return false;
  1189. }
  1190. }
  1191. return true;
  1192. }
  1193. void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overwrite) {
  1194. if (!overwrite) {
  1195. to_move_path = p_to_path;
  1196. bool can_move = _check_existing();
  1197. if (!can_move) {
  1198. // Ask to do something.
  1199. overwrite_dialog->popup_centered_minsize();
  1200. overwrite_dialog->grab_focus();
  1201. return;
  1202. }
  1203. }
  1204. // Check groups.
  1205. for (int i = 0; i < to_move.size(); i++) {
  1206. print_line("is group: " + to_move[i].path + ": " + itos(EditorFileSystem::get_singleton()->is_group_file(to_move[i].path)));
  1207. if (to_move[i].is_file && EditorFileSystem::get_singleton()->is_group_file(to_move[i].path)) {
  1208. print_line("move to: " + p_to_path.plus_file(to_move[i].path.get_file()));
  1209. EditorFileSystem::get_singleton()->move_group_file(to_move[i].path, p_to_path.plus_file(to_move[i].path.get_file()));
  1210. }
  1211. }
  1212. Map<String, String> file_renames;
  1213. Map<String, String> folder_renames;
  1214. bool is_moved = false;
  1215. for (int i = 0; i < to_move.size(); i++) {
  1216. String old_path = to_move[i].path.ends_with("/") ? to_move[i].path.substr(0, to_move[i].path.length() - 1) : to_move[i].path;
  1217. String new_path = p_to_path.plus_file(old_path.get_file());
  1218. if (old_path != new_path) {
  1219. _try_move_item(to_move[i], new_path, file_renames, folder_renames);
  1220. is_moved = true;
  1221. }
  1222. }
  1223. if (is_moved) {
  1224. int current_tab = editor->get_current_tab();
  1225. _save_scenes_after_move(file_renames); //save scenes before updating
  1226. _update_dependencies_after_move(file_renames);
  1227. _update_resource_paths_after_move(file_renames);
  1228. _update_project_settings_after_move(file_renames);
  1229. _update_favorites_list_after_move(file_renames, folder_renames);
  1230. editor->set_current_tab(current_tab);
  1231. print_verbose("FileSystem: calling rescan.");
  1232. _rescan();
  1233. print_verbose("FileSystem: saving moved scenes.");
  1234. _save_scenes_after_move(file_renames);
  1235. }
  1236. }
  1237. Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) {
  1238. // Build a list of selected items with the active one at the first position.
  1239. Vector<String> selected_strings;
  1240. TreeItem *favorites_item = tree->get_root()->get_children();
  1241. TreeItem *active_selected = tree->get_selected();
  1242. if (active_selected && active_selected != favorites_item) {
  1243. selected_strings.push_back(active_selected->get_metadata(0));
  1244. }
  1245. TreeItem *selected = tree->get_root();
  1246. selected = tree->get_next_selected(selected);
  1247. while (selected) {
  1248. if (selected != active_selected && selected != favorites_item) {
  1249. selected_strings.push_back(selected->get_metadata(0));
  1250. }
  1251. selected = tree->get_next_selected(selected);
  1252. }
  1253. if (remove_self_inclusion) {
  1254. selected_strings = _remove_self_included_paths(selected_strings);
  1255. }
  1256. return selected_strings;
  1257. }
  1258. Vector<String> FileSystemDock::_remove_self_included_paths(Vector<String> selected_strings) {
  1259. // Remove paths or files that are included into another.
  1260. if (selected_strings.size() > 1) {
  1261. selected_strings.sort_custom<NaturalNoCaseComparator>();
  1262. String last_path = "";
  1263. for (int i = 0; i < selected_strings.size(); i++) {
  1264. if (last_path != "" && selected_strings[i].begins_with(last_path)) {
  1265. selected_strings.remove(i);
  1266. i--;
  1267. }
  1268. if (selected_strings[i].ends_with("/")) {
  1269. last_path = selected_strings[i];
  1270. }
  1271. }
  1272. }
  1273. return selected_strings;
  1274. }
  1275. void FileSystemDock::_tree_rmb_option(int p_option) {
  1276. Vector<String> selected_strings = _tree_get_selected(false);
  1277. // Execute the current option.
  1278. switch (p_option) {
  1279. case FOLDER_EXPAND_ALL:
  1280. case FOLDER_COLLAPSE_ALL: {
  1281. // Expand or collapse the folder
  1282. if (selected_strings.size() == 1) {
  1283. bool is_collapsed = (p_option == FOLDER_COLLAPSE_ALL);
  1284. Vector<TreeItem *> needs_check;
  1285. needs_check.push_back(tree->get_selected());
  1286. while (needs_check.size()) {
  1287. needs_check[0]->set_collapsed(is_collapsed);
  1288. TreeItem *child = needs_check[0]->get_children();
  1289. while (child) {
  1290. needs_check.push_back(child);
  1291. child = child->get_next();
  1292. }
  1293. needs_check.remove(0);
  1294. }
  1295. }
  1296. } break;
  1297. default: {
  1298. _file_option(p_option, selected_strings);
  1299. } break;
  1300. }
  1301. }
  1302. void FileSystemDock::_file_list_rmb_option(int p_option) {
  1303. Vector<int> selected_id = files->get_selected_items();
  1304. Vector<String> selected;
  1305. for (int i = 0; i < selected_id.size(); i++) {
  1306. selected.push_back(files->get_item_metadata(selected_id[i]));
  1307. }
  1308. _file_option(p_option, selected);
  1309. }
  1310. void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected) {
  1311. // The first one should be the active item.
  1312. switch (p_option) {
  1313. case FILE_SHOW_IN_EXPLORER: {
  1314. // Show the file/folder in the OS explorer.
  1315. String fpath = path;
  1316. if (path == "Favorites") {
  1317. fpath = p_selected[0];
  1318. }
  1319. if (!fpath.ends_with("/")) {
  1320. fpath = fpath.get_base_dir();
  1321. }
  1322. String dir = ProjectSettings::get_singleton()->globalize_path(fpath);
  1323. OS::get_singleton()->shell_open(String("file://") + dir);
  1324. } break;
  1325. case FILE_OPEN: {
  1326. // Open folders.
  1327. TreeItem *selected = tree->get_root();
  1328. selected = tree->get_next_selected(selected);
  1329. while (selected) {
  1330. if (p_selected.find(selected->get_metadata(0)) >= 0) {
  1331. selected->set_collapsed(false);
  1332. }
  1333. selected = tree->get_next_selected(selected);
  1334. }
  1335. // Open the file.
  1336. for (int i = 0; i < p_selected.size(); i++) {
  1337. _select_file(p_selected[i]);
  1338. }
  1339. } break;
  1340. case FILE_INHERIT: {
  1341. // Create a new scene inherited from the selected one.
  1342. if (p_selected.size() == 1) {
  1343. emit_signal("inherit", p_selected[0]);
  1344. }
  1345. } break;
  1346. case FILE_MAIN_SCENE: {
  1347. // Set as main scene with selected scene file.
  1348. if (p_selected.size() == 1) {
  1349. ProjectSettings::get_singleton()->set("application/run/main_scene", p_selected[0]);
  1350. ProjectSettings::get_singleton()->save();
  1351. _update_tree(_compute_uncollapsed_paths());
  1352. }
  1353. } break;
  1354. case FILE_INSTANCE: {
  1355. // Instance all selected scenes.
  1356. Vector<String> paths;
  1357. for (int i = 0; i < p_selected.size(); i++) {
  1358. String fpath = p_selected[i];
  1359. if (EditorFileSystem::get_singleton()->get_file_type(fpath) == "PackedScene") {
  1360. paths.push_back(fpath);
  1361. }
  1362. }
  1363. if (!paths.empty()) {
  1364. emit_signal("instance", paths);
  1365. }
  1366. } break;
  1367. case FILE_ADD_FAVORITE: {
  1368. // Add the files from favorites.
  1369. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
  1370. for (int i = 0; i < p_selected.size(); i++) {
  1371. if (favorites.find(p_selected[i]) == -1) {
  1372. favorites.push_back(p_selected[i]);
  1373. }
  1374. }
  1375. EditorSettings::get_singleton()->set_favorites(favorites);
  1376. _update_tree(_compute_uncollapsed_paths());
  1377. } break;
  1378. case FILE_REMOVE_FAVORITE: {
  1379. // Remove the files from favorites.
  1380. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
  1381. for (int i = 0; i < p_selected.size(); i++) {
  1382. favorites.erase(p_selected[i]);
  1383. }
  1384. EditorSettings::get_singleton()->set_favorites(favorites);
  1385. _update_tree(_compute_uncollapsed_paths());
  1386. if (path == "Favorites")
  1387. _update_file_list(true);
  1388. } break;
  1389. case FILE_DEPENDENCIES: {
  1390. // Checkout the file dependencies.
  1391. if (!p_selected.empty()) {
  1392. String fpath = p_selected[0];
  1393. deps_editor->edit(fpath);
  1394. }
  1395. } break;
  1396. case FILE_OWNERS: {
  1397. // Checkout the file owners.
  1398. if (!p_selected.empty()) {
  1399. String fpath = p_selected[0];
  1400. owners_editor->show(fpath);
  1401. }
  1402. } break;
  1403. case FILE_MOVE: {
  1404. // Move the files to a given location.
  1405. to_move.clear();
  1406. Vector<String> collapsed_paths = _remove_self_included_paths(p_selected);
  1407. for (int i = collapsed_paths.size() - 1; i >= 0; i--) {
  1408. String fpath = collapsed_paths[i];
  1409. if (fpath != "res://") {
  1410. to_move.push_back(FileOrFolder(fpath, !fpath.ends_with("/")));
  1411. }
  1412. }
  1413. if (to_move.size() > 0) {
  1414. move_dialog->popup_centered_ratio();
  1415. }
  1416. } break;
  1417. case FILE_RENAME: {
  1418. // Rename the active file.
  1419. if (!p_selected.empty()) {
  1420. to_rename.path = p_selected[0];
  1421. if (to_rename.path != "res://") {
  1422. to_rename.is_file = !to_rename.path.ends_with("/");
  1423. if (to_rename.is_file) {
  1424. String name = to_rename.path.get_file();
  1425. rename_dialog->set_title(TTR("Renaming file:") + " " + name);
  1426. rename_dialog_text->set_text(name);
  1427. rename_dialog_text->select(0, name.find_last("."));
  1428. } else {
  1429. String name = to_rename.path.substr(0, to_rename.path.length() - 1).get_file();
  1430. rename_dialog->set_title(TTR("Renaming folder:") + " " + name);
  1431. rename_dialog_text->set_text(name);
  1432. rename_dialog_text->select(0, name.length());
  1433. }
  1434. rename_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  1435. rename_dialog_text->grab_focus();
  1436. }
  1437. }
  1438. } break;
  1439. case FILE_REMOVE: {
  1440. // Remove the selected files.
  1441. Vector<String> remove_files;
  1442. Vector<String> remove_folders;
  1443. Vector<String> collapsed_paths = _remove_self_included_paths(p_selected);
  1444. for (int i = 0; i < collapsed_paths.size(); i++) {
  1445. String fpath = collapsed_paths[i];
  1446. if (fpath != "res://") {
  1447. if (fpath.ends_with("/")) {
  1448. remove_folders.push_back(fpath);
  1449. } else {
  1450. remove_files.push_back(fpath);
  1451. }
  1452. }
  1453. }
  1454. if (remove_files.size() + remove_folders.size() > 0) {
  1455. remove_dialog->show(remove_folders, remove_files);
  1456. }
  1457. } break;
  1458. case FILE_DUPLICATE: {
  1459. // Duplicate the selected files.
  1460. for (int i = 0; i < p_selected.size(); i++) {
  1461. to_duplicate.path = p_selected[i];
  1462. to_duplicate.is_file = !to_duplicate.path.ends_with("/");
  1463. if (to_duplicate.is_file) {
  1464. String name = to_duplicate.path.get_file();
  1465. duplicate_dialog->set_title(TTR("Duplicating file:") + " " + name);
  1466. duplicate_dialog_text->set_text(name);
  1467. duplicate_dialog_text->select(0, name.find_last("."));
  1468. } else {
  1469. String name = to_duplicate.path.substr(0, to_duplicate.path.length() - 1).get_file();
  1470. duplicate_dialog->set_title(TTR("Duplicating folder:") + " " + name);
  1471. duplicate_dialog_text->set_text(name);
  1472. duplicate_dialog_text->select(0, name.length());
  1473. }
  1474. duplicate_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  1475. duplicate_dialog_text->grab_focus();
  1476. }
  1477. } break;
  1478. case FILE_INFO: {
  1479. } break;
  1480. case FILE_REIMPORT: {
  1481. // Reimport all selected files.
  1482. Vector<String> reimport;
  1483. for (int i = 0; i < p_selected.size(); i++) {
  1484. reimport.push_back(p_selected[i]);
  1485. }
  1486. ERR_FAIL_COND_MSG(reimport.size() == 0, "You need to select files to reimport them.");
  1487. } break;
  1488. case FILE_NEW_FOLDER: {
  1489. make_dir_dialog_text->set_text("new folder");
  1490. make_dir_dialog_text->select_all();
  1491. make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  1492. make_dir_dialog_text->grab_focus();
  1493. } break;
  1494. case FILE_NEW_SCENE: {
  1495. make_scene_dialog_text->set_text("new scene");
  1496. make_scene_dialog_text->select_all();
  1497. make_scene_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  1498. make_scene_dialog_text->grab_focus();
  1499. } break;
  1500. case FILE_NEW_SCRIPT: {
  1501. String fpath = path;
  1502. if (!fpath.ends_with("/")) {
  1503. fpath = fpath.get_base_dir();
  1504. }
  1505. make_script_dialog_text->config("Node", fpath.plus_file("new_script.gd"), false);
  1506. make_script_dialog_text->popup_centered(Size2(300, 300) * EDSCALE);
  1507. } break;
  1508. case FILE_COPY_PATH: {
  1509. if (!p_selected.empty()) {
  1510. String fpath = p_selected[0];
  1511. OS::get_singleton()->set_clipboard(fpath);
  1512. }
  1513. } break;
  1514. case FILE_NEW_RESOURCE: {
  1515. new_resource_dialog->popup_create(true);
  1516. } break;
  1517. }
  1518. }
  1519. void FileSystemDock::_resource_created() const {
  1520. Object *c = new_resource_dialog->instance_selected();
  1521. ERR_FAIL_COND(!c);
  1522. Resource *r = Object::cast_to<Resource>(c);
  1523. ERR_FAIL_COND(!r);
  1524. REF res(r);
  1525. editor->push_item(c);
  1526. RES current_res = RES(r);
  1527. String fpath = path;
  1528. if (!fpath.ends_with("/")) {
  1529. fpath = fpath.get_base_dir();
  1530. }
  1531. editor->save_resource_as(current_res, fpath);
  1532. }
  1533. void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) {
  1534. if (searched_string.length() == 0 && p_text.length() > 0) {
  1535. // Register the uncollapsed paths before they change.
  1536. uncollapsed_paths_before_search = _compute_uncollapsed_paths();
  1537. }
  1538. searched_string = p_text.to_lower();
  1539. if (p_from == tree_search_box)
  1540. file_list_search_box->set_text(searched_string);
  1541. else // File_list_search_box.
  1542. tree_search_box->set_text(searched_string);
  1543. switch (display_mode) {
  1544. case DISPLAY_MODE_TREE_ONLY: {
  1545. _update_tree(searched_string.length() == 0 ? uncollapsed_paths_before_search : Vector<String>());
  1546. } break;
  1547. case DISPLAY_MODE_SPLIT: {
  1548. _update_file_list(false);
  1549. _update_tree(searched_string.length() == 0 ? uncollapsed_paths_before_search : Vector<String>());
  1550. } break;
  1551. }
  1552. }
  1553. void FileSystemDock::_rescan() {
  1554. _set_scanning_mode();
  1555. EditorFileSystem::get_singleton()->scan();
  1556. }
  1557. void FileSystemDock::_toggle_split_mode(bool p_active) {
  1558. set_display_mode(p_active ? DISPLAY_MODE_SPLIT : DISPLAY_MODE_TREE_ONLY);
  1559. emit_signal("display_mode_changed");
  1560. }
  1561. void FileSystemDock::fix_dependencies(const String &p_for_file) {
  1562. deps_editor->edit(p_for_file);
  1563. }
  1564. void FileSystemDock::focus_on_filter() {
  1565. file_list_search_box->grab_focus();
  1566. }
  1567. void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) {
  1568. if (p_mode == file_list_display_mode)
  1569. return;
  1570. _toggle_file_display();
  1571. }
  1572. Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  1573. bool all_favorites = true;
  1574. bool all_not_favorites = true;
  1575. Vector<String> paths;
  1576. if (p_from == tree) {
  1577. // Check if the first selected is in favorite.
  1578. TreeItem *selected = tree->get_next_selected(tree->get_root());
  1579. while (selected) {
  1580. TreeItem *favorites_item = tree->get_root()->get_children();
  1581. if (selected == favorites_item) {
  1582. // The "Favorites" item is not draggable.
  1583. return Variant();
  1584. }
  1585. bool is_favorite = selected->get_parent() != NULL && tree->get_root()->get_children() == selected->get_parent();
  1586. all_favorites &= is_favorite;
  1587. all_not_favorites &= !is_favorite;
  1588. selected = tree->get_next_selected(selected);
  1589. }
  1590. if (!all_not_favorites) {
  1591. paths = _tree_get_selected(false);
  1592. } else {
  1593. paths = _tree_get_selected();
  1594. }
  1595. } else if (p_from == files) {
  1596. for (int i = 0; i < files->get_item_count(); i++) {
  1597. if (files->is_selected(i)) {
  1598. paths.push_back(files->get_item_metadata(i));
  1599. }
  1600. }
  1601. all_favorites = false;
  1602. all_not_favorites = true;
  1603. }
  1604. if (paths.empty())
  1605. return Variant();
  1606. Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from);
  1607. if (!all_not_favorites) {
  1608. drag_data["favorite"] = all_favorites ? "all" : "mixed";
  1609. }
  1610. return drag_data;
  1611. }
  1612. bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  1613. Dictionary drag_data = p_data;
  1614. if (drag_data.has("favorite")) {
  1615. if (String(drag_data["favorite"]) != "all") {
  1616. return false;
  1617. }
  1618. // Moving favorite around.
  1619. TreeItem *ti = tree->get_item_at_position(p_point);
  1620. if (!ti)
  1621. return false;
  1622. int drop_section = tree->get_drop_section_at_position(p_point);
  1623. TreeItem *favorites_item = tree->get_root()->get_children();
  1624. TreeItem *resources_item = favorites_item->get_next();
  1625. if (ti == favorites_item) {
  1626. return (drop_section == 1); // The parent, first fav.
  1627. }
  1628. if (ti->get_parent() && favorites_item == ti->get_parent()) {
  1629. return true; // A favorite
  1630. }
  1631. if (ti == resources_item) {
  1632. return (drop_section == -1); // The tree, last fav.
  1633. }
  1634. return false;
  1635. }
  1636. if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
  1637. // Move resources.
  1638. String to_dir;
  1639. bool favorite;
  1640. _get_drag_target_folder(to_dir, favorite, p_point, p_from);
  1641. return !to_dir.empty();
  1642. }
  1643. if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
  1644. // Move files or dir.
  1645. String to_dir;
  1646. bool favorite;
  1647. _get_drag_target_folder(to_dir, favorite, p_point, p_from);
  1648. if (favorite)
  1649. return true;
  1650. if (to_dir.empty())
  1651. return false;
  1652. // Attempting to move a folder into itself will fail later,
  1653. // rather than bring up a message don't try to do it in the first place
  1654. to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/");
  1655. Vector<String> fnames = drag_data["files"];
  1656. for (int i = 0; i < fnames.size(); ++i) {
  1657. if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i]))
  1658. return false;
  1659. }
  1660. return true;
  1661. }
  1662. return false;
  1663. }
  1664. void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  1665. if (!can_drop_data_fw(p_point, p_data, p_from))
  1666. return;
  1667. Dictionary drag_data = p_data;
  1668. Vector<String> dirs = EditorSettings::get_singleton()->get_favorites();
  1669. if (drag_data.has("favorite")) {
  1670. if (String(drag_data["favorite"]) != "all") {
  1671. return;
  1672. }
  1673. // Moving favorite around.
  1674. TreeItem *ti = tree->get_item_at_position(p_point);
  1675. if (!ti)
  1676. return;
  1677. int drop_section = tree->get_drop_section_at_position(p_point);
  1678. int drop_position;
  1679. Vector<String> files = drag_data["files"];
  1680. TreeItem *favorites_item = tree->get_root()->get_children();
  1681. TreeItem *resources_item = favorites_item->get_next();
  1682. if (ti == favorites_item) {
  1683. // Drop on the favorite folder.
  1684. drop_position = 0;
  1685. } else if (ti == resources_item) {
  1686. // Drop on the resource item.
  1687. drop_position = dirs.size();
  1688. } else {
  1689. // Drop in the list.
  1690. drop_position = dirs.find(ti->get_metadata(0));
  1691. if (drop_section == 1) {
  1692. drop_position++;
  1693. }
  1694. }
  1695. // Remove dragged favorites.
  1696. Vector<int> to_remove;
  1697. int offset = 0;
  1698. for (int i = 0; i < files.size(); i++) {
  1699. int to_remove_pos = dirs.find(files[i]);
  1700. to_remove.push_back(to_remove_pos);
  1701. if (to_remove_pos < drop_position) {
  1702. offset++;
  1703. }
  1704. }
  1705. drop_position -= offset;
  1706. to_remove.sort();
  1707. for (int i = 0; i < to_remove.size(); i++) {
  1708. dirs.remove(to_remove[i] - i);
  1709. }
  1710. // Re-add them at the right position.
  1711. for (int i = 0; i < files.size(); i++) {
  1712. dirs.insert(drop_position, files[i]);
  1713. drop_position++;
  1714. }
  1715. EditorSettings::get_singleton()->set_favorites(dirs);
  1716. _update_tree(_compute_uncollapsed_paths());
  1717. if (display_mode == DISPLAY_MODE_SPLIT && path == "Favorites")
  1718. _update_file_list(true);
  1719. return;
  1720. }
  1721. if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
  1722. // Moving resource.
  1723. Ref<Resource> res = drag_data["resource"];
  1724. String to_dir;
  1725. bool favorite;
  1726. _get_drag_target_folder(to_dir, favorite, p_point, p_from);
  1727. if (res.is_valid() && !to_dir.empty()) {
  1728. EditorNode::get_singleton()->push_item(res.ptr());
  1729. EditorNode::get_singleton()->save_resource_as(res, to_dir);
  1730. }
  1731. }
  1732. if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
  1733. // Move files or add to favorites.
  1734. String to_dir;
  1735. bool favorite;
  1736. _get_drag_target_folder(to_dir, favorite, p_point, p_from);
  1737. if (!to_dir.empty()) {
  1738. Vector<String> fnames = drag_data["files"];
  1739. to_move.clear();
  1740. for (int i = 0; i < fnames.size(); i++) {
  1741. to_move.push_back(FileOrFolder(fnames[i], !fnames[i].ends_with("/")));
  1742. }
  1743. _move_operation_confirm(to_dir);
  1744. } else if (favorite) {
  1745. // Add the files from favorites
  1746. Vector<String> fnames = drag_data["files"];
  1747. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
  1748. for (int i = 0; i < fnames.size(); i++) {
  1749. if (favorites.find(fnames[i]) == -1) {
  1750. favorites.push_back(fnames[i]);
  1751. }
  1752. }
  1753. EditorSettings::get_singleton()->set_favorites(favorites);
  1754. _update_tree(_compute_uncollapsed_paths());
  1755. }
  1756. }
  1757. }
  1758. void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favorites, const Point2 &p_point, Control *p_from) const {
  1759. target = String();
  1760. target_favorites = false;
  1761. // In the file list.
  1762. if (p_from == files) {
  1763. int pos = files->get_item_at_position(p_point, true);
  1764. if (pos == -1) {
  1765. return;
  1766. }
  1767. String ltarget = files->get_item_metadata(pos);
  1768. target = ltarget.ends_with("/") ? ltarget : path.get_base_dir();
  1769. return;
  1770. }
  1771. // In the tree.
  1772. if (p_from == tree) {
  1773. TreeItem *ti = tree->get_item_at_position(p_point);
  1774. int section = tree->get_drop_section_at_position(p_point);
  1775. if (ti) {
  1776. // Check the favorites first.
  1777. if (ti == tree->get_root()->get_children() && section >= 0) {
  1778. target_favorites = true;
  1779. return;
  1780. } else if (ti->get_parent() == tree->get_root()->get_children()) {
  1781. target_favorites = true;
  1782. return;
  1783. } else {
  1784. String fpath = ti->get_metadata(0);
  1785. if (section == 0) {
  1786. if (fpath.ends_with("/")) {
  1787. // We drop on a folder.
  1788. target = fpath;
  1789. return;
  1790. }
  1791. } else {
  1792. if (ti->get_parent() != tree->get_root()->get_children()) {
  1793. // Not in the favorite section.
  1794. if (fpath != "res://") {
  1795. // We drop between two files
  1796. if (fpath.ends_with("/")) {
  1797. fpath = fpath.substr(0, fpath.length() - 1);
  1798. }
  1799. target = fpath.get_base_dir();
  1800. return;
  1801. }
  1802. }
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options) {
  1809. // Add options for files and folders.
  1810. ERR_FAIL_COND_MSG(p_paths.empty(), "Path cannot be empty.");
  1811. Vector<String> filenames;
  1812. Vector<String> foldernames;
  1813. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
  1814. bool all_files = true;
  1815. bool all_files_scenes = true;
  1816. bool all_folders = true;
  1817. bool all_favorites = true;
  1818. bool all_not_favorites = true;
  1819. for (int i = 0; i < p_paths.size(); i++) {
  1820. String fpath = p_paths[i];
  1821. if (fpath.ends_with("/")) {
  1822. foldernames.push_back(fpath);
  1823. all_files = false;
  1824. } else {
  1825. filenames.push_back(fpath);
  1826. all_folders = false;
  1827. all_files_scenes &= (EditorFileSystem::get_singleton()->get_file_type(fpath) == "PackedScene");
  1828. }
  1829. // Check if in favorites.
  1830. bool found = false;
  1831. for (int j = 0; j < favorites.size(); j++) {
  1832. if (favorites[j] == fpath) {
  1833. found = true;
  1834. break;
  1835. }
  1836. }
  1837. if (found) {
  1838. all_not_favorites = false;
  1839. } else {
  1840. all_favorites = false;
  1841. }
  1842. }
  1843. if (all_files) {
  1844. if (all_files_scenes) {
  1845. if (filenames.size() == 1) {
  1846. p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open Scene"), FILE_OPEN);
  1847. p_popup->add_icon_item(get_icon("CreateNewSceneFrom", "EditorIcons"), TTR("New Inherited Scene"), FILE_INHERIT);
  1848. p_popup->add_icon_item(get_icon("PlayScene", "EditorIcons"), TTR("Set As Main Scene"), FILE_MAIN_SCENE);
  1849. } else {
  1850. p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open Scenes"), FILE_OPEN);
  1851. }
  1852. p_popup->add_icon_item(get_icon("Instance", "EditorIcons"), TTR("Instance"), FILE_INSTANCE);
  1853. p_popup->add_separator();
  1854. } else if (filenames.size() == 1) {
  1855. p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open"), FILE_OPEN);
  1856. p_popup->add_separator();
  1857. }
  1858. }
  1859. if (p_paths.size() >= 1) {
  1860. if (!all_favorites) {
  1861. p_popup->add_icon_item(get_icon("Favorites", "EditorIcons"), TTR("Add to Favorites"), FILE_ADD_FAVORITE);
  1862. }
  1863. if (!all_not_favorites) {
  1864. p_popup->add_icon_item(get_icon("NonFavorite", "EditorIcons"), TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE);
  1865. }
  1866. p_popup->add_separator();
  1867. }
  1868. if (all_files) {
  1869. if (filenames.size() == 1) {
  1870. p_popup->add_item(TTR("Edit Dependencies..."), FILE_DEPENDENCIES);
  1871. p_popup->add_item(TTR("View Owners..."), FILE_OWNERS);
  1872. p_popup->add_separator();
  1873. }
  1874. } else if (all_folders && foldernames.size() > 0) {
  1875. p_popup->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open"), FILE_OPEN);
  1876. p_popup->add_separator();
  1877. }
  1878. if (p_paths.size() == 1) {
  1879. p_popup->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Path"), FILE_COPY_PATH);
  1880. if (p_paths[0] != "res://") {
  1881. p_popup->add_icon_item(get_icon("Rename", "EditorIcons"), TTR("Rename..."), FILE_RENAME);
  1882. p_popup->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Duplicate..."), FILE_DUPLICATE);
  1883. }
  1884. }
  1885. if (p_paths.size() > 1 || p_paths[0] != "res://") {
  1886. p_popup->add_icon_item(get_icon("MoveUp", "EditorIcons"), TTR("Move To..."), FILE_MOVE);
  1887. p_popup->add_icon_item(get_icon("Remove", "EditorIcons"), TTR("Delete"), FILE_REMOVE);
  1888. }
  1889. if (p_paths.size() == 1) {
  1890. p_popup->add_separator();
  1891. if (p_display_path_dependent_options) {
  1892. p_popup->add_icon_item(get_icon("Folder", "EditorIcons"), TTR("New Folder..."), FILE_NEW_FOLDER);
  1893. p_popup->add_icon_item(get_icon("PackedScene", "EditorIcons"), TTR("New Scene..."), FILE_NEW_SCENE);
  1894. p_popup->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script..."), FILE_NEW_SCRIPT);
  1895. p_popup->add_icon_item(get_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE);
  1896. p_popup->add_separator();
  1897. }
  1898. String fpath = p_paths[0];
  1899. String item_text = fpath.ends_with("/") ? TTR("Open in File Manager") : TTR("Show in File Manager");
  1900. p_popup->add_icon_item(get_icon("Filesystem", "EditorIcons"), item_text, FILE_SHOW_IN_EXPLORER);
  1901. }
  1902. }
  1903. void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) {
  1904. // Right click is pressed in the tree.
  1905. Vector<String> paths = _tree_get_selected(false);
  1906. if (paths.size() == 1) {
  1907. if (paths[0].ends_with("/")) {
  1908. tree_popup->add_icon_item(get_icon("GuiTreeArrowDown", "EditorIcons"), TTR("Expand All"), FOLDER_EXPAND_ALL);
  1909. tree_popup->add_icon_item(get_icon("GuiTreeArrowRight", "EditorIcons"), TTR("Collapse All"), FOLDER_COLLAPSE_ALL);
  1910. tree_popup->add_separator();
  1911. }
  1912. }
  1913. // Popup.
  1914. if (!paths.empty()) {
  1915. tree_popup->clear();
  1916. tree_popup->set_size(Size2(1, 1));
  1917. _file_and_folders_fill_popup(tree_popup, paths);
  1918. tree_popup->set_position(tree->get_global_position() + p_pos);
  1919. tree_popup->popup();
  1920. }
  1921. }
  1922. void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) {
  1923. // Right click is pressed in the empty space of the tree.
  1924. path = "res://";
  1925. tree_popup->clear();
  1926. tree_popup->set_size(Size2(1, 1));
  1927. tree_popup->add_icon_item(get_icon("Folder", "EditorIcons"), TTR("New Folder..."), FILE_NEW_FOLDER);
  1928. tree_popup->add_icon_item(get_icon("PackedScene", "EditorIcons"), TTR("New Scene..."), FILE_NEW_SCENE);
  1929. tree_popup->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script..."), FILE_NEW_SCRIPT);
  1930. tree_popup->add_icon_item(get_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE);
  1931. tree_popup->set_position(tree->get_global_position() + p_pos);
  1932. tree_popup->popup();
  1933. }
  1934. void FileSystemDock::_tree_empty_selected() {
  1935. tree->deselect_all();
  1936. }
  1937. void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) {
  1938. // Right click is pressed in the file list.
  1939. Vector<String> paths;
  1940. for (int i = 0; i < files->get_item_count(); i++) {
  1941. if (!files->is_selected(i))
  1942. continue;
  1943. if (files->get_item_text(p_item) == "..") {
  1944. files->unselect(i);
  1945. continue;
  1946. }
  1947. paths.push_back(files->get_item_metadata(i));
  1948. }
  1949. // Popup.
  1950. if (!paths.empty()) {
  1951. file_list_popup->clear();
  1952. file_list_popup->set_size(Size2(1, 1));
  1953. _file_and_folders_fill_popup(file_list_popup, paths, searched_string.length() == 0);
  1954. file_list_popup->set_position(files->get_global_position() + p_pos);
  1955. file_list_popup->popup();
  1956. }
  1957. }
  1958. void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) {
  1959. // Right click on empty space for file list.
  1960. if (searched_string.length() > 0)
  1961. return;
  1962. file_list_popup->clear();
  1963. file_list_popup->set_size(Size2(1, 1));
  1964. file_list_popup->add_icon_item(get_icon("Folder", "EditorIcons"), TTR("New Folder..."), FILE_NEW_FOLDER);
  1965. file_list_popup->add_icon_item(get_icon("PackedScene", "EditorIcons"), TTR("New Scene..."), FILE_NEW_SCENE);
  1966. file_list_popup->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script..."), FILE_NEW_SCRIPT);
  1967. file_list_popup->add_icon_item(get_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE);
  1968. file_list_popup->add_separator();
  1969. file_list_popup->add_icon_item(get_icon("Filesystem", "EditorIcons"), TTR("Open in File Manager"), FILE_SHOW_IN_EXPLORER);
  1970. file_list_popup->set_position(files->get_global_position() + p_pos);
  1971. file_list_popup->popup();
  1972. }
  1973. void FileSystemDock::select_file(const String &p_file) {
  1974. _navigate_to_path(p_file);
  1975. }
  1976. void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) {
  1977. // Set the path to the current focused item.
  1978. int current = files->get_current();
  1979. if (current == p_index) {
  1980. String fpath = files->get_item_metadata(current);
  1981. if (!fpath.ends_with("/")) {
  1982. path = fpath;
  1983. if (display_mode == DISPLAY_MODE_SPLIT) {
  1984. _update_tree(_compute_uncollapsed_paths());
  1985. }
  1986. }
  1987. }
  1988. // Update the import dock.
  1989. import_dock_needs_update = true;
  1990. call_deferred("_update_import_dock");
  1991. }
  1992. void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
  1993. if (get_viewport()->get_modal_stack_top())
  1994. return; // Ignore because of modal window.
  1995. Ref<InputEventKey> key = p_event;
  1996. if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
  1997. if (ED_IS_SHORTCUT("filesystem_dock/duplicate", p_event)) {
  1998. _tree_rmb_option(FILE_DUPLICATE);
  1999. } else if (ED_IS_SHORTCUT("filesystem_dock/copy_path", p_event)) {
  2000. _tree_rmb_option(FILE_COPY_PATH);
  2001. } else if (ED_IS_SHORTCUT("filesystem_dock/delete", p_event)) {
  2002. _tree_rmb_option(FILE_REMOVE);
  2003. } else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) {
  2004. _tree_rmb_option(FILE_RENAME);
  2005. }
  2006. }
  2007. }
  2008. void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
  2009. if (get_viewport()->get_modal_stack_top())
  2010. return; // Ignore because of modal window.
  2011. Ref<InputEventKey> key = p_event;
  2012. if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
  2013. if (ED_IS_SHORTCUT("filesystem_dock/duplicate", p_event)) {
  2014. _file_list_rmb_option(FILE_DUPLICATE);
  2015. } else if (ED_IS_SHORTCUT("filesystem_dock/copy_path", p_event)) {
  2016. _file_list_rmb_option(FILE_COPY_PATH);
  2017. } else if (ED_IS_SHORTCUT("filesystem_dock/delete", p_event)) {
  2018. _file_list_rmb_option(FILE_REMOVE);
  2019. } else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) {
  2020. _file_list_rmb_option(FILE_RENAME);
  2021. }
  2022. }
  2023. }
  2024. void FileSystemDock::_update_import_dock() {
  2025. if (!import_dock_needs_update)
  2026. return;
  2027. // List selected.
  2028. Vector<String> selected;
  2029. if (display_mode == DISPLAY_MODE_TREE_ONLY) {
  2030. // Use the tree
  2031. selected = _tree_get_selected();
  2032. } else {
  2033. // Use the file list.
  2034. for (int i = 0; i < files->get_item_count(); i++) {
  2035. if (!files->is_selected(i))
  2036. continue;
  2037. selected.push_back(files->get_item_metadata(i));
  2038. }
  2039. }
  2040. // Check import.
  2041. Vector<String> imports;
  2042. String import_type;
  2043. for (int i = 0; i < selected.size(); i++) {
  2044. String fpath = selected[i];
  2045. if (fpath.ends_with("/")) {
  2046. imports.clear();
  2047. break;
  2048. }
  2049. if (!FileAccess::exists(fpath + ".import")) {
  2050. imports.clear();
  2051. break;
  2052. }
  2053. Ref<ConfigFile> cf;
  2054. cf.instance();
  2055. Error err = cf->load(fpath + ".import");
  2056. if (err != OK) {
  2057. imports.clear();
  2058. break;
  2059. }
  2060. String type = cf->get_value("remap", "type");
  2061. if (import_type == "") {
  2062. import_type = type;
  2063. } else if (import_type != type) {
  2064. // All should be the same type.
  2065. imports.clear();
  2066. break;
  2067. }
  2068. imports.push_back(fpath);
  2069. }
  2070. if (imports.size() == 0) {
  2071. EditorNode::get_singleton()->get_import_dock()->clear();
  2072. } else if (imports.size() == 1) {
  2073. EditorNode::get_singleton()->get_import_dock()->set_edit_path(imports[0]);
  2074. } else {
  2075. EditorNode::get_singleton()->get_import_dock()->set_edit_multiple_paths(imports);
  2076. }
  2077. import_dock_needs_update = false;
  2078. }
  2079. void FileSystemDock::_feature_profile_changed() {
  2080. _update_display_mode(true);
  2081. }
  2082. void FileSystemDock::_bind_methods() {
  2083. ClassDB::bind_method(D_METHOD("_file_list_gui_input"), &FileSystemDock::_file_list_gui_input);
  2084. ClassDB::bind_method(D_METHOD("_tree_gui_input"), &FileSystemDock::_tree_gui_input);
  2085. ClassDB::bind_method(D_METHOD("_update_tree"), &FileSystemDock::_update_tree);
  2086. ClassDB::bind_method(D_METHOD("_rescan"), &FileSystemDock::_rescan);
  2087. ClassDB::bind_method(D_METHOD("_toggle_split_mode"), &FileSystemDock::_toggle_split_mode);
  2088. ClassDB::bind_method(D_METHOD("_tree_rmb_option", "option"), &FileSystemDock::_tree_rmb_option);
  2089. ClassDB::bind_method(D_METHOD("_tree_rmb_select"), &FileSystemDock::_tree_rmb_select);
  2090. ClassDB::bind_method(D_METHOD("_tree_empty_selected"), &FileSystemDock::_tree_empty_selected);
  2091. ClassDB::bind_method(D_METHOD("_file_list_rmb_option", "option"), &FileSystemDock::_file_list_rmb_option);
  2092. ClassDB::bind_method(D_METHOD("_file_list_rmb_select"), &FileSystemDock::_file_list_rmb_select);
  2093. ClassDB::bind_method(D_METHOD("_file_list_rmb_pressed"), &FileSystemDock::_file_list_rmb_pressed);
  2094. ClassDB::bind_method(D_METHOD("_tree_rmb_empty"), &FileSystemDock::_tree_rmb_empty);
  2095. ClassDB::bind_method(D_METHOD("_file_deleted"), &FileSystemDock::_file_deleted);
  2096. ClassDB::bind_method(D_METHOD("_folder_deleted"), &FileSystemDock::_folder_deleted);
  2097. ClassDB::bind_method(D_METHOD("_file_list_thumbnail_done"), &FileSystemDock::_file_list_thumbnail_done);
  2098. ClassDB::bind_method(D_METHOD("_tree_thumbnail_done"), &FileSystemDock::_tree_thumbnail_done);
  2099. ClassDB::bind_method(D_METHOD("_file_list_activate_file"), &FileSystemDock::_file_list_activate_file);
  2100. ClassDB::bind_method(D_METHOD("_tree_activate_file"), &FileSystemDock::_tree_activate_file);
  2101. ClassDB::bind_method(D_METHOD("_select_file"), &FileSystemDock::_select_file);
  2102. ClassDB::bind_method(D_METHOD("_navigate_to_path"), &FileSystemDock::_navigate_to_path, DEFVAL(false));
  2103. ClassDB::bind_method(D_METHOD("_toggle_file_display"), &FileSystemDock::_toggle_file_display);
  2104. ClassDB::bind_method(D_METHOD("_fw_history"), &FileSystemDock::_fw_history);
  2105. ClassDB::bind_method(D_METHOD("_bw_history"), &FileSystemDock::_bw_history);
  2106. ClassDB::bind_method(D_METHOD("_fs_changed"), &FileSystemDock::_fs_changed);
  2107. ClassDB::bind_method(D_METHOD("_tree_multi_selected"), &FileSystemDock::_tree_multi_selected);
  2108. ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileSystemDock::_make_dir_confirm);
  2109. ClassDB::bind_method(D_METHOD("_make_scene_confirm"), &FileSystemDock::_make_scene_confirm);
  2110. ClassDB::bind_method(D_METHOD("_resource_created"), &FileSystemDock::_resource_created);
  2111. ClassDB::bind_method(D_METHOD("_move_operation_confirm", "to_path", "overwrite"), &FileSystemDock::_move_operation_confirm, DEFVAL(false));
  2112. ClassDB::bind_method(D_METHOD("_move_with_overwrite"), &FileSystemDock::_move_with_overwrite);
  2113. ClassDB::bind_method(D_METHOD("_rename_operation_confirm"), &FileSystemDock::_rename_operation_confirm);
  2114. ClassDB::bind_method(D_METHOD("_duplicate_operation_confirm"), &FileSystemDock::_duplicate_operation_confirm);
  2115. ClassDB::bind_method(D_METHOD("_search_changed"), &FileSystemDock::_search_changed);
  2116. ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &FileSystemDock::get_drag_data_fw);
  2117. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &FileSystemDock::can_drop_data_fw);
  2118. ClassDB::bind_method(D_METHOD("drop_data_fw"), &FileSystemDock::drop_data_fw);
  2119. ClassDB::bind_method(D_METHOD("navigate_to_path"), &FileSystemDock::navigate_to_path);
  2120. ClassDB::bind_method(D_METHOD("_preview_invalidated"), &FileSystemDock::_preview_invalidated);
  2121. ClassDB::bind_method(D_METHOD("_file_multi_selected"), &FileSystemDock::_file_multi_selected);
  2122. ClassDB::bind_method(D_METHOD("_update_import_dock"), &FileSystemDock::_update_import_dock);
  2123. ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &FileSystemDock::_feature_profile_changed);
  2124. ADD_SIGNAL(MethodInfo("inherit", PropertyInfo(Variant::STRING, "file")));
  2125. ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::POOL_STRING_ARRAY, "files")));
  2126. ADD_SIGNAL(MethodInfo("file_removed", PropertyInfo(Variant::STRING, "file")));
  2127. ADD_SIGNAL(MethodInfo("folder_removed", PropertyInfo(Variant::STRING, "folder")));
  2128. ADD_SIGNAL(MethodInfo("files_moved", PropertyInfo(Variant::STRING, "old_file"), PropertyInfo(Variant::STRING, "new_file")));
  2129. ADD_SIGNAL(MethodInfo("folder_moved", PropertyInfo(Variant::STRING, "old_folder"), PropertyInfo(Variant::STRING, "new_file")));
  2130. ADD_SIGNAL(MethodInfo("display_mode_changed"));
  2131. }
  2132. FileSystemDock::FileSystemDock(EditorNode *p_editor) {
  2133. set_name("FileSystem");
  2134. editor = p_editor;
  2135. path = "res://";
  2136. ED_SHORTCUT("filesystem_dock/copy_path", TTR("Copy Path"), KEY_MASK_CMD | KEY_C);
  2137. ED_SHORTCUT("filesystem_dock/duplicate", TTR("Duplicate..."), KEY_MASK_CMD | KEY_D);
  2138. ED_SHORTCUT("filesystem_dock/delete", TTR("Delete"), KEY_DELETE);
  2139. ED_SHORTCUT("filesystem_dock/rename", TTR("Rename"));
  2140. VBoxContainer *top_vbc = memnew(VBoxContainer);
  2141. add_child(top_vbc);
  2142. HBoxContainer *toolbar_hbc = memnew(HBoxContainer);
  2143. toolbar_hbc->add_constant_override("separation", 0);
  2144. top_vbc->add_child(toolbar_hbc);
  2145. button_hist_prev = memnew(ToolButton);
  2146. button_hist_prev->set_disabled(true);
  2147. button_hist_prev->set_focus_mode(FOCUS_NONE);
  2148. button_hist_prev->set_tooltip(TTR("Previous Folder/File"));
  2149. toolbar_hbc->add_child(button_hist_prev);
  2150. button_hist_next = memnew(ToolButton);
  2151. button_hist_next->set_disabled(true);
  2152. button_hist_next->set_focus_mode(FOCUS_NONE);
  2153. button_hist_next->set_tooltip(TTR("Next Folder/File"));
  2154. toolbar_hbc->add_child(button_hist_next);
  2155. current_path = memnew(LineEdit);
  2156. current_path->set_h_size_flags(SIZE_EXPAND_FILL);
  2157. _set_current_path_text(path);
  2158. toolbar_hbc->add_child(current_path);
  2159. button_reload = memnew(Button);
  2160. button_reload->set_flat(true);
  2161. button_reload->connect("pressed", this, "_rescan");
  2162. button_reload->set_focus_mode(FOCUS_NONE);
  2163. button_reload->set_tooltip(TTR("Re-Scan Filesystem"));
  2164. button_reload->hide();
  2165. toolbar_hbc->add_child(button_reload);
  2166. button_toggle_display_mode = memnew(Button);
  2167. button_toggle_display_mode->set_flat(true);
  2168. button_toggle_display_mode->set_toggle_mode(true);
  2169. button_toggle_display_mode->connect("toggled", this, "_toggle_split_mode");
  2170. button_toggle_display_mode->set_focus_mode(FOCUS_NONE);
  2171. button_toggle_display_mode->set_tooltip(TTR("Toggle Split Mode"));
  2172. toolbar_hbc->add_child(button_toggle_display_mode);
  2173. HBoxContainer *toolbar2_hbc = memnew(HBoxContainer);
  2174. toolbar2_hbc->add_constant_override("separation", 0);
  2175. top_vbc->add_child(toolbar2_hbc);
  2176. tree_search_box = memnew(LineEdit);
  2177. tree_search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  2178. tree_search_box->set_placeholder(TTR("Search files"));
  2179. tree_search_box->connect("text_changed", this, "_search_changed", varray(tree_search_box));
  2180. toolbar2_hbc->add_child(tree_search_box);
  2181. file_list_popup = memnew(PopupMenu);
  2182. file_list_popup->set_hide_on_window_lose_focus(true);
  2183. add_child(file_list_popup);
  2184. tree_popup = memnew(PopupMenu);
  2185. tree_popup->set_hide_on_window_lose_focus(true);
  2186. add_child(tree_popup);
  2187. split_box = memnew(VSplitContainer);
  2188. split_box->set_v_size_flags(SIZE_EXPAND_FILL);
  2189. add_child(split_box);
  2190. tree = memnew(Tree);
  2191. tree->set_hide_root(true);
  2192. tree->set_drag_forwarding(this);
  2193. tree->set_allow_rmb_select(true);
  2194. tree->set_select_mode(Tree::SELECT_MULTI);
  2195. tree->set_custom_minimum_size(Size2(0, 15 * EDSCALE));
  2196. split_box->add_child(tree);
  2197. tree->connect("item_activated", this, "_tree_activate_file");
  2198. tree->connect("multi_selected", this, "_tree_multi_selected");
  2199. tree->connect("item_rmb_selected", this, "_tree_rmb_select");
  2200. tree->connect("empty_rmb", this, "_tree_rmb_empty");
  2201. tree->connect("nothing_selected", this, "_tree_empty_selected");
  2202. tree->connect("gui_input", this, "_tree_gui_input");
  2203. file_list_vb = memnew(VBoxContainer);
  2204. file_list_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  2205. split_box->add_child(file_list_vb);
  2206. path_hb = memnew(HBoxContainer);
  2207. file_list_vb->add_child(path_hb);
  2208. file_list_search_box = memnew(LineEdit);
  2209. file_list_search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  2210. file_list_search_box->set_placeholder(TTR("Search files"));
  2211. file_list_search_box->connect("text_changed", this, "_search_changed", varray(file_list_search_box));
  2212. path_hb->add_child(file_list_search_box);
  2213. button_file_list_display_mode = memnew(ToolButton);
  2214. path_hb->add_child(button_file_list_display_mode);
  2215. files = memnew(ItemList);
  2216. files->set_v_size_flags(SIZE_EXPAND_FILL);
  2217. files->set_select_mode(ItemList::SELECT_MULTI);
  2218. files->set_drag_forwarding(this);
  2219. files->connect("item_rmb_selected", this, "_file_list_rmb_select");
  2220. files->connect("gui_input", this, "_file_list_gui_input");
  2221. files->connect("multi_selected", this, "_file_multi_selected");
  2222. files->connect("rmb_clicked", this, "_file_list_rmb_pressed");
  2223. files->set_custom_minimum_size(Size2(0, 15 * EDSCALE));
  2224. files->set_allow_rmb_select(true);
  2225. file_list_vb->add_child(files);
  2226. scanning_vb = memnew(VBoxContainer);
  2227. scanning_vb->hide();
  2228. add_child(scanning_vb);
  2229. Label *slabel = memnew(Label);
  2230. slabel->set_text(TTR("Scanning Files,\nPlease Wait..."));
  2231. slabel->set_align(Label::ALIGN_CENTER);
  2232. scanning_vb->add_child(slabel);
  2233. scanning_progress = memnew(ProgressBar);
  2234. scanning_vb->add_child(scanning_progress);
  2235. deps_editor = memnew(DependencyEditor);
  2236. add_child(deps_editor);
  2237. owners_editor = memnew(DependencyEditorOwners(editor));
  2238. add_child(owners_editor);
  2239. remove_dialog = memnew(DependencyRemoveDialog);
  2240. remove_dialog->connect("file_removed", this, "_file_deleted");
  2241. remove_dialog->connect("folder_removed", this, "_folder_deleted");
  2242. add_child(remove_dialog);
  2243. move_dialog = memnew(EditorDirDialog);
  2244. move_dialog->get_ok()->set_text(TTR("Move"));
  2245. add_child(move_dialog);
  2246. move_dialog->connect("dir_selected", this, "_move_operation_confirm");
  2247. rename_dialog = memnew(ConfirmationDialog);
  2248. VBoxContainer *rename_dialog_vb = memnew(VBoxContainer);
  2249. rename_dialog->add_child(rename_dialog_vb);
  2250. rename_dialog_text = memnew(LineEdit);
  2251. rename_dialog_vb->add_margin_child(TTR("Name:"), rename_dialog_text);
  2252. rename_dialog->get_ok()->set_text(TTR("Rename"));
  2253. add_child(rename_dialog);
  2254. rename_dialog->register_text_enter(rename_dialog_text);
  2255. rename_dialog->connect("confirmed", this, "_rename_operation_confirm");
  2256. overwrite_dialog = memnew(ConfirmationDialog);
  2257. overwrite_dialog->set_text(TTR("There is already file or folder with the same name in this location."));
  2258. overwrite_dialog->get_ok()->set_text(TTR("Overwrite"));
  2259. add_child(overwrite_dialog);
  2260. overwrite_dialog->connect("confirmed", this, "_move_with_overwrite");
  2261. duplicate_dialog = memnew(ConfirmationDialog);
  2262. VBoxContainer *duplicate_dialog_vb = memnew(VBoxContainer);
  2263. duplicate_dialog->add_child(duplicate_dialog_vb);
  2264. duplicate_dialog_text = memnew(LineEdit);
  2265. duplicate_dialog_vb->add_margin_child(TTR("Name:"), duplicate_dialog_text);
  2266. duplicate_dialog->get_ok()->set_text(TTR("Duplicate"));
  2267. add_child(duplicate_dialog);
  2268. duplicate_dialog->register_text_enter(duplicate_dialog_text);
  2269. duplicate_dialog->connect("confirmed", this, "_duplicate_operation_confirm");
  2270. make_dir_dialog = memnew(ConfirmationDialog);
  2271. make_dir_dialog->set_title(TTR("Create Folder"));
  2272. VBoxContainer *make_folder_dialog_vb = memnew(VBoxContainer);
  2273. make_dir_dialog->add_child(make_folder_dialog_vb);
  2274. make_dir_dialog_text = memnew(LineEdit);
  2275. make_folder_dialog_vb->add_margin_child(TTR("Name:"), make_dir_dialog_text);
  2276. add_child(make_dir_dialog);
  2277. make_dir_dialog->register_text_enter(make_dir_dialog_text);
  2278. make_dir_dialog->connect("confirmed", this, "_make_dir_confirm");
  2279. make_scene_dialog = memnew(ConfirmationDialog);
  2280. make_scene_dialog->set_title(TTR("Create Scene"));
  2281. VBoxContainer *make_scene_dialog_vb = memnew(VBoxContainer);
  2282. make_scene_dialog->add_child(make_scene_dialog_vb);
  2283. make_scene_dialog_text = memnew(LineEdit);
  2284. make_scene_dialog_vb->add_margin_child(TTR("Name:"), make_scene_dialog_text);
  2285. add_child(make_scene_dialog);
  2286. make_scene_dialog->register_text_enter(make_scene_dialog_text);
  2287. make_scene_dialog->connect("confirmed", this, "_make_scene_confirm");
  2288. make_script_dialog_text = memnew(ScriptCreateDialog);
  2289. make_script_dialog_text->set_title(TTR("Create Script"));
  2290. add_child(make_script_dialog_text);
  2291. new_resource_dialog = memnew(CreateDialog);
  2292. add_child(new_resource_dialog);
  2293. new_resource_dialog->set_base_type("Resource");
  2294. new_resource_dialog->connect("create", this, "_resource_created");
  2295. searched_string = String();
  2296. uncollapsed_paths_before_search = Vector<String>();
  2297. updating_tree = false;
  2298. tree_update_id = 0;
  2299. initialized = false;
  2300. import_dock_needs_update = false;
  2301. history_pos = 0;
  2302. history_max_size = 20;
  2303. history.push_back("res://");
  2304. display_mode = DISPLAY_MODE_TREE_ONLY;
  2305. old_display_mode = DISPLAY_MODE_TREE_ONLY;
  2306. file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS;
  2307. always_show_folders = false;
  2308. }
  2309. FileSystemDock::~FileSystemDock() {
  2310. }