filesystem_dock.cpp 89 KB

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