filesystem_dock.cpp 59 KB

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