filesystem_dock.cpp 91 KB

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