filesystem_dock.cpp 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  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 "globals.h"
  32. #include "os/dir_access.h"
  33. #include "os/file_access.h"
  34. #include "editor_node.h"
  35. #include "io/resource_loader.h"
  36. #include "os/os.h"
  37. #include "editor_settings.h"
  38. #include "scene/main/viewport.h"
  39. bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir) {
  40. TreeItem *item = tree->create_item(p_parent);
  41. String dname = p_dir->get_name();
  42. if (dname == "")
  43. dname = "res://";
  44. item->set_text(0, dname);
  45. item->set_icon(0, get_icon("Folder", "EditorIcons"));
  46. item->set_selectable(0, true);
  47. String lpath = p_dir->get_path();
  48. if (lpath != "res://" && lpath.ends_with("/")) {
  49. lpath = lpath.substr(0, lpath.length() - 1);
  50. }
  51. item->set_metadata(0, lpath);
  52. if (lpath == path) {
  53. item->select(0);
  54. }
  55. for (int i = 0; i < p_dir->get_subdir_count(); i++)
  56. _create_tree(item, p_dir->get_subdir(i));
  57. return true;
  58. }
  59. void FileSystemDock::_update_tree() {
  60. tree->clear();
  61. updating_tree = true;
  62. TreeItem *root = tree->create_item();
  63. TreeItem *favorites = tree->create_item(root);
  64. favorites->set_icon(0, get_icon("Favorites", "EditorIcons"));
  65. favorites->set_text(0, TTR("Favorites:"));
  66. favorites->set_selectable(0, false);
  67. Vector<String> faves = EditorSettings::get_singleton()->get_favorite_dirs();
  68. for (int i = 0; i < faves.size(); i++) {
  69. if (!faves[i].begins_with("res://"))
  70. continue;
  71. TreeItem *ti = tree->create_item(favorites);
  72. String fv = faves[i];
  73. if (fv == "res://")
  74. ti->set_text(0, "/");
  75. else
  76. ti->set_text(0, faves[i].get_file());
  77. ti->set_icon(0, get_icon("Folder", "EditorIcons"));
  78. ti->set_selectable(0, true);
  79. ti->set_metadata(0, faves[i]);
  80. }
  81. _create_tree(root, EditorFileSystem::get_singleton()->get_filesystem());
  82. updating_tree = false;
  83. }
  84. void FileSystemDock::_notification(int p_what) {
  85. switch (p_what) {
  86. case NOTIFICATION_RESIZED: {
  87. bool new_mode = get_size().height < get_viewport_rect().size.height / 2;
  88. if (new_mode != split_mode) {
  89. split_mode = new_mode;
  90. //print_line("SPLIT MODE? "+itos(split_mode));
  91. if (split_mode) {
  92. file_list_vb->hide();
  93. tree->set_custom_minimum_size(Size2(0, 0));
  94. tree->set_v_size_flags(SIZE_EXPAND_FILL);
  95. button_back->show();
  96. } else {
  97. tree->show();
  98. file_list_vb->show();
  99. tree->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
  100. tree->set_v_size_flags(SIZE_FILL);
  101. button_back->hide();
  102. if (!EditorFileSystem::get_singleton()->is_scanning()) {
  103. _fs_changed();
  104. }
  105. }
  106. }
  107. } break;
  108. case NOTIFICATION_ENTER_TREE: {
  109. if (initialized)
  110. return;
  111. initialized = true;
  112. EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_fs_changed");
  113. EditorResourcePreview::get_singleton()->connect("preview_invalidated", this, "_preview_invalidated");
  114. button_reload->set_icon(get_icon("Reload", "EditorIcons"));
  115. button_favorite->set_icon(get_icon("Favorites", "EditorIcons"));
  116. //button_instance->set_icon( get_icon("Add","EditorIcons"));
  117. //button_open->set_icon( get_icon("Folder","EditorIcons"));
  118. button_back->set_icon(get_icon("Filesystem", "EditorIcons"));
  119. if (display_mode == DISPLAY_THUMBNAILS) {
  120. button_display_mode->set_icon(get_icon("FileList", "EditorIcons"));
  121. } else {
  122. button_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons"));
  123. }
  124. button_display_mode->connect("pressed", this, "_change_file_display");
  125. //file_options->set_icon( get_icon("Tools","EditorIcons"));
  126. files->connect("item_activated", this, "_select_file");
  127. button_hist_next->connect("pressed", this, "_fw_history");
  128. button_hist_prev->connect("pressed", this, "_bw_history");
  129. search_icon->set_texture(get_icon("Zoom", "EditorIcons"));
  130. button_hist_next->set_icon(get_icon("Forward", "EditorIcons"));
  131. button_hist_prev->set_icon(get_icon("Back", "EditorIcons"));
  132. file_options->connect("item_pressed", this, "_file_option");
  133. folder_options->connect("item_pressed", this, "_folder_option");
  134. button_back->connect("pressed", this, "_go_to_tree", varray(), CONNECT_DEFERRED);
  135. current_path->connect("text_entered", this, "_go_to_dir");
  136. _update_tree(); //maybe it finished already
  137. if (EditorFileSystem::get_singleton()->is_scanning()) {
  138. _set_scanning_mode();
  139. }
  140. } break;
  141. case NOTIFICATION_PROCESS: {
  142. if (EditorFileSystem::get_singleton()->is_scanning()) {
  143. scanning_progress->set_val(EditorFileSystem::get_singleton()->get_scanning_progress() * 100);
  144. }
  145. } break;
  146. case NOTIFICATION_EXIT_TREE: {
  147. } break;
  148. case NOTIFICATION_DRAG_BEGIN: {
  149. Dictionary dd = get_viewport()->gui_get_drag_data();
  150. if (tree->is_visible() && dd.has("type")) {
  151. if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) {
  152. tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  153. }
  154. if ((String(dd["type"]) == "favorite")) {
  155. tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  156. }
  157. }
  158. } break;
  159. case NOTIFICATION_DRAG_END: {
  160. tree->set_drop_mode_flags(0);
  161. } break;
  162. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  163. int new_mode = int(EditorSettings::get_singleton()->get("filesystem_dock/display_mode"));
  164. if (new_mode != display_mode) {
  165. set_display_mode(new_mode);
  166. } else {
  167. _update_files(true);
  168. }
  169. } break;
  170. }
  171. }
  172. void FileSystemDock::_dir_selected() {
  173. TreeItem *ti = tree->get_selected();
  174. if (!ti)
  175. return;
  176. String dir = ti->get_metadata(0);
  177. bool found = false;
  178. Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
  179. for (int i = 0; i < favorites.size(); i++) {
  180. if (favorites[i] == dir) {
  181. found = true;
  182. break;
  183. }
  184. }
  185. button_favorite->set_pressed(found);
  186. if (!split_mode) {
  187. _open_pressed(); //go directly to dir
  188. }
  189. }
  190. void FileSystemDock::_dir_rmb_pressed(const Vector2 &p_pos) {
  191. folder_options->clear();
  192. folder_options->set_size(Size2(1, 1));
  193. folder_options->add_item(TTR("Expand all"), FOLDER_EXPAND_ALL);
  194. folder_options->add_item(TTR("Collapse all"), FOLDER_COLLAPSE_ALL);
  195. TreeItem *item = tree->get_selected();
  196. if (item) {
  197. String fpath = item->get_metadata(tree->get_selected_column());
  198. folder_options->add_separator();
  199. folder_options->add_item(TTR("Copy Path"), FOLDER_COPY_PATH);
  200. if (fpath != "res://") {
  201. folder_options->add_item(TTR("Rename.."), FOLDER_RENAME);
  202. folder_options->add_item(TTR("Move To.."), FOLDER_MOVE);
  203. folder_options->add_item(TTR("Delete"), FOLDER_REMOVE);
  204. }
  205. folder_options->add_separator();
  206. folder_options->add_item(TTR("New Folder.."), FOLDER_NEW_FOLDER);
  207. folder_options->add_item(TTR("Show In File Manager"), FOLDER_SHOW_IN_EXPLORER);
  208. }
  209. folder_options->set_pos(tree->get_global_pos() + p_pos);
  210. folder_options->popup();
  211. }
  212. void FileSystemDock::_make_dir_confirm() {
  213. String dir_name = make_dir_dialog_text->get_text().strip_edges();
  214. if (dir_name.length() == 0) {
  215. EditorNode::get_singleton()->show_warning(TTR("No name provided"));
  216. return;
  217. } else if (dir_name.find("/") != -1 || dir_name.find("\\") != -1 || dir_name.find(":") != -1) {
  218. EditorNode::get_singleton()->show_warning(TTR("Provided name contains invalid characters"));
  219. return;
  220. }
  221. print_line("Making folder " + dir_name + " in " + path);
  222. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  223. Error err = da->change_dir(path);
  224. if (err == OK) {
  225. err = da->make_dir(dir_name);
  226. }
  227. memdelete(da);
  228. if (err == OK) {
  229. print_line("call rescan!");
  230. _rescan();
  231. } else {
  232. EditorNode::get_singleton()->show_warning(TTR("Could not create folder."));
  233. }
  234. }
  235. void FileSystemDock::_rename_operation_confirm() {
  236. String new_name = rename_dialog_text->get_text().strip_edges();
  237. if (new_name.length() == 0) {
  238. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  239. return;
  240. } else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
  241. EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
  242. return;
  243. }
  244. String old_path = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1) : to_rename.path;
  245. String new_path = old_path.get_base_dir().plus_file(new_name);
  246. if (old_path == new_path) {
  247. return;
  248. }
  249. //Present a more user friendly warning for name conflict
  250. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  251. if (da->file_exists(new_path) || da->dir_exists(new_path)) {
  252. EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
  253. memdelete(da);
  254. return;
  255. }
  256. memdelete(da);
  257. Map<String, String> renames;
  258. _try_move_item(to_rename, new_path, renames);
  259. _update_dependencies_after_move(renames);
  260. //Rescan everything
  261. print_line("call rescan!");
  262. _rescan();
  263. }
  264. void FileSystemDock::_move_operation_confirm(const String &p_to_path) {
  265. Map<String, String> renames;
  266. for (int i = 0; i < to_move.size(); i++) {
  267. 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;
  268. String new_path = p_to_path.plus_file(old_path.get_file());
  269. _try_move_item(to_move[i], new_path, renames);
  270. }
  271. _update_dependencies_after_move(renames);
  272. print_line("call rescan!");
  273. _rescan();
  274. }
  275. void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_renames) {
  276. //Ensure folder paths end with "/"
  277. String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/");
  278. String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/");
  279. if (new_path == old_path) {
  280. return;
  281. } else if (old_path == "res://") {
  282. EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root."));
  283. return;
  284. } else if (!p_item.is_file && new_path.begins_with(old_path)) {
  285. //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/"
  286. EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.\n") + old_path + "\n");
  287. return;
  288. }
  289. //Build a list of files which will have new paths as a result of this operation
  290. Vector<String> changed_paths;
  291. if (p_item.is_file) {
  292. changed_paths.push_back(old_path);
  293. } else {
  294. _get_all_files_in_dir(EditorFileSystem::get_singleton()->get_path(old_path), changed_paths);
  295. }
  296. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  297. print_line("Moving " + old_path + " -> " + new_path);
  298. Error err = da->rename(old_path, new_path);
  299. if (err == OK) {
  300. //Only treat as a changed dependency if it was successfully moved
  301. for (int i = 0; i < changed_paths.size(); ++i) {
  302. p_renames[changed_paths[i]] = changed_paths[i].replace_first(old_path, new_path);
  303. print_line(" Remap: " + changed_paths[i] + " -> " + p_renames[changed_paths[i]]);
  304. }
  305. } else {
  306. EditorNode::get_singleton()->add_io_error(TTR("Error moving:\n") + old_path + "\n");
  307. }
  308. memdelete(da);
  309. }
  310. void FileSystemDock::_get_all_files_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files) {
  311. if (efsd == NULL)
  312. return;
  313. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  314. _get_all_files_in_dir(efsd->get_subdir(i), files);
  315. }
  316. for (int i = 0; i < efsd->get_file_count(); i++) {
  317. files.push_back(efsd->get_file_path(i));
  318. }
  319. }
  320. void FileSystemDock::_update_dependencies_after_move(Map<String, String> &p_renames) {
  321. //The following code assumes that the following holds:
  322. // 1) EditorFileSystem contains the old paths/folder structure from before the rename/move.
  323. // 2) ResourceLoader can use the new paths without needing to call rescan.
  324. List<String> remaps;
  325. _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps);
  326. for (int i = 0; i < remaps.size(); ++i) {
  327. //Because we haven't called a rescan yet the found remap might still be an old path itself.
  328. String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i];
  329. print_line("Remapping dependencies for: " + file);
  330. Error err = ResourceLoader::rename_dependencies(file, p_renames);
  331. if (err != OK) {
  332. EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:\n") + remaps[i] + "\n");
  333. }
  334. }
  335. }
  336. void FileSystemDock::_favorites_pressed() {
  337. TreeItem *sel = tree->get_selected();
  338. if (!sel)
  339. return;
  340. String dir = sel->get_metadata(0);
  341. int idx = -1;
  342. Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
  343. for (int i = 0; i < favorites.size(); i++) {
  344. if (favorites[i] == dir) {
  345. idx = i;
  346. break;
  347. }
  348. }
  349. if (button_favorite->is_pressed() && idx == -1) {
  350. favorites.push_back(dir);
  351. EditorSettings::get_singleton()->set_favorite_dirs(favorites);
  352. _update_tree();
  353. } else if (!button_favorite->is_pressed() && idx != -1) {
  354. favorites.remove(idx);
  355. EditorSettings::get_singleton()->set_favorite_dirs(favorites);
  356. _update_tree();
  357. }
  358. }
  359. String FileSystemDock::get_selected_path() const {
  360. TreeItem *sel = tree->get_selected();
  361. if (!sel)
  362. return "";
  363. String path = sel->get_metadata(0);
  364. return "res://" + path;
  365. }
  366. void FileSystemDock::navigate_to_path(const String &p_path) {
  367. // If the path is a file, do not only go to the directory in the tree, also select the file in the file list.
  368. String file_name = "";
  369. DirAccess *dirAccess = DirAccess::open("res://");
  370. if (dirAccess->file_exists(p_path)) {
  371. path = p_path.get_base_dir();
  372. file_name = p_path.get_file();
  373. } else if (dirAccess->dir_exists(p_path)) {
  374. path = p_path;
  375. } else {
  376. ERR_EXPLAIN(vformat(TTR("Cannot navigate to '%s' as it has not been found in the file system!"), p_path));
  377. ERR_FAIL();
  378. }
  379. current_path->set_text(path);
  380. _push_to_history();
  381. _update_tree();
  382. _update_files(false);
  383. if (!file_name.empty()) {
  384. for (int i = 0; i < files->get_item_count(); i++) {
  385. if (files->get_item_text(i) == file_name) {
  386. files->select(i, true);
  387. files->ensure_current_is_visible();
  388. break;
  389. }
  390. }
  391. }
  392. }
  393. String FileSystemDock::get_current_path() const {
  394. return path;
  395. }
  396. void FileSystemDock::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
  397. bool valid = false;
  398. if (!search_box->is_hidden()) {
  399. valid = true;
  400. } else {
  401. valid = (path == p_path.get_base_dir());
  402. }
  403. if (p_preview.is_valid() && valid) {
  404. Array uarr = p_udata;
  405. int idx = uarr[0];
  406. String file = uarr[1];
  407. if (idx >= files->get_item_count())
  408. return;
  409. if (files->get_item_text(idx) != file)
  410. return;
  411. String fpath = files->get_item_metadata(idx);
  412. if (fpath != p_path)
  413. return;
  414. files->set_item_icon(idx, p_preview);
  415. }
  416. }
  417. void FileSystemDock::_change_file_display() {
  418. if (button_display_mode->is_pressed()) {
  419. display_mode = DISPLAY_LIST;
  420. button_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons"));
  421. } else {
  422. display_mode = DISPLAY_THUMBNAILS;
  423. button_display_mode->set_icon(get_icon("FileList", "EditorIcons"));
  424. }
  425. EditorSettings::get_singleton()->set("filesystem_dock/display_mode", display_mode);
  426. _update_files(true);
  427. }
  428. void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) {
  429. if (matches->size() > p_max_items)
  430. return;
  431. for (int i = 0; i < p_path->get_subdir_count(); i++) {
  432. _search(p_path->get_subdir(i), matches, p_max_items);
  433. }
  434. String match = search_box->get_text();
  435. for (int i = 0; i < p_path->get_file_count(); i++) {
  436. String file = p_path->get_file(i);
  437. if (file.find(match) != -1) {
  438. FileInfo fi;
  439. fi.name = file;
  440. fi.type = p_path->get_file_type(i);
  441. fi.path = p_path->get_file_path(i);
  442. if (p_path->get_file_meta(i)) {
  443. if (p_path->is_missing_sources(i)) {
  444. fi.import_status = 3;
  445. } else if (p_path->have_sources_changed(i)) {
  446. fi.import_status = 2;
  447. } else {
  448. fi.import_status = 1;
  449. }
  450. } else {
  451. fi.import_status = 0;
  452. }
  453. for (int j = 0; j < p_path->get_source_count(i); j++) {
  454. String s = EditorImportPlugin::expand_source_path(p_path->get_source_file(i, j));
  455. if (p_path->is_source_file_missing(i, j)) {
  456. s += " (Missing)";
  457. }
  458. fi.sources.push_back(s);
  459. }
  460. matches->push_back(fi);
  461. if (matches->size() > p_max_items)
  462. return;
  463. }
  464. }
  465. }
  466. void FileSystemDock::_update_files(bool p_keep_selection) {
  467. Set<String> cselection;
  468. if (p_keep_selection) {
  469. for (int i = 0; i < files->get_item_count(); i++) {
  470. if (files->is_selected(i))
  471. cselection.insert(files->get_item_text(i));
  472. }
  473. }
  474. files->clear();
  475. current_path->set_text(path);
  476. EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
  477. if (!efd)
  478. return;
  479. int thumbnail_size = EditorSettings::get_singleton()->get("filesystem_dock/thumbnail_size");
  480. thumbnail_size *= EDSCALE;
  481. Ref<Texture> folder_thumbnail;
  482. Ref<Texture> file_thumbnail;
  483. bool use_thumbnails = (display_mode == DISPLAY_THUMBNAILS);
  484. bool use_folders = search_box->get_text().length() == 0 && split_mode;
  485. if (use_thumbnails) { //thumbnails
  486. files->set_max_columns(0);
  487. files->set_icon_mode(ItemList::ICON_MODE_TOP);
  488. files->set_fixed_column_width(thumbnail_size * 3 / 2);
  489. files->set_max_text_lines(2);
  490. files->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size));
  491. if (!has_icon("ResizedFolder", "EditorIcons")) {
  492. Ref<ImageTexture> folder = get_icon("FolderBig", "EditorIcons");
  493. Image img = folder->get_data();
  494. img.resize(thumbnail_size, thumbnail_size);
  495. Ref<ImageTexture> resized_folder = Ref<ImageTexture>(memnew(ImageTexture));
  496. resized_folder->create_from_image(img, 0);
  497. Theme::get_default()->set_icon("ResizedFolder", "EditorIcons", resized_folder);
  498. }
  499. folder_thumbnail = get_icon("ResizedFolder", "EditorIcons");
  500. if (!has_icon("ResizedFile", "EditorIcons")) {
  501. Ref<ImageTexture> file = get_icon("FileBig", "EditorIcons");
  502. Image img = file->get_data();
  503. img.resize(thumbnail_size, thumbnail_size);
  504. Ref<ImageTexture> resized_file = Ref<ImageTexture>(memnew(ImageTexture));
  505. resized_file->create_from_image(img, 0);
  506. Theme::get_default()->set_icon("ResizedFile", "EditorIcons", resized_file);
  507. }
  508. file_thumbnail = get_icon("ResizedFile", "EditorIcons");
  509. } else {
  510. files->set_icon_mode(ItemList::ICON_MODE_LEFT);
  511. files->set_max_columns(1);
  512. files->set_max_text_lines(1);
  513. files->set_fixed_column_width(0);
  514. files->set_fixed_icon_size(Size2());
  515. }
  516. if (use_folders) {
  517. if (path != "res://") {
  518. if (use_thumbnails) {
  519. files->add_item("..", folder_thumbnail, true);
  520. } else {
  521. files->add_item("..", get_icon("folder", "FileDialog"), true);
  522. }
  523. String bd = path.get_base_dir();
  524. if (bd != "res://" && !bd.ends_with("/"))
  525. bd += "/";
  526. files->set_item_metadata(files->get_item_count() - 1, bd);
  527. }
  528. for (int i = 0; i < efd->get_subdir_count(); i++) {
  529. String dname = efd->get_subdir(i)->get_name();
  530. if (use_thumbnails) {
  531. files->add_item(dname, folder_thumbnail, true);
  532. } else {
  533. files->add_item(dname, get_icon("folder", "FileDialog"), true);
  534. }
  535. files->set_item_metadata(files->get_item_count() - 1, path.plus_file(dname) + "/");
  536. if (cselection.has(dname))
  537. files->select(files->get_item_count() - 1, false);
  538. }
  539. }
  540. List<FileInfo> filelist;
  541. if (search_box->get_text().length()) {
  542. if (search_box->get_text().length() > 1) {
  543. _search(EditorFileSystem::get_singleton()->get_filesystem(), &filelist, 128);
  544. }
  545. filelist.sort();
  546. } else {
  547. for (int i = 0; i < efd->get_file_count(); i++) {
  548. FileInfo fi;
  549. fi.name = efd->get_file(i);
  550. fi.path = path.plus_file(fi.name);
  551. fi.type = efd->get_file_type(i);
  552. if (efd->get_file_meta(i)) {
  553. if (efd->is_missing_sources(i)) {
  554. fi.import_status = 3;
  555. } else if (efd->have_sources_changed(i)) {
  556. fi.import_status = 2;
  557. } else {
  558. fi.import_status = 1;
  559. }
  560. for (int j = 0; j < efd->get_source_count(i); j++) {
  561. String s = EditorImportPlugin::expand_source_path(efd->get_source_file(i, j));
  562. if (efd->is_source_file_missing(i, j)) {
  563. s += " (Missing)";
  564. }
  565. fi.sources.push_back(s);
  566. }
  567. } else {
  568. fi.import_status = 0;
  569. }
  570. filelist.push_back(fi);
  571. }
  572. }
  573. StringName ei = "EditorIcons"; //make it faster..
  574. StringName oi = "Object";
  575. for (List<FileInfo>::Element *E = filelist.front(); E; E = E->next()) {
  576. String fname = E->get().name;
  577. String fp = E->get().path;
  578. StringName type = E->get().type;
  579. Ref<Texture> type_icon;
  580. String tooltip = fname;
  581. if (E->get().import_status == 0) {
  582. if (has_icon(type, ei)) {
  583. type_icon = get_icon(type, ei);
  584. } else {
  585. type_icon = get_icon(oi, ei);
  586. }
  587. } else if (E->get().import_status == 1) {
  588. type_icon = get_icon("DependencyOk", "EditorIcons");
  589. } else if (E->get().import_status == 2) {
  590. type_icon = get_icon("DependencyChanged", "EditorIcons");
  591. tooltip + "\nStatus: Needs Re-Import";
  592. } else if (E->get().import_status == 3) {
  593. type_icon = get_icon("ImportFail", "EditorIcons");
  594. tooltip + "\nStatus: Missing Dependencies";
  595. }
  596. if (E->get().sources.size()) {
  597. for (int i = 0; i < E->get().sources.size(); i++) {
  598. tooltip += "\nSource: " + E->get().sources[i];
  599. }
  600. }
  601. if (use_thumbnails) {
  602. files->add_item(fname, file_thumbnail, true);
  603. files->set_item_metadata(files->get_item_count() - 1, fp);
  604. files->set_item_tag_icon(files->get_item_count() - 1, type_icon);
  605. Array udata;
  606. udata.resize(2);
  607. udata[0] = files->get_item_count() - 1;
  608. udata[1] = fname;
  609. EditorResourcePreview::get_singleton()->queue_resource_preview(fp, this, "_thumbnail_done", udata);
  610. } else {
  611. files->add_item(fname, type_icon, true);
  612. files->set_item_metadata(files->get_item_count() - 1, fp);
  613. }
  614. if (cselection.has(fname))
  615. files->select(files->get_item_count() - 1, false);
  616. files->set_item_tooltip(files->get_item_count() - 1, tooltip);
  617. }
  618. }
  619. void FileSystemDock::_select_file(int p_idx) {
  620. files->select(p_idx, true);
  621. _file_option(FILE_OPEN);
  622. }
  623. void FileSystemDock::_go_to_tree() {
  624. tree->show();
  625. file_list_vb->hide();
  626. _update_tree();
  627. tree->grab_focus();
  628. tree->ensure_cursor_is_visible();
  629. button_favorite->show();
  630. //button_open->hide();
  631. //file_options->hide();
  632. }
  633. void FileSystemDock::_go_to_dir(const String &p_dir) {
  634. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  635. if (da->change_dir(p_dir) == OK) {
  636. path = da->get_current_dir();
  637. _update_files(false);
  638. }
  639. current_path->set_text(path);
  640. memdelete(da);
  641. }
  642. void FileSystemDock::_preview_invalidated(const String &p_path) {
  643. if (display_mode == DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && search_box->get_text() == String() && file_list_vb->is_visible()) {
  644. for (int i = 0; i < files->get_item_count(); i++) {
  645. if (files->get_item_metadata(i) == p_path) {
  646. //re-request preview
  647. Array udata;
  648. udata.resize(2);
  649. udata[0] = i;
  650. udata[1] = files->get_item_text(i);
  651. EditorResourcePreview::get_singleton()->queue_resource_preview(p_path, this, "_thumbnail_done", udata);
  652. break;
  653. }
  654. }
  655. }
  656. }
  657. void FileSystemDock::_fs_changed() {
  658. button_hist_prev->set_disabled(history_pos == 0);
  659. button_hist_next->set_disabled(history_pos + 1 == history.size());
  660. scanning_vb->hide();
  661. split_box->show();
  662. if (!tree->is_hidden()) {
  663. button_favorite->show();
  664. _update_tree();
  665. }
  666. if (!file_list_vb->is_hidden()) {
  667. _update_files(true);
  668. }
  669. set_process(false);
  670. }
  671. void FileSystemDock::_set_scanning_mode() {
  672. split_box->hide();
  673. button_hist_prev->set_disabled(true);
  674. button_hist_next->set_disabled(true);
  675. scanning_vb->show();
  676. set_process(true);
  677. if (EditorFileSystem::get_singleton()->is_scanning()) {
  678. scanning_progress->set_val(EditorFileSystem::get_singleton()->get_scanning_progress() * 100);
  679. } else {
  680. scanning_progress->set_val(0);
  681. }
  682. }
  683. void FileSystemDock::_fw_history() {
  684. if (history_pos < history.size() - 1)
  685. history_pos++;
  686. path = history[history_pos];
  687. if (!tree->is_hidden()) {
  688. _update_tree();
  689. tree->grab_focus();
  690. tree->ensure_cursor_is_visible();
  691. }
  692. if (!file_list_vb->is_hidden()) {
  693. _update_files(false);
  694. current_path->set_text(path);
  695. }
  696. button_hist_prev->set_disabled(history_pos == 0);
  697. button_hist_next->set_disabled(history_pos + 1 == history.size());
  698. }
  699. void FileSystemDock::_bw_history() {
  700. if (history_pos > 0)
  701. history_pos--;
  702. path = history[history_pos];
  703. if (!tree->is_hidden()) {
  704. _update_tree();
  705. tree->grab_focus();
  706. tree->ensure_cursor_is_visible();
  707. }
  708. if (!file_list_vb->is_hidden()) {
  709. _update_files(false);
  710. current_path->set_text(path);
  711. }
  712. button_hist_prev->set_disabled(history_pos == 0);
  713. button_hist_next->set_disabled(history_pos + 1 == history.size());
  714. }
  715. void FileSystemDock::_push_to_history() {
  716. history.resize(history_pos + 1);
  717. if (history[history_pos] != path) {
  718. history.push_back(path);
  719. history_pos++;
  720. }
  721. button_hist_prev->set_disabled(history_pos == 0);
  722. button_hist_next->set_disabled(history_pos + 1 == history.size());
  723. }
  724. void FileSystemDock::_find_inside_move_files(EditorFileSystemDirectory *efsd, Vector<String> &files) {
  725. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  726. _find_inside_move_files(efsd->get_subdir(i), files);
  727. }
  728. for (int i = 0; i < efsd->get_file_count(); i++) {
  729. files.push_back(efsd->get_file_path(i));
  730. }
  731. }
  732. void FileSystemDock::_find_remaps(EditorFileSystemDirectory *efsd, Map<String, String> &renames, List<String> &to_remaps) {
  733. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  734. _find_remaps(efsd->get_subdir(i), renames, to_remaps);
  735. }
  736. for (int i = 0; i < efsd->get_file_count(); i++) {
  737. Vector<String> deps = efsd->get_file_deps(i);
  738. for (int j = 0; j < deps.size(); j++) {
  739. if (renames.has(deps[j])) {
  740. to_remaps.push_back(efsd->get_file_path(i));
  741. break;
  742. }
  743. }
  744. }
  745. }
  746. void FileSystemDock::_rename_operation(const String &p_to_path) {
  747. if (move_files[0] == p_to_path) {
  748. EditorNode::get_singleton()->show_warning(TTR("Same source and destination files, doing nothing."));
  749. return;
  750. }
  751. if (FileAccess::exists(p_to_path)) {
  752. EditorNode::get_singleton()->show_warning("Target file exists, can't overwrite. Delete first.");
  753. return;
  754. }
  755. Map<String, String> renames;
  756. renames[move_files[0]] = p_to_path;
  757. List<String> remap;
  758. _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), renames, remap);
  759. print_line("found files to remap: " + itos(remap.size()));
  760. //perform remaps
  761. for (List<String>::Element *E = remap.front(); E; E = E->next()) {
  762. Error err = ResourceLoader::rename_dependencies(E->get(), renames);
  763. print_line("remapping: " + E->get());
  764. if (err != OK) {
  765. EditorNode::get_singleton()->add_io_error("Can't rename deps for:\n" + E->get() + "\n");
  766. }
  767. }
  768. //finally, perform moves
  769. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  770. Error err = da->rename(move_files[0], p_to_path);
  771. print_line("moving file " + move_files[0] + " to " + p_to_path);
  772. if (err != OK) {
  773. EditorNode::get_singleton()->add_io_error("Error moving file:\n" + move_files[0] + "\n");
  774. }
  775. //rescan everything
  776. memdelete(da);
  777. print_line("call rescan!");
  778. _rescan();
  779. }
  780. void FileSystemDock::_move_operation(const String &p_to_path) {
  781. if (p_to_path == path) {
  782. EditorNode::get_singleton()->show_warning(TTR("Same source and destination paths, doing nothing."));
  783. return;
  784. }
  785. //find files inside dirs to be moved
  786. Vector<String> inside_files;
  787. for (int i = 0; i < move_dirs.size(); i++) {
  788. if (p_to_path.begins_with(move_dirs[i])) {
  789. EditorNode::get_singleton()->show_warning(TTR("Can't move directories to within themselves."));
  790. return;
  791. }
  792. EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->get_path(move_dirs[i]);
  793. if (!efsd)
  794. continue;
  795. _find_inside_move_files(efsd, inside_files);
  796. }
  797. //make list of remaps
  798. Map<String, String> renames;
  799. String repfrom = path == "res://" ? path : String(path + "/");
  800. String repto = p_to_path == "res://" ? p_to_path : String(p_to_path + "/");
  801. for (int i = 0; i < move_files.size(); i++) {
  802. renames[move_files[i]] = move_files[i].replace_first(repfrom, repto);
  803. print_line("move file " + move_files[i] + " -> " + renames[move_files[i]]);
  804. }
  805. for (int i = 0; i < inside_files.size(); i++) {
  806. renames[inside_files[i]] = inside_files[i].replace_first(repfrom, repto);
  807. print_line("inside file " + inside_files[i] + " -> " + renames[inside_files[i]]);
  808. }
  809. //make list of files that will be run the remapping
  810. List<String> remap;
  811. _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), renames, remap);
  812. print_line("found files to remap: " + itos(remap.size()));
  813. //perform remaps
  814. for (List<String>::Element *E = remap.front(); E; E = E->next()) {
  815. Error err = ResourceLoader::rename_dependencies(E->get(), renames);
  816. print_line("remapping: " + E->get());
  817. if (err != OK) {
  818. EditorNode::get_singleton()->add_io_error("Can't rename deps for:\n" + E->get() + "\n");
  819. }
  820. }
  821. //finally, perform moves
  822. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  823. for (int i = 0; i < move_files.size(); i++) {
  824. String to = move_files[i].replace_first(repfrom, repto);
  825. Error err = da->rename(move_files[i], to);
  826. print_line("moving file " + move_files[i] + " to " + to);
  827. if (err != OK) {
  828. EditorNode::get_singleton()->add_io_error("Error moving file:\n" + move_files[i] + "\n");
  829. }
  830. }
  831. for (int i = 0; i < move_dirs.size(); i++) {
  832. String mdir = move_dirs[i];
  833. if (mdir == "res://")
  834. continue;
  835. if (mdir.ends_with("/")) {
  836. mdir = mdir.substr(0, mdir.length() - 1);
  837. }
  838. String to = p_to_path.plus_file(mdir.get_file());
  839. Error err = da->rename(mdir, to);
  840. print_line("moving dir " + mdir + " to " + to);
  841. if (err != OK) {
  842. EditorNode::get_singleton()->add_io_error("Error moving dir:\n" + move_dirs[i] + "\n");
  843. }
  844. }
  845. memdelete(da);
  846. //rescan everything
  847. print_line("call rescan!");
  848. _rescan();
  849. }
  850. void FileSystemDock::_file_option(int p_option) {
  851. switch (p_option) {
  852. case FILE_SHOW_IN_EXPLORER:
  853. case FILE_OPEN: {
  854. int idx = -1;
  855. int selectcount = files->get_selected_items().size();
  856. for (int i = 0; i < files->get_item_count(); i++) {
  857. if (files->is_selected(i)) {
  858. String path = files->get_item_metadata(i);
  859. if (selectcount == 1) {
  860. if (p_option == FILE_SHOW_IN_EXPLORER) {
  861. String dir = Globals::get_singleton()->globalize_path(path);
  862. dir = dir.substr(0, dir.find_last("/"));
  863. OS::get_singleton()->shell_open(String("file://") + dir);
  864. return;
  865. }
  866. if (path.ends_with("/")) {
  867. if (path != "res://") {
  868. path = path.substr(0, path.length() - 1);
  869. }
  870. this->path = path;
  871. _update_files(false);
  872. current_path->set_text(path);
  873. _push_to_history();
  874. } else {
  875. if (ResourceLoader::get_resource_type(path) == "PackedScene") {
  876. editor->open_request(path);
  877. } else {
  878. editor->load_resource(path);
  879. }
  880. }
  881. } else if (selectcount > 1) {
  882. if (ResourceLoader::get_resource_type(path) == "PackedScene") {
  883. editor->open_request(path);
  884. }
  885. }
  886. }
  887. }
  888. } break;
  889. case FILE_INSTANCE: {
  890. Vector<String> paths;
  891. for (int i = 0; i < files->get_item_count(); i++) {
  892. if (!files->is_selected(i))
  893. continue;
  894. String path = files->get_item_metadata(i);
  895. if (EditorFileSystem::get_singleton()->get_file_type(path) == "PackedScene") {
  896. paths.push_back(path);
  897. }
  898. }
  899. if (!paths.empty()) {
  900. emit_signal("instance", paths);
  901. }
  902. } break;
  903. case FILE_DEPENDENCIES: {
  904. int idx = files->get_current();
  905. if (idx < 0 || idx >= files->get_item_count())
  906. break;
  907. String path = files->get_item_metadata(idx);
  908. deps_editor->edit(path);
  909. } break;
  910. case FILE_OWNERS: {
  911. int idx = files->get_current();
  912. if (idx < 0 || idx >= files->get_item_count())
  913. break;
  914. String path = files->get_item_metadata(idx);
  915. owners_editor->show(path);
  916. } break;
  917. case FILE_MOVE: {
  918. move_dirs.clear();
  919. move_files.clear();
  920. for (int i = 0; i < files->get_item_count(); i++) {
  921. String path = files->get_item_metadata(i);
  922. if (!files->is_selected(i))
  923. continue;
  924. if (files->get_item_text(i) == "..") {
  925. EditorNode::get_singleton()->show_warning(TTR("Can't operate on '..'"));
  926. return;
  927. }
  928. if (path.ends_with("/")) {
  929. move_dirs.push_back(path.substr(0, path.length() - 1));
  930. } else {
  931. move_files.push_back(path);
  932. }
  933. }
  934. if (move_dirs.empty() && move_files.size() == 1) {
  935. rename_dialog->clear_filters();
  936. rename_dialog->add_filter("*." + move_files[0].extension());
  937. rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  938. rename_dialog->set_current_path(move_files[0]);
  939. rename_dialog->popup_centered_ratio();
  940. rename_dialog->set_title(TTR("Pick New Name and Location For:") + " " + move_files[0].get_file());
  941. } else {
  942. //just move
  943. move_dialog->popup_centered_ratio();
  944. }
  945. } break;
  946. case FILE_REMOVE: {
  947. Vector<String> torem;
  948. for (int i = 0; i < files->get_item_count(); i++) {
  949. String path = files->get_item_metadata(i);
  950. if (path.ends_with("/") || !files->is_selected(i))
  951. continue;
  952. torem.push_back(path);
  953. }
  954. if (torem.empty()) {
  955. EditorNode::get_singleton()->show_warning(TTR("No files selected!"));
  956. break;
  957. }
  958. remove_dialog->show(torem);
  959. //1) find if used
  960. //2) warn
  961. } break;
  962. case FILE_INFO: {
  963. } break;
  964. case FILE_REIMPORT: {
  965. Vector<String> reimport;
  966. for (int i = 0; i < files->get_item_count(); i++) {
  967. if (!files->is_selected(i))
  968. continue;
  969. String path = files->get_item_metadata(i);
  970. reimport.push_back(path);
  971. }
  972. ERR_FAIL_COND(reimport.size() == 0);
  973. Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(reimport[0]);
  974. ERR_FAIL_COND(!rimd.is_valid());
  975. String editor = rimd->get_editor();
  976. if (editor.begins_with("texture_")) { //compatibility fix for old texture format
  977. editor = "texture";
  978. }
  979. Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor);
  980. ERR_FAIL_COND(!rimp.is_valid());
  981. if (reimport.size() == 1) {
  982. rimp->import_dialog(reimport[0]);
  983. } else {
  984. rimp->reimport_multiple_files(reimport);
  985. }
  986. } break;
  987. case FILE_COPY_PATH:
  988. int idx = files->get_current();
  989. if (idx < 0 || idx >= files->get_item_count())
  990. break;
  991. String path = files->get_item_metadata(idx);
  992. OS::get_singleton()->set_clipboard(path);
  993. }
  994. }
  995. void FileSystemDock::_folder_option(int p_option) {
  996. TreeItem *selected = tree->get_selected();
  997. switch (p_option) {
  998. case FOLDER_EXPAND_ALL:
  999. case FOLDER_COLLAPSE_ALL: {
  1000. bool is_collapsed = (p_option == FOLDER_COLLAPSE_ALL);
  1001. Vector<TreeItem *> needs_check;
  1002. needs_check.push_back(selected);
  1003. while (needs_check.size()) {
  1004. needs_check[0]->set_collapsed(is_collapsed);
  1005. TreeItem *child = needs_check[0]->get_children();
  1006. while (child) {
  1007. needs_check.push_back(child);
  1008. child = child->get_next();
  1009. }
  1010. needs_check.remove(0);
  1011. }
  1012. } break;
  1013. case FOLDER_MOVE: {
  1014. to_move.clear();
  1015. String fpath = selected->get_metadata(tree->get_selected_column());
  1016. if (fpath != "res://") {
  1017. fpath = fpath.ends_with("/") ? fpath.substr(0, fpath.length() - 1) : fpath;
  1018. to_move.push_back(FileOrFolder(fpath, false));
  1019. move_dir_dialog->popup_centered_ratio();
  1020. }
  1021. } break;
  1022. case FOLDER_RENAME: {
  1023. to_rename.path = selected->get_metadata(tree->get_selected_column());
  1024. to_rename.is_file = false;
  1025. if (to_rename.path != "res://") {
  1026. String name = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1).get_file() : to_rename.path.get_file();
  1027. rename_dir_dialog->set_title(TTR("Renaming folder:") + " " + name);
  1028. rename_dialog_text->set_text(name);
  1029. rename_dialog_text->select(0, name.length());
  1030. rename_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  1031. rename_dialog_text->grab_focus();
  1032. }
  1033. } break;
  1034. case FOLDER_REMOVE: {
  1035. Vector<String> remove_folders;
  1036. Vector<String> remove_files;
  1037. String fpath = selected->get_metadata(tree->get_selected_column());
  1038. if (fpath != "res://") {
  1039. remove_folders.push_back(fpath);
  1040. remove_dialog->show(remove_folders);
  1041. }
  1042. } break;
  1043. case FOLDER_NEW_FOLDER: {
  1044. make_dir_dialog_text->set_text("new folder");
  1045. make_dir_dialog_text->select_all();
  1046. make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  1047. make_dir_dialog_text->grab_focus();
  1048. } break;
  1049. case FOLDER_COPY_PATH: {
  1050. String fpath = selected->get_metadata(tree->get_selected_column());
  1051. OS::get_singleton()->set_clipboard(fpath);
  1052. } break;
  1053. case FOLDER_SHOW_IN_EXPLORER: {
  1054. String fpath = selected->get_metadata(tree->get_selected_column());
  1055. String dir = Globals::get_singleton()->globalize_path(fpath);
  1056. OS::get_singleton()->shell_open(String("file://") + dir);
  1057. } break;
  1058. }
  1059. }
  1060. void FileSystemDock::_open_pressed() {
  1061. TreeItem *sel = tree->get_selected();
  1062. if (!sel) {
  1063. return;
  1064. }
  1065. path = sel->get_metadata(0);
  1066. /*if (path!="res://" && path.ends_with("/")) {
  1067. path=path.substr(0,path.length()-1);
  1068. }*/
  1069. //tree_mode=false;
  1070. if (split_mode) {
  1071. tree->hide();
  1072. file_list_vb->show();
  1073. button_favorite->hide();
  1074. }
  1075. //file_options->show();
  1076. _update_files(false);
  1077. current_path->set_text(path);
  1078. _push_to_history();
  1079. // emit_signal("open",path);
  1080. }
  1081. void FileSystemDock::_search_changed(const String &p_text) {
  1082. if (!search_box->is_visible())
  1083. return; //wtf
  1084. _update_files(false);
  1085. }
  1086. void FileSystemDock::_rescan() {
  1087. _set_scanning_mode();
  1088. EditorFileSystem::get_singleton()->scan();
  1089. }
  1090. void FileSystemDock::fix_dependencies(const String &p_for_file) {
  1091. deps_editor->edit(p_for_file);
  1092. }
  1093. void FileSystemDock::focus_on_filter() {
  1094. if (!search_box->is_visible()) {
  1095. // Tree mode, switch to files list with search box
  1096. tree->hide();
  1097. file_list_vb->show();
  1098. button_favorite->hide();
  1099. }
  1100. search_box->grab_focus();
  1101. }
  1102. void FileSystemDock::set_display_mode(int p_mode) {
  1103. if (p_mode == display_mode)
  1104. return;
  1105. button_display_mode->set_pressed(p_mode == DISPLAY_LIST);
  1106. _change_file_display();
  1107. }
  1108. Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  1109. if (p_from == tree) {
  1110. TreeItem *selected = tree->get_selected();
  1111. if (!selected)
  1112. return Variant();
  1113. String path = selected->get_metadata(0);
  1114. if (path == String())
  1115. return Variant();
  1116. if (!path.ends_with("/"))
  1117. path = path + "/";
  1118. Vector<String> paths;
  1119. paths.push_back(path);
  1120. Dictionary d = EditorNode::get_singleton()->drag_files(paths, p_from);
  1121. if (selected->get_parent() && tree->get_root()->get_children() == selected->get_parent()) {
  1122. //a favorite.. treat as such
  1123. d["type"] = "favorite";
  1124. }
  1125. return d;
  1126. }
  1127. if (p_from == files) {
  1128. List<int> seldirs;
  1129. List<int> selfiles;
  1130. for (int i = 0; i < files->get_item_count(); i++) {
  1131. if (files->is_selected(i)) {
  1132. String path = files->get_item_metadata(i);
  1133. if (path.ends_with("/"))
  1134. seldirs.push_back(i);
  1135. else
  1136. selfiles.push_back(i);
  1137. }
  1138. }
  1139. if (seldirs.empty() && selfiles.empty())
  1140. return Variant();
  1141. //if (seldirs.size() && selfiles.size())
  1142. // return Variant(); //can't really mix files and dirs (i think?) - yes you can, commenting
  1143. /*if (selfiles.size()==1) {
  1144. Ref<Resource> resource = ResourceLoader::load(files->get_item_metadata(selfiles.front()->get()));
  1145. if (resource.is_valid()) {
  1146. return EditorNode::get_singleton()->drag_resource(resource,p_from);
  1147. }
  1148. }*/
  1149. if (selfiles.size() > 0 && seldirs.size() == 0) {
  1150. Vector<String> fnames;
  1151. for (List<int>::Element *E = selfiles.front(); E; E = E->next()) {
  1152. fnames.push_back(files->get_item_metadata(E->get()));
  1153. }
  1154. return EditorNode::get_singleton()->drag_files(fnames, p_from);
  1155. }
  1156. if (selfiles.size() > 0 || seldirs.size() > 0) {
  1157. Vector<String> fnames;
  1158. for (List<int>::Element *E = selfiles.front(); E; E = E->next()) {
  1159. fnames.push_back(files->get_item_metadata(E->get()));
  1160. }
  1161. for (List<int>::Element *E = seldirs.front(); E; E = E->next()) {
  1162. fnames.push_back(files->get_item_metadata(E->get()));
  1163. }
  1164. return EditorNode::get_singleton()->drag_files_and_dirs(fnames, p_from);
  1165. }
  1166. }
  1167. return Variant();
  1168. }
  1169. bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  1170. Dictionary drag_data = p_data;
  1171. if (drag_data.has("type") && String(drag_data["type"]) == "favorite") {
  1172. //moving favorite around
  1173. TreeItem *ti = tree->get_item_at_pos(p_point);
  1174. if (!ti)
  1175. return false;
  1176. int what = tree->get_drop_section_at_pos(p_point);
  1177. if (ti == tree->get_root()->get_children()) {
  1178. return (what == 1); //the parent, first fav
  1179. }
  1180. if (ti->get_parent() && tree->get_root()->get_children() == ti->get_parent()) {
  1181. return true; // a favorite
  1182. }
  1183. if (ti == tree->get_root()->get_children()->get_next()) {
  1184. return (what == -1); //the tree, last fav
  1185. }
  1186. return false;
  1187. }
  1188. if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
  1189. return true;
  1190. }
  1191. if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
  1192. Vector<String> fnames = drag_data["files"];
  1193. if (p_from == files) {
  1194. int at_pos = files->get_item_at_pos(p_point);
  1195. if (at_pos != -1) {
  1196. String dir = files->get_item_metadata(at_pos);
  1197. if (dir.ends_with("/"))
  1198. return true;
  1199. }
  1200. }
  1201. if (p_from == tree) {
  1202. TreeItem *ti = tree->get_item_at_pos(p_point);
  1203. if (!ti)
  1204. return false;
  1205. String path = ti->get_metadata(0);
  1206. if (path == String())
  1207. return false;
  1208. return true;
  1209. }
  1210. }
  1211. return false;
  1212. }
  1213. void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  1214. if (!can_drop_data_fw(p_point, p_data, p_from))
  1215. return;
  1216. Dictionary drag_data = p_data;
  1217. if (drag_data.has("type") && String(drag_data["type"]) == "favorite") {
  1218. //moving favorite around
  1219. TreeItem *ti = tree->get_item_at_pos(p_point);
  1220. if (!ti)
  1221. return;
  1222. Vector<String> files = drag_data["files"];
  1223. ERR_FAIL_COND(files.size() != 1);
  1224. String swap = files[0];
  1225. if (swap != "res://" && swap.ends_with("/")) {
  1226. swap = swap.substr(0, swap.length() - 1);
  1227. }
  1228. int what = tree->get_drop_section_at_pos(p_point);
  1229. TreeItem *swap_item = NULL;
  1230. if (ti == tree->get_root()->get_children()) {
  1231. swap_item = tree->get_root()->get_children()->get_children();
  1232. } else if (ti->get_parent() && tree->get_root()->get_children() == ti->get_parent()) {
  1233. if (what == -1) {
  1234. swap_item = ti;
  1235. } else {
  1236. swap_item = ti->get_next();
  1237. }
  1238. }
  1239. String swap_with;
  1240. if (swap_item) {
  1241. swap_with = swap_item->get_metadata(0);
  1242. if (swap_with != "res://" && swap_with.ends_with("/")) {
  1243. swap_with = swap_with.substr(0, swap_with.length() - 1);
  1244. }
  1245. }
  1246. if (swap == swap_with)
  1247. return;
  1248. Vector<String> dirs = EditorSettings::get_singleton()->get_favorite_dirs();
  1249. ERR_FAIL_COND(dirs.find(swap) == -1);
  1250. ERR_FAIL_COND(swap_with != String() && dirs.find(swap_with) == -1);
  1251. dirs.erase(swap);
  1252. if (swap_with == String()) {
  1253. dirs.push_back(swap);
  1254. } else {
  1255. int idx = dirs.find(swap_with);
  1256. dirs.insert(idx, swap);
  1257. }
  1258. EditorSettings::get_singleton()->set_favorite_dirs(dirs);
  1259. _update_tree();
  1260. return;
  1261. }
  1262. if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
  1263. Ref<Resource> res = drag_data["resource"];
  1264. if (!res.is_valid()) {
  1265. return;
  1266. }
  1267. if (p_from == tree) {
  1268. TreeItem *ti = tree->get_item_at_pos(p_point);
  1269. if (!ti)
  1270. return;
  1271. String path = ti->get_metadata(0);
  1272. if (path == String())
  1273. return;
  1274. EditorNode::get_singleton()->save_resource_as(res, path);
  1275. return;
  1276. }
  1277. if (p_from == files) {
  1278. String save_path = path;
  1279. int at_pos = files->get_item_at_pos(p_point);
  1280. if (at_pos != -1) {
  1281. String to_dir = files->get_item_metadata(at_pos);
  1282. if (to_dir.ends_with("/")) {
  1283. save_path = to_dir;
  1284. if (save_path != "res://")
  1285. save_path = save_path.substr(0, save_path.length() - 1);
  1286. }
  1287. }
  1288. EditorNode::get_singleton()->save_resource_as(res, save_path);
  1289. return;
  1290. }
  1291. }
  1292. if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
  1293. if (p_from == files || p_from == tree) {
  1294. String to_dir;
  1295. if (p_from == files) {
  1296. int at_pos = files->get_item_at_pos(p_point);
  1297. ERR_FAIL_COND(at_pos == -1);
  1298. to_dir = files->get_item_metadata(at_pos);
  1299. } else {
  1300. TreeItem *ti = tree->get_item_at_pos(p_point);
  1301. if (!ti)
  1302. return;
  1303. to_dir = ti->get_metadata(0);
  1304. ERR_FAIL_COND(to_dir == String());
  1305. }
  1306. if (to_dir != "res://" && to_dir.ends_with("/")) {
  1307. to_dir = to_dir.substr(0, to_dir.length() - 1);
  1308. }
  1309. Vector<String> fnames = drag_data["files"];
  1310. move_files.clear();
  1311. move_dirs.clear();
  1312. for (int i = 0; i < fnames.size(); i++) {
  1313. if (fnames[i].ends_with("/"))
  1314. move_dirs.push_back(fnames[i]);
  1315. else
  1316. move_files.push_back(fnames[i]);
  1317. }
  1318. _move_operation(to_dir);
  1319. }
  1320. }
  1321. }
  1322. void FileSystemDock::_files_list_rmb_select(int p_item, const Vector2 &p_pos) {
  1323. Vector<String> filenames;
  1324. bool all_scenes = true;
  1325. bool all_can_reimport = true;
  1326. Set<String> types;
  1327. for (int i = 0; i < files->get_item_count(); i++) {
  1328. if (!files->is_selected(i))
  1329. continue;
  1330. String path = files->get_item_metadata(i);
  1331. if (files->get_item_text(i) == "..") {
  1332. // no operate on ..
  1333. return;
  1334. }
  1335. if (path.ends_with("/")) {
  1336. //no operate on dirs
  1337. return;
  1338. }
  1339. EditorFileSystemDirectory *efsd = NULL;
  1340. int pos;
  1341. efsd = EditorFileSystem::get_singleton()->find_file(path, &pos);
  1342. if (efsd) {
  1343. if (!efsd->get_file_meta(pos)) {
  1344. all_can_reimport = false;
  1345. } else {
  1346. Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(path);
  1347. if (rimd.is_valid()) {
  1348. String editor = rimd->get_editor();
  1349. if (editor.begins_with("texture_")) { //compatibility fix for old texture format
  1350. editor = "texture";
  1351. }
  1352. types.insert(editor);
  1353. } else {
  1354. all_can_reimport = false;
  1355. }
  1356. }
  1357. } else {
  1358. all_can_reimport = false;
  1359. }
  1360. filenames.push_back(path);
  1361. if (EditorFileSystem::get_singleton()->get_file_type(path) != "PackedScene")
  1362. all_scenes = false;
  1363. }
  1364. if (filenames.size() == 0)
  1365. return;
  1366. file_options->clear();
  1367. file_options->set_size(Size2(1, 1));
  1368. file_options->add_item(TTR("Open"), FILE_OPEN);
  1369. if (all_scenes) {
  1370. file_options->add_item(TTR("Instance"), FILE_INSTANCE);
  1371. }
  1372. file_options->add_separator();
  1373. if (filenames.size() == 1) {
  1374. file_options->add_item(TTR("Edit Dependencies.."), FILE_DEPENDENCIES);
  1375. file_options->add_item(TTR("View Owners.."), FILE_OWNERS);
  1376. file_options->add_separator();
  1377. }
  1378. if (filenames.size() == 1) {
  1379. file_options->add_item(TTR("Copy Path"), FILE_COPY_PATH);
  1380. file_options->add_item(TTR("Rename or Move.."), FILE_MOVE);
  1381. } else {
  1382. file_options->add_item(TTR("Move To.."), FILE_MOVE);
  1383. }
  1384. file_options->add_item(TTR("Delete"), FILE_REMOVE);
  1385. //file_options->add_item(TTR("Info"),FILE_INFO);
  1386. file_options->add_separator();
  1387. file_options->add_item(TTR("Show In File Manager"), FILE_SHOW_IN_EXPLORER);
  1388. if (all_can_reimport && types.size() == 1) { //all can reimport and are of the same type
  1389. bool valid = true;
  1390. Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(types.front()->get());
  1391. if (rimp.is_valid()) {
  1392. if (filenames.size() > 1 && !rimp->can_reimport_multiple_files()) {
  1393. valid = false;
  1394. }
  1395. } else {
  1396. valid = false;
  1397. }
  1398. if (valid) {
  1399. file_options->add_separator();
  1400. file_options->add_item(TTR("Re-Import.."), FILE_REIMPORT);
  1401. }
  1402. }
  1403. file_options->set_pos(files->get_global_pos() + p_pos);
  1404. file_options->popup();
  1405. }
  1406. void FileSystemDock::_bind_methods() {
  1407. ObjectTypeDB::bind_method(_MD("_update_tree"), &FileSystemDock::_update_tree);
  1408. ObjectTypeDB::bind_method(_MD("_rescan"), &FileSystemDock::_rescan);
  1409. ObjectTypeDB::bind_method(_MD("_favorites_pressed"), &FileSystemDock::_favorites_pressed);
  1410. // ObjectTypeDB::bind_method(_MD("_instance_pressed"),&ScenesDock::_instance_pressed);
  1411. ObjectTypeDB::bind_method(_MD("_open_pressed"), &FileSystemDock::_open_pressed);
  1412. ObjectTypeDB::bind_method(_MD("_thumbnail_done"), &FileSystemDock::_thumbnail_done);
  1413. ObjectTypeDB::bind_method(_MD("_select_file"), &FileSystemDock::_select_file);
  1414. ObjectTypeDB::bind_method(_MD("_go_to_tree"), &FileSystemDock::_go_to_tree);
  1415. ObjectTypeDB::bind_method(_MD("_go_to_dir"), &FileSystemDock::_go_to_dir);
  1416. ObjectTypeDB::bind_method(_MD("navigate_to_path"), &FileSystemDock::navigate_to_path);
  1417. ObjectTypeDB::bind_method(_MD("_change_file_display"), &FileSystemDock::_change_file_display);
  1418. ObjectTypeDB::bind_method(_MD("_fw_history"), &FileSystemDock::_fw_history);
  1419. ObjectTypeDB::bind_method(_MD("_bw_history"), &FileSystemDock::_bw_history);
  1420. ObjectTypeDB::bind_method(_MD("_fs_changed"), &FileSystemDock::_fs_changed);
  1421. ObjectTypeDB::bind_method(_MD("_dir_selected"), &FileSystemDock::_dir_selected);
  1422. ObjectTypeDB::bind_method(_MD("_file_option"), &FileSystemDock::_file_option);
  1423. ObjectTypeDB::bind_method(_MD("_move_operation"), &FileSystemDock::_move_operation);
  1424. ObjectTypeDB::bind_method(_MD("_rename_operation"), &FileSystemDock::_rename_operation);
  1425. ObjectTypeDB::bind_method(_MD("_folder_option"), &FileSystemDock::_folder_option);
  1426. ObjectTypeDB::bind_method(_MD("_dir_rmb_pressed"), &FileSystemDock::_dir_rmb_pressed);
  1427. ObjectTypeDB::bind_method(_MD("_make_dir_confirm"), &FileSystemDock::_make_dir_confirm);
  1428. ObjectTypeDB::bind_method(_MD("_rename_operation_confirm"), &FileSystemDock::_rename_operation_confirm);
  1429. ObjectTypeDB::bind_method(_MD("_move_operation_confirm"), &FileSystemDock::_move_operation_confirm);
  1430. ObjectTypeDB::bind_method(_MD("_search_changed"), &FileSystemDock::_search_changed);
  1431. ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &FileSystemDock::get_drag_data_fw);
  1432. ObjectTypeDB::bind_method(_MD("can_drop_data_fw"), &FileSystemDock::can_drop_data_fw);
  1433. ObjectTypeDB::bind_method(_MD("drop_data_fw"), &FileSystemDock::drop_data_fw);
  1434. ObjectTypeDB::bind_method(_MD("_files_list_rmb_select"), &FileSystemDock::_files_list_rmb_select);
  1435. ObjectTypeDB::bind_method(_MD("_preview_invalidated"), &FileSystemDock::_preview_invalidated);
  1436. ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::STRING_ARRAY, "files")));
  1437. ADD_SIGNAL(MethodInfo("open"));
  1438. }
  1439. FileSystemDock::FileSystemDock(EditorNode *p_editor) {
  1440. editor = p_editor;
  1441. HBoxContainer *toolbar_hbc = memnew(HBoxContainer);
  1442. add_child(toolbar_hbc);
  1443. button_hist_prev = memnew(ToolButton);
  1444. toolbar_hbc->add_child(button_hist_prev);
  1445. button_hist_prev->set_disabled(true);
  1446. button_hist_prev->set_tooltip(TTR("Previous Directory"));
  1447. button_hist_next = memnew(ToolButton);
  1448. toolbar_hbc->add_child(button_hist_next);
  1449. button_hist_next->set_disabled(true);
  1450. button_hist_prev->set_focus_mode(FOCUS_NONE);
  1451. button_hist_next->set_focus_mode(FOCUS_NONE);
  1452. button_hist_next->set_tooltip(TTR("Next Directory"));
  1453. current_path = memnew(LineEdit);
  1454. current_path->set_h_size_flags(SIZE_EXPAND_FILL);
  1455. toolbar_hbc->add_child(current_path);
  1456. button_reload = memnew(Button);
  1457. button_reload->set_flat(true);
  1458. button_reload->connect("pressed", this, "_rescan");
  1459. toolbar_hbc->add_child(button_reload);
  1460. button_reload->set_focus_mode(FOCUS_NONE);
  1461. button_reload->set_tooltip(TTR("Re-Scan Filesystem"));
  1462. button_reload->hide();
  1463. //toolbar_hbc->add_spacer();
  1464. button_favorite = memnew(Button);
  1465. button_favorite->set_flat(true);
  1466. button_favorite->set_toggle_mode(true);
  1467. button_favorite->connect("pressed", this, "_favorites_pressed");
  1468. toolbar_hbc->add_child(button_favorite);
  1469. button_favorite->set_tooltip(TTR("Toggle folder status as Favorite"));
  1470. button_favorite->set_focus_mode(FOCUS_NONE);
  1471. // Control *spacer = memnew( Control);
  1472. /*
  1473. button_open = memnew( Button );
  1474. button_open->set_flat(true);
  1475. button_open->connect("pressed",this,"_open_pressed");
  1476. toolbar_hbc->add_child(button_open);
  1477. button_open->hide();
  1478. button_open->set_focus_mode(FOCUS_NONE);
  1479. button_open->set_tooltip("Open the selected file.\nOpen as scene if a scene, or as resource otherwise.");
  1480. button_instance = memnew( Button );
  1481. button_instance->set_flat(true);
  1482. button_instance->connect("pressed",this,"_instance_pressed");
  1483. toolbar_hbc->add_child(button_instance);
  1484. button_instance->hide();
  1485. button_instance->set_focus_mode(FOCUS_NONE);
  1486. button_instance->set_tooltip(TTR("Instance the selected scene(s) as child of the selected node."));
  1487. */
  1488. file_options = memnew(PopupMenu);
  1489. add_child(file_options);
  1490. folder_options = memnew(PopupMenu);
  1491. add_child(folder_options);
  1492. move_dir_dialog = memnew(EditorDirDialog);
  1493. move_dir_dialog->get_ok()->set_text(TTR("Move"));
  1494. add_child(move_dir_dialog);
  1495. move_dir_dialog->connect("dir_selected", this, "_move_operation_confirm");
  1496. rename_dir_dialog = memnew(ConfirmationDialog);
  1497. VBoxContainer *rename_dialog_vb = memnew(VBoxContainer);
  1498. rename_dir_dialog->add_child(rename_dialog_vb);
  1499. rename_dialog_text = memnew(LineEdit);
  1500. rename_dialog_vb->add_margin_child(TTR("Name:"), rename_dialog_text);
  1501. rename_dir_dialog->get_ok()->set_text(TTR("Rename"));
  1502. add_child(rename_dir_dialog);
  1503. rename_dir_dialog->set_child_rect(rename_dialog_vb);
  1504. rename_dir_dialog->register_text_enter(rename_dialog_text);
  1505. rename_dir_dialog->connect("confirmed", this, "_rename_operation_confirm");
  1506. make_dir_dialog = memnew(ConfirmationDialog);
  1507. make_dir_dialog->set_title(TTR("Create Folder"));
  1508. VBoxContainer *make_folder_dialog_vb = memnew(VBoxContainer);
  1509. make_dir_dialog_text = memnew(LineEdit);
  1510. make_folder_dialog_vb->add_margin_child(TTR("Name:"), make_dir_dialog_text);
  1511. add_child(make_dir_dialog);
  1512. make_dir_dialog->add_child(make_folder_dialog_vb);
  1513. make_dir_dialog->set_child_rect(make_folder_dialog_vb);
  1514. make_dir_dialog->register_text_enter(make_dir_dialog_text);
  1515. make_dir_dialog->connect("confirmed", this, "_make_dir_confirm");
  1516. split_box = memnew(VSplitContainer);
  1517. add_child(split_box);
  1518. split_box->set_v_size_flags(SIZE_EXPAND_FILL);
  1519. tree = memnew(Tree);
  1520. tree->set_hide_root(true);
  1521. split_box->add_child(tree);
  1522. tree->set_drag_forwarding(this);
  1523. tree->set_allow_rmb_select(true);
  1524. //tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1525. tree->connect("item_edited", this, "_favorite_toggled");
  1526. tree->connect("item_activated", this, "_open_pressed");
  1527. tree->connect("cell_selected", this, "_dir_selected");
  1528. tree->connect("item_rmb_selected", this, "_dir_rmb_pressed");
  1529. files = memnew(ItemList);
  1530. files->set_v_size_flags(SIZE_EXPAND_FILL);
  1531. files->set_select_mode(ItemList::SELECT_MULTI);
  1532. files->set_drag_forwarding(this);
  1533. files->connect("item_rmb_selected", this, "_files_list_rmb_select");
  1534. files->set_allow_rmb_select(true);
  1535. file_list_vb = memnew(VBoxContainer);
  1536. split_box->add_child(file_list_vb);
  1537. file_list_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  1538. path_hb = memnew(HBoxContainer);
  1539. file_list_vb->add_child(path_hb);
  1540. button_back = memnew(ToolButton);
  1541. path_hb->add_child(button_back);
  1542. button_back->hide();
  1543. search_box = memnew(LineEdit);
  1544. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  1545. path_hb->add_child(search_box);
  1546. search_box->connect("text_changed", this, "_search_changed");
  1547. search_icon = memnew(TextureFrame);
  1548. search_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED);
  1549. path_hb->add_child(search_icon);
  1550. button_display_mode = memnew(ToolButton);
  1551. path_hb->add_child(button_display_mode);
  1552. button_display_mode->set_toggle_mode(true);
  1553. file_list_vb->add_child(files);
  1554. scanning_vb = memnew(VBoxContainer);
  1555. Label *slabel = memnew(Label);
  1556. slabel->set_text("Scanning Files,\nPlease Wait..");
  1557. slabel->set_align(Label::ALIGN_CENTER);
  1558. scanning_vb->add_child(slabel);
  1559. scanning_progress = memnew(ProgressBar);
  1560. scanning_vb->add_child(scanning_progress);
  1561. add_child(scanning_vb);
  1562. scanning_vb->hide();
  1563. deps_editor = memnew(DependencyEditor);
  1564. add_child(deps_editor);
  1565. owners_editor = memnew(DependencyEditorOwners(editor));
  1566. add_child(owners_editor);
  1567. remove_dialog = memnew(DependencyRemoveDialog);
  1568. add_child(remove_dialog);
  1569. move_dialog = memnew(EditorDirDialog);
  1570. add_child(move_dialog);
  1571. move_dialog->connect("dir_selected", this, "_move_operation");
  1572. move_dialog->get_ok()->set_text(TTR("Move"));
  1573. rename_dialog = memnew(EditorFileDialog);
  1574. rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  1575. rename_dialog->connect("file_selected", this, "_rename_operation");
  1576. add_child(rename_dialog);
  1577. updating_tree = false;
  1578. initialized = false;
  1579. history.push_back("res://");
  1580. history_pos = 0;
  1581. split_mode = false;
  1582. display_mode = DISPLAY_THUMBNAILS;
  1583. path = "res://";
  1584. add_constant_override("separation", 3);
  1585. }
  1586. FileSystemDock::~FileSystemDock() {
  1587. }