filesystem_dock.cpp 91 KB

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