filesystem_dock.cpp 90 KB

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