filesystem_dock.cpp 57 KB

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