filesystem_dock.cpp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  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. navigate_to_path(fpath);
  475. } else {
  476. if (ResourceLoader::get_resource_type(fpath) == "PackedScene") {
  477. editor->open_request(fpath);
  478. } else {
  479. editor->load_resource(fpath);
  480. }
  481. }
  482. }
  483. void FileSystemDock::_go_to_tree() {
  484. if (low_height_mode) {
  485. tree->show();
  486. button_favorite->show();
  487. file_list_vb->hide();
  488. }
  489. _update_tree(true);
  490. tree->grab_focus();
  491. tree->ensure_cursor_is_visible();
  492. //button_open->hide();
  493. //file_options->hide();
  494. }
  495. void FileSystemDock::_preview_invalidated(const String &p_path) {
  496. if (display_mode == DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && search_box->get_text() == String() && file_list_vb->is_visible_in_tree()) {
  497. for (int i = 0; i < files->get_item_count(); i++) {
  498. if (files->get_item_metadata(i) == p_path) {
  499. //re-request preview
  500. Array udata;
  501. udata.resize(2);
  502. udata[0] = i;
  503. udata[1] = files->get_item_text(i);
  504. EditorResourcePreview::get_singleton()->queue_resource_preview(p_path, this, "_thumbnail_done", udata);
  505. break;
  506. }
  507. }
  508. }
  509. }
  510. void FileSystemDock::_fs_changed() {
  511. button_hist_prev->set_disabled(history_pos == 0);
  512. button_hist_next->set_disabled(history_pos == history.size() - 1);
  513. scanning_vb->hide();
  514. split_box->show();
  515. if (tree->is_visible()) {
  516. _update_tree(true);
  517. }
  518. if (file_list_vb->is_visible()) {
  519. _update_files(true);
  520. }
  521. set_process(false);
  522. }
  523. void FileSystemDock::_set_scanning_mode() {
  524. button_hist_prev->set_disabled(true);
  525. button_hist_next->set_disabled(true);
  526. split_box->hide();
  527. scanning_vb->show();
  528. set_process(true);
  529. if (EditorFileSystem::get_singleton()->is_scanning()) {
  530. scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100);
  531. } else {
  532. scanning_progress->set_value(0);
  533. }
  534. }
  535. void FileSystemDock::_fw_history() {
  536. if (history_pos < history.size() - 1)
  537. history_pos++;
  538. _update_history();
  539. }
  540. void FileSystemDock::_bw_history() {
  541. if (history_pos > 0)
  542. history_pos--;
  543. _update_history();
  544. }
  545. void FileSystemDock::_update_history() {
  546. path = history[history_pos];
  547. current_path->set_text(path);
  548. if (tree->is_visible()) {
  549. _update_tree(true);
  550. tree->grab_focus();
  551. tree->ensure_cursor_is_visible();
  552. }
  553. if (file_list_vb->is_visible()) {
  554. _update_files(false);
  555. }
  556. button_hist_prev->set_disabled(history_pos == 0);
  557. button_hist_next->set_disabled(history_pos == history.size() - 1);
  558. }
  559. void FileSystemDock::_push_to_history() {
  560. if (history[history_pos] != path) {
  561. history.resize(history_pos + 1);
  562. history.push_back(path);
  563. history_pos++;
  564. if (history.size() > history_max_size) {
  565. history.remove(0);
  566. history_pos = history_max_size - 1;
  567. }
  568. }
  569. button_hist_prev->set_disabled(history_pos == 0);
  570. button_hist_next->set_disabled(history_pos == history.size() - 1);
  571. }
  572. void FileSystemDock::_get_all_files_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files) const {
  573. if (efsd == NULL)
  574. return;
  575. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  576. _get_all_files_in_dir(efsd->get_subdir(i), files);
  577. }
  578. for (int i = 0; i < efsd->get_file_count(); i++) {
  579. files.push_back(efsd->get_file_path(i));
  580. }
  581. }
  582. void FileSystemDock::_find_remaps(EditorFileSystemDirectory *efsd, const Map<String, String> &renames, Vector<String> &to_remaps) const {
  583. for (int i = 0; i < efsd->get_subdir_count(); i++) {
  584. _find_remaps(efsd->get_subdir(i), renames, to_remaps);
  585. }
  586. for (int i = 0; i < efsd->get_file_count(); i++) {
  587. Vector<String> deps = efsd->get_file_deps(i);
  588. for (int j = 0; j < deps.size(); j++) {
  589. if (renames.has(deps[j])) {
  590. to_remaps.push_back(efsd->get_file_path(i));
  591. break;
  592. }
  593. }
  594. }
  595. }
  596. void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_renames) const {
  597. //Ensure folder paths end with "/"
  598. String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/");
  599. String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/");
  600. if (new_path == old_path) {
  601. return;
  602. } else if (old_path == "res://") {
  603. EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root."));
  604. return;
  605. } else if (!p_item.is_file && new_path.begins_with(old_path)) {
  606. //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/"
  607. EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.\n") + old_path + "\n");
  608. return;
  609. }
  610. //Build a list of files which will have new paths as a result of this operation
  611. Vector<String> changed_paths;
  612. if (p_item.is_file) {
  613. changed_paths.push_back(old_path);
  614. } else {
  615. _get_all_files_in_dir(EditorFileSystem::get_singleton()->get_filesystem_path(old_path), changed_paths);
  616. }
  617. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  618. print_line("Moving " + old_path + " -> " + new_path);
  619. Error err = da->rename(old_path, new_path);
  620. if (err == OK) {
  621. //Move/Rename any corresponding import settings too
  622. if (p_item.is_file && FileAccess::exists(old_path + ".import")) {
  623. err = da->rename(old_path + ".import", new_path + ".import");
  624. if (err != OK) {
  625. EditorNode::get_singleton()->add_io_error(TTR("Error moving:\n") + old_path + ".import\n");
  626. }
  627. }
  628. // update scene if it is open
  629. for (int i = 0; i < changed_paths.size(); ++i) {
  630. String new_item_path = p_item.is_file ? new_path : changed_paths[i].replace_first(old_path, new_path);
  631. if (ResourceLoader::get_resource_type(new_item_path) == "PackedScene" && editor->is_scene_open(changed_paths[i])) {
  632. EditorData *ed = &editor->get_editor_data();
  633. for (int j = 0; j < ed->get_edited_scene_count(); j++) {
  634. if (ed->get_scene_path(j) == changed_paths[i]) {
  635. ed->get_edited_scene_root(j)->set_filename(new_item_path);
  636. break;
  637. }
  638. }
  639. }
  640. }
  641. //Only treat as a changed dependency if it was successfully moved
  642. for (int i = 0; i < changed_paths.size(); ++i) {
  643. p_renames[changed_paths[i]] = changed_paths[i].replace_first(old_path, new_path);
  644. print_line(" Remap: " + changed_paths[i] + " -> " + p_renames[changed_paths[i]]);
  645. }
  646. } else {
  647. EditorNode::get_singleton()->add_io_error(TTR("Error moving:\n") + old_path + "\n");
  648. }
  649. memdelete(da);
  650. }
  651. void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const {
  652. //Ensure folder paths end with "/"
  653. String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/");
  654. String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/");
  655. if (new_path == old_path) {
  656. return;
  657. } else if (old_path == "res://") {
  658. EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root."));
  659. return;
  660. } else if (!p_item.is_file && new_path.begins_with(old_path)) {
  661. //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/"
  662. EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.\n") + old_path + "\n");
  663. return;
  664. }
  665. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  666. print_line("Duplicating " + old_path + " -> " + new_path);
  667. Error err = da->copy(old_path, new_path);
  668. if (err == OK) {
  669. //Move/Rename any corresponding import settings too
  670. if (p_item.is_file && FileAccess::exists(old_path + ".import")) {
  671. err = da->copy(old_path + ".import", new_path + ".import");
  672. if (err != OK) {
  673. EditorNode::get_singleton()->add_io_error(TTR("Error duplicating:\n") + old_path + ".import\n");
  674. }
  675. }
  676. } else {
  677. EditorNode::get_singleton()->add_io_error(TTR("Error duplicating:\n") + old_path + "\n");
  678. }
  679. memdelete(da);
  680. }
  681. void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &p_renames) const {
  682. //The following code assumes that the following holds:
  683. // 1) EditorFileSystem contains the old paths/folder structure from before the rename/move.
  684. // 2) ResourceLoader can use the new paths without needing to call rescan.
  685. Vector<String> remaps;
  686. _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps);
  687. for (int i = 0; i < remaps.size(); ++i) {
  688. //Because we haven't called a rescan yet the found remap might still be an old path itself.
  689. String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i];
  690. print_line("Remapping dependencies for: " + file);
  691. Error err = ResourceLoader::rename_dependencies(file, p_renames);
  692. if (err == OK) {
  693. if (ResourceLoader::get_resource_type(file) == "PackedScene")
  694. editor->reload_scene(file);
  695. } else {
  696. EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:\n") + remaps[i] + "\n");
  697. }
  698. }
  699. }
  700. void FileSystemDock::_make_dir_confirm() {
  701. String dir_name = make_dir_dialog_text->get_text().strip_edges();
  702. if (dir_name.length() == 0) {
  703. EditorNode::get_singleton()->show_warning(TTR("No name provided"));
  704. return;
  705. } else if (dir_name.find("/") != -1 || dir_name.find("\\") != -1 || dir_name.find(":") != -1) {
  706. EditorNode::get_singleton()->show_warning(TTR("Provided name contains invalid characters"));
  707. return;
  708. }
  709. print_line("Making folder " + dir_name + " in " + path);
  710. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  711. Error err = da->change_dir(path);
  712. if (err == OK) {
  713. err = da->make_dir(dir_name);
  714. }
  715. memdelete(da);
  716. if (err == OK) {
  717. print_line("call rescan!");
  718. _rescan();
  719. } else {
  720. EditorNode::get_singleton()->show_warning(TTR("Could not create folder."));
  721. }
  722. }
  723. void FileSystemDock::_rename_operation_confirm() {
  724. String new_name = rename_dialog_text->get_text().strip_edges();
  725. if (new_name.length() == 0) {
  726. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  727. return;
  728. } else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
  729. EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
  730. return;
  731. }
  732. String old_path = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1) : to_rename.path;
  733. String new_path = old_path.get_base_dir().plus_file(new_name);
  734. if (old_path == new_path) {
  735. return;
  736. }
  737. //Present a more user friendly warning for name conflict
  738. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  739. if (da->file_exists(new_path) || da->dir_exists(new_path)) {
  740. EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
  741. memdelete(da);
  742. return;
  743. }
  744. memdelete(da);
  745. Map<String, String> renames;
  746. _try_move_item(to_rename, new_path, renames);
  747. _update_dependencies_after_move(renames);
  748. //Rescan everything
  749. print_line("call rescan!");
  750. _rescan();
  751. }
  752. void FileSystemDock::_duplicate_operation_confirm() {
  753. String new_name = duplicate_dialog_text->get_text().strip_edges();
  754. if (new_name.length() == 0) {
  755. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  756. return;
  757. } else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
  758. EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
  759. return;
  760. }
  761. String old_path = to_duplicate.path.ends_with("/") ? to_duplicate.path.substr(0, to_duplicate.path.length() - 1) : to_rename.path;
  762. String new_path = old_path.get_base_dir().plus_file(new_name);
  763. if (old_path == new_path) {
  764. return;
  765. }
  766. //Present a more user friendly warning for name conflict
  767. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  768. if (da->file_exists(new_path) || da->dir_exists(new_path)) {
  769. EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
  770. memdelete(da);
  771. return;
  772. }
  773. memdelete(da);
  774. _try_duplicate_item(to_duplicate, new_name);
  775. //Rescan everything
  776. print_line("call rescan!");
  777. _rescan();
  778. }
  779. void FileSystemDock::_move_operation_confirm(const String &p_to_path) {
  780. Map<String, String> renames;
  781. for (int i = 0; i < to_move.size(); i++) {
  782. 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;
  783. String new_path = p_to_path.plus_file(old_path.get_file());
  784. _try_move_item(to_move[i], new_path, renames);
  785. }
  786. _update_dependencies_after_move(renames);
  787. print_line("call rescan!");
  788. _rescan();
  789. }
  790. void FileSystemDock::_file_option(int p_option) {
  791. switch (p_option) {
  792. case FILE_SHOW_IN_EXPLORER: {
  793. String dir = ProjectSettings::get_singleton()->globalize_path(this->path);
  794. OS::get_singleton()->shell_open(String("file://") + dir);
  795. } break;
  796. case FILE_OPEN: {
  797. for (int i = 0; i < files->get_item_count(); i++) {
  798. if (files->is_selected(i)) {
  799. _select_file(i);
  800. }
  801. }
  802. } break;
  803. case FILE_INSTANCE: {
  804. Vector<String> paths;
  805. for (int i = 0; i < files->get_item_count(); i++) {
  806. if (!files->is_selected(i))
  807. continue;
  808. String fpath = files->get_item_metadata(i);
  809. if (EditorFileSystem::get_singleton()->get_file_type(fpath) == "PackedScene") {
  810. paths.push_back(fpath);
  811. }
  812. }
  813. if (!paths.empty()) {
  814. emit_signal("instance", paths);
  815. }
  816. } break;
  817. case FILE_DEPENDENCIES: {
  818. int idx = files->get_current();
  819. if (idx < 0 || idx >= files->get_item_count())
  820. break;
  821. String fpath = files->get_item_metadata(idx);
  822. deps_editor->edit(fpath);
  823. } break;
  824. case FILE_OWNERS: {
  825. int idx = files->get_current();
  826. if (idx < 0 || idx >= files->get_item_count())
  827. break;
  828. String fpath = files->get_item_metadata(idx);
  829. owners_editor->show(fpath);
  830. } break;
  831. case FILE_MOVE: {
  832. to_move.clear();
  833. for (int i = 0; i < files->get_item_count(); i++) {
  834. if (!files->is_selected(i))
  835. continue;
  836. String fpath = files->get_item_metadata(i);
  837. to_move.push_back(FileOrFolder(fpath, !fpath.ends_with("/")));
  838. }
  839. if (to_move.size() > 0) {
  840. move_dialog->popup_centered_ratio();
  841. }
  842. } break;
  843. case FILE_RENAME: {
  844. int idx = files->get_current();
  845. if (idx < 0 || idx >= files->get_item_count())
  846. break;
  847. to_rename.path = files->get_item_metadata(idx);
  848. to_rename.is_file = !to_rename.path.ends_with("/");
  849. if (to_rename.is_file) {
  850. String name = to_rename.path.get_file();
  851. rename_dialog->set_title(TTR("Renaming file:") + " " + name);
  852. rename_dialog_text->set_text(name);
  853. rename_dialog_text->select(0, name.find_last("."));
  854. } else {
  855. String name = to_rename.path.substr(0, to_rename.path.length() - 1).get_file();
  856. rename_dialog->set_title(TTR("Renaming folder:") + " " + name);
  857. rename_dialog_text->set_text(name);
  858. rename_dialog_text->select(0, name.length());
  859. }
  860. rename_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  861. rename_dialog_text->grab_focus();
  862. } break;
  863. case FILE_REMOVE: {
  864. Vector<String> remove_files;
  865. Vector<String> remove_folders;
  866. for (int i = 0; i < files->get_item_count(); i++) {
  867. String fpath = files->get_item_metadata(i);
  868. if (files->is_selected(i) && fpath != "res://") {
  869. if (fpath.ends_with("/")) {
  870. remove_folders.push_back(fpath);
  871. } else {
  872. remove_files.push_back(fpath);
  873. }
  874. }
  875. }
  876. if (remove_files.size() + remove_folders.size() > 0) {
  877. remove_dialog->show(remove_folders, remove_files);
  878. //1) find if used
  879. //2) warn
  880. }
  881. } break;
  882. case FILE_DUPLICATE: {
  883. int idx = files->get_current();
  884. if (idx < 0 || idx >= files->get_item_count())
  885. break;
  886. to_duplicate.path = files->get_item_metadata(idx);
  887. to_duplicate.is_file = !to_duplicate.path.ends_with("/");
  888. if (to_duplicate.is_file) {
  889. String name = to_duplicate.path.get_file();
  890. duplicate_dialog->set_title(TTR("Duplicating file:") + " " + name);
  891. duplicate_dialog_text->set_text(name);
  892. duplicate_dialog_text->select(0, name.find_last("."));
  893. } else {
  894. String name = to_duplicate.path.substr(0, to_duplicate.path.length() - 1).get_file();
  895. duplicate_dialog->set_title(TTR("Duplicating folder:") + " " + name);
  896. duplicate_dialog_text->set_text(name);
  897. duplicate_dialog_text->select(0, name.length());
  898. }
  899. duplicate_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  900. duplicate_dialog_text->grab_focus();
  901. } break;
  902. case FILE_INFO: {
  903. } break;
  904. case FILE_REIMPORT: {
  905. Vector<String> reimport;
  906. for (int i = 0; i < files->get_item_count(); i++) {
  907. if (!files->is_selected(i))
  908. continue;
  909. String fpath = files->get_item_metadata(i);
  910. reimport.push_back(fpath);
  911. }
  912. ERR_FAIL_COND(reimport.size() == 0);
  913. /*
  914. Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(reimport[0]);
  915. ERR_FAIL_COND(!rimd.is_valid());
  916. String editor=rimd->get_editor();
  917. if (editor.begins_with("texture_")) { //compatibility fix for old texture format
  918. editor="texture";
  919. }
  920. Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor);
  921. ERR_FAIL_COND(!rimp.is_valid());
  922. if (reimport.size()==1) {
  923. rimp->import_dialog(reimport[0]);
  924. } else {
  925. rimp->reimport_multiple_files(reimport);
  926. }
  927. */
  928. } break;
  929. case FILE_NEW_FOLDER: {
  930. make_dir_dialog_text->set_text("new folder");
  931. make_dir_dialog_text->select_all();
  932. make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  933. make_dir_dialog_text->grab_focus();
  934. } break;
  935. case FILE_COPY_PATH: {
  936. int idx = files->get_current();
  937. if (idx < 0 || idx >= files->get_item_count())
  938. break;
  939. String fpath = files->get_item_metadata(idx);
  940. OS::get_singleton()->set_clipboard(fpath);
  941. } break;
  942. }
  943. }
  944. void FileSystemDock::_folder_option(int p_option) {
  945. TreeItem *selected = tree->get_selected();
  946. switch (p_option) {
  947. case FOLDER_EXPAND_ALL:
  948. case FOLDER_COLLAPSE_ALL: {
  949. bool is_collapsed = (p_option == FOLDER_COLLAPSE_ALL);
  950. Vector<TreeItem *> needs_check;
  951. needs_check.push_back(selected);
  952. while (needs_check.size()) {
  953. needs_check[0]->set_collapsed(is_collapsed);
  954. TreeItem *child = needs_check[0]->get_children();
  955. while (child) {
  956. needs_check.push_back(child);
  957. child = child->get_next();
  958. }
  959. needs_check.remove(0);
  960. }
  961. } break;
  962. case FOLDER_MOVE: {
  963. to_move.clear();
  964. String fpath = selected->get_metadata(tree->get_selected_column());
  965. if (fpath != "res://") {
  966. fpath = fpath.ends_with("/") ? fpath.substr(0, fpath.length() - 1) : fpath;
  967. to_move.push_back(FileOrFolder(fpath, false));
  968. move_dialog->popup_centered_ratio();
  969. }
  970. } break;
  971. case FOLDER_RENAME: {
  972. to_rename.path = selected->get_metadata(tree->get_selected_column());
  973. to_rename.is_file = false;
  974. if (to_rename.path != "res://") {
  975. String name = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1).get_file() : to_rename.path.get_file();
  976. rename_dialog->set_title(TTR("Renaming folder:") + " " + name);
  977. rename_dialog_text->set_text(name);
  978. rename_dialog_text->select(0, name.length());
  979. rename_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  980. rename_dialog_text->grab_focus();
  981. }
  982. } break;
  983. case FOLDER_REMOVE: {
  984. Vector<String> remove_folders;
  985. Vector<String> remove_files;
  986. String fpath = selected->get_metadata(tree->get_selected_column());
  987. if (fpath != "res://") {
  988. remove_folders.push_back(fpath);
  989. remove_dialog->show(remove_folders, remove_files);
  990. }
  991. } break;
  992. case FOLDER_NEW_FOLDER: {
  993. make_dir_dialog_text->set_text("new folder");
  994. make_dir_dialog_text->select_all();
  995. make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
  996. make_dir_dialog_text->grab_focus();
  997. } break;
  998. case FOLDER_COPY_PATH: {
  999. String fpath = selected->get_metadata(tree->get_selected_column());
  1000. OS::get_singleton()->set_clipboard(fpath);
  1001. } break;
  1002. case FOLDER_SHOW_IN_EXPLORER: {
  1003. String fpath = selected->get_metadata(tree->get_selected_column());
  1004. String dir = ProjectSettings::get_singleton()->globalize_path(fpath);
  1005. OS::get_singleton()->shell_open(String("file://") + dir);
  1006. } break;
  1007. }
  1008. }
  1009. void FileSystemDock::_go_to_file_list() {
  1010. if (low_height_mode) {
  1011. tree->hide();
  1012. file_list_vb->show();
  1013. button_favorite->hide();
  1014. } else {
  1015. bool collapsed = tree->get_selected()->is_collapsed();
  1016. tree->get_selected()->set_collapsed(!collapsed);
  1017. }
  1018. //file_options->show();
  1019. _update_files(false);
  1020. //emit_signal("open",path);
  1021. }
  1022. void FileSystemDock::_dir_rmb_pressed(const Vector2 &p_pos) {
  1023. folder_options->clear();
  1024. folder_options->set_size(Size2(1, 1));
  1025. folder_options->add_item(TTR("Expand all"), FOLDER_EXPAND_ALL);
  1026. folder_options->add_item(TTR("Collapse all"), FOLDER_COLLAPSE_ALL);
  1027. TreeItem *item = tree->get_selected();
  1028. if (item) {
  1029. String fpath = item->get_metadata(tree->get_selected_column());
  1030. folder_options->add_separator();
  1031. folder_options->add_item(TTR("Copy Path"), FOLDER_COPY_PATH);
  1032. if (fpath != "res://") {
  1033. folder_options->add_item(TTR("Rename.."), FOLDER_RENAME);
  1034. folder_options->add_item(TTR("Move To.."), FOLDER_MOVE);
  1035. folder_options->add_item(TTR("Delete"), FOLDER_REMOVE);
  1036. }
  1037. folder_options->add_separator();
  1038. folder_options->add_item(TTR("New Folder.."), FOLDER_NEW_FOLDER);
  1039. folder_options->add_item(TTR("Show In File Manager"), FOLDER_SHOW_IN_EXPLORER);
  1040. }
  1041. folder_options->set_position(tree->get_global_position() + p_pos);
  1042. folder_options->popup();
  1043. }
  1044. void FileSystemDock::_search_changed(const String &p_text) {
  1045. if (file_list_vb->is_visible())
  1046. _update_files(false);
  1047. }
  1048. void FileSystemDock::_rescan() {
  1049. _set_scanning_mode();
  1050. EditorFileSystem::get_singleton()->scan();
  1051. }
  1052. void FileSystemDock::fix_dependencies(const String &p_for_file) {
  1053. deps_editor->edit(p_for_file);
  1054. }
  1055. void FileSystemDock::focus_on_filter() {
  1056. if (low_height_mode && tree->is_visible()) {
  1057. // Tree mode, switch to files list with search box
  1058. tree->hide();
  1059. file_list_vb->show();
  1060. button_favorite->hide();
  1061. }
  1062. search_box->grab_focus();
  1063. }
  1064. void FileSystemDock::set_display_mode(int p_mode) {
  1065. if (p_mode == display_mode)
  1066. return;
  1067. button_display_mode->set_pressed(p_mode == DISPLAY_LIST);
  1068. _change_file_display();
  1069. }
  1070. Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  1071. bool is_favorite = false;
  1072. Vector<String> paths;
  1073. if (p_from == tree) {
  1074. TreeItem *selected = tree->get_selected();
  1075. if (!selected)
  1076. return Variant();
  1077. String folder = selected->get_metadata(0);
  1078. if (folder == String())
  1079. return Variant();
  1080. paths.push_back(folder.ends_with("/") ? folder : (folder + "/"));
  1081. is_favorite = selected->get_parent() != NULL && tree->get_root()->get_children() == selected->get_parent();
  1082. } else if (p_from == files) {
  1083. for (int i = 0; i < files->get_item_count(); i++) {
  1084. if (files->is_selected(i)) {
  1085. paths.push_back(files->get_item_metadata(i));
  1086. }
  1087. }
  1088. }
  1089. if (paths.empty())
  1090. return Variant();
  1091. Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from);
  1092. if (is_favorite) {
  1093. drag_data["type"] = "favorite";
  1094. }
  1095. return drag_data;
  1096. }
  1097. bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  1098. Dictionary drag_data = p_data;
  1099. if (drag_data.has("type") && String(drag_data["type"]) == "favorite") {
  1100. //moving favorite around
  1101. TreeItem *ti = tree->get_item_at_position(p_point);
  1102. if (!ti)
  1103. return false;
  1104. int what = tree->get_drop_section_at_position(p_point);
  1105. if (ti == tree->get_root()->get_children()) {
  1106. return (what == 1); //the parent, first fav
  1107. }
  1108. if (ti->get_parent() && tree->get_root()->get_children() == ti->get_parent()) {
  1109. return true; // a favorite
  1110. }
  1111. if (ti == tree->get_root()->get_children()->get_next()) {
  1112. return (what == -1); //the tree, last fav
  1113. }
  1114. return false;
  1115. }
  1116. if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
  1117. String to_dir = _get_drag_target_folder(p_point, p_from);
  1118. return !to_dir.empty();
  1119. }
  1120. if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
  1121. String to_dir = _get_drag_target_folder(p_point, p_from);
  1122. if (to_dir.empty())
  1123. return false;
  1124. //Attempting to move a folder into itself will fail later
  1125. //Rather than bring up a message don't try to do it in the first place
  1126. to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/");
  1127. Vector<String> fnames = drag_data["files"];
  1128. for (int i = 0; i < fnames.size(); ++i) {
  1129. if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i]))
  1130. return false;
  1131. }
  1132. return true;
  1133. }
  1134. return false;
  1135. }
  1136. void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  1137. if (!can_drop_data_fw(p_point, p_data, p_from))
  1138. return;
  1139. Dictionary drag_data = p_data;
  1140. if (drag_data.has("type") && String(drag_data["type"]) == "favorite") {
  1141. //moving favorite around
  1142. TreeItem *ti = tree->get_item_at_position(p_point);
  1143. if (!ti)
  1144. return;
  1145. Vector<String> files = drag_data["files"];
  1146. ERR_FAIL_COND(files.size() != 1);
  1147. String swap = files[0];
  1148. if (swap != "res://" && swap.ends_with("/")) {
  1149. swap = swap.substr(0, swap.length() - 1);
  1150. }
  1151. int what = tree->get_drop_section_at_position(p_point);
  1152. TreeItem *swap_item = NULL;
  1153. if (ti == tree->get_root()->get_children()) {
  1154. swap_item = tree->get_root()->get_children()->get_children();
  1155. } else if (ti->get_parent() && tree->get_root()->get_children() == ti->get_parent()) {
  1156. if (what == -1) {
  1157. swap_item = ti;
  1158. } else {
  1159. swap_item = ti->get_next();
  1160. }
  1161. }
  1162. String swap_with;
  1163. if (swap_item) {
  1164. swap_with = swap_item->get_metadata(0);
  1165. if (swap_with != "res://" && swap_with.ends_with("/")) {
  1166. swap_with = swap_with.substr(0, swap_with.length() - 1);
  1167. }
  1168. }
  1169. if (swap == swap_with)
  1170. return;
  1171. Vector<String> dirs = EditorSettings::get_singleton()->get_favorite_dirs();
  1172. ERR_FAIL_COND(dirs.find(swap) == -1);
  1173. ERR_FAIL_COND(swap_with != String() && dirs.find(swap_with) == -1);
  1174. dirs.erase(swap);
  1175. if (swap_with == String()) {
  1176. dirs.push_back(swap);
  1177. } else {
  1178. int idx = dirs.find(swap_with);
  1179. dirs.insert(idx, swap);
  1180. }
  1181. EditorSettings::get_singleton()->set_favorite_dirs(dirs);
  1182. _update_tree(true);
  1183. return;
  1184. }
  1185. if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
  1186. Ref<Resource> res = drag_data["resource"];
  1187. String to_dir = _get_drag_target_folder(p_point, p_from);
  1188. if (res.is_valid() && !to_dir.empty()) {
  1189. EditorNode::get_singleton()->push_item(res.ptr());
  1190. EditorNode::get_singleton()->save_resource_as(res, to_dir);
  1191. }
  1192. }
  1193. if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
  1194. String to_dir = _get_drag_target_folder(p_point, p_from);
  1195. if (!to_dir.empty()) {
  1196. Vector<String> fnames = drag_data["files"];
  1197. to_move.clear();
  1198. for (int i = 0; i < fnames.size(); i++) {
  1199. to_move.push_back(FileOrFolder(fnames[i], !fnames[i].ends_with("/")));
  1200. }
  1201. _move_operation_confirm(to_dir);
  1202. }
  1203. }
  1204. }
  1205. String FileSystemDock::_get_drag_target_folder(const Point2 &p_point, Control *p_from) const {
  1206. if (p_from == files) {
  1207. int pos = files->get_item_at_position(p_point, true);
  1208. if (pos == -1)
  1209. return path;
  1210. String target = files->get_item_metadata(pos);
  1211. return target.ends_with("/") ? target : path;
  1212. }
  1213. if (p_from == tree) {
  1214. TreeItem *ti = tree->get_item_at_position(p_point);
  1215. if (ti && ti != tree->get_root()->get_children())
  1216. return ti->get_metadata(0);
  1217. }
  1218. return String();
  1219. }
  1220. void FileSystemDock::_files_list_rmb_select(int p_item, const Vector2 &p_pos) {
  1221. //Right clicking ".." should clear current selection
  1222. if (files->get_item_text(p_item) == "..") {
  1223. for (int i = 0; i < files->get_item_count(); i++) {
  1224. files->unselect(i);
  1225. }
  1226. }
  1227. Vector<String> filenames;
  1228. Vector<String> foldernames;
  1229. bool all_files = true;
  1230. bool all_files_scenes = true;
  1231. bool all_folders = true;
  1232. for (int i = 0; i < files->get_item_count(); i++) {
  1233. if (!files->is_selected(i)) {
  1234. continue;
  1235. }
  1236. String fpath = files->get_item_metadata(i);
  1237. if (fpath.ends_with("/")) {
  1238. foldernames.push_back(fpath);
  1239. all_files = false;
  1240. } else {
  1241. filenames.push_back(fpath);
  1242. all_folders = false;
  1243. all_files_scenes &= (EditorFileSystem::get_singleton()->get_file_type(fpath) == "PackedScene");
  1244. }
  1245. }
  1246. file_options->clear();
  1247. file_options->set_size(Size2(1, 1));
  1248. if (all_files) {
  1249. if (all_files_scenes && filenames.size() >= 1) {
  1250. file_options->add_item(TTR("Open Scene(s)"), FILE_OPEN);
  1251. file_options->add_item(TTR("Instance"), FILE_INSTANCE);
  1252. file_options->add_separator();
  1253. }
  1254. if (!all_files_scenes && filenames.size() == 1) {
  1255. file_options->add_item(TTR("Open"), FILE_OPEN);
  1256. file_options->add_separator();
  1257. }
  1258. if (filenames.size() == 1) {
  1259. file_options->add_item(TTR("Edit Dependencies.."), FILE_DEPENDENCIES);
  1260. file_options->add_item(TTR("View Owners.."), FILE_OWNERS);
  1261. file_options->add_separator();
  1262. }
  1263. } else if (all_folders && foldernames.size() > 0) {
  1264. file_options->add_item(TTR("Open"), FILE_OPEN);
  1265. file_options->add_separator();
  1266. }
  1267. int num_items = filenames.size() + foldernames.size();
  1268. if (num_items >= 1) {
  1269. if (num_items == 1) {
  1270. file_options->add_item(TTR("Copy Path"), FILE_COPY_PATH);
  1271. file_options->add_item(TTR("Rename.."), FILE_RENAME);
  1272. file_options->add_item(TTR("Duplicate.."), FILE_DUPLICATE);
  1273. }
  1274. file_options->add_item(TTR("Move To.."), FILE_MOVE);
  1275. file_options->add_item(TTR("Delete"), FILE_REMOVE);
  1276. file_options->add_separator();
  1277. }
  1278. file_options->add_item(TTR("New Folder.."), FILE_NEW_FOLDER);
  1279. file_options->add_item(TTR("Show In File Manager"), FILE_SHOW_IN_EXPLORER);
  1280. file_options->set_position(files->get_global_position() + p_pos);
  1281. file_options->popup();
  1282. }
  1283. void FileSystemDock::_rmb_pressed(const Vector2 &p_pos) {
  1284. file_options->clear();
  1285. file_options->set_size(Size2(1, 1));
  1286. file_options->add_item(TTR("New Folder.."), FILE_NEW_FOLDER);
  1287. file_options->add_item(TTR("Show In File Manager"), FILE_SHOW_IN_EXPLORER);
  1288. file_options->set_position(files->get_global_position() + p_pos);
  1289. file_options->popup();
  1290. }
  1291. void FileSystemDock::select_file(const String &p_file) {
  1292. navigate_to_path(p_file);
  1293. }
  1294. void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) {
  1295. import_dock_needs_update = true;
  1296. call_deferred("_update_import_dock");
  1297. }
  1298. void FileSystemDock::_file_selected() {
  1299. import_dock_needs_update = true;
  1300. _update_import_dock();
  1301. }
  1302. void FileSystemDock::_update_import_dock() {
  1303. if (!import_dock_needs_update)
  1304. return;
  1305. //check import
  1306. Vector<String> imports;
  1307. String import_type;
  1308. for (int i = 0; i < files->get_item_count(); i++) {
  1309. if (!files->is_selected(i))
  1310. continue;
  1311. String fpath = files->get_item_metadata(i);
  1312. if (!FileAccess::exists(fpath + ".import")) {
  1313. imports.clear();
  1314. break;
  1315. }
  1316. Ref<ConfigFile> cf;
  1317. cf.instance();
  1318. Error err = cf->load(fpath + ".import");
  1319. if (err != OK) {
  1320. imports.clear();
  1321. break;
  1322. }
  1323. String type = cf->get_value("remap", "type");
  1324. if (import_type == "") {
  1325. import_type = type;
  1326. } else if (import_type != type) {
  1327. //all should be the same type
  1328. imports.clear();
  1329. break;
  1330. }
  1331. imports.push_back(fpath);
  1332. }
  1333. if (imports.size() == 0) {
  1334. EditorNode::get_singleton()->get_import_dock()->clear();
  1335. } else if (imports.size() == 1) {
  1336. EditorNode::get_singleton()->get_import_dock()->set_edit_path(imports[0]);
  1337. } else {
  1338. EditorNode::get_singleton()->get_import_dock()->set_edit_multiple_paths(imports);
  1339. }
  1340. import_dock_needs_update = false;
  1341. }
  1342. void FileSystemDock::_bind_methods() {
  1343. ClassDB::bind_method(D_METHOD("_update_tree"), &FileSystemDock::_update_tree);
  1344. ClassDB::bind_method(D_METHOD("_rescan"), &FileSystemDock::_rescan);
  1345. ClassDB::bind_method(D_METHOD("_favorites_pressed"), &FileSystemDock::_favorites_pressed);
  1346. //ClassDB::bind_method(D_METHOD("_instance_pressed"),&ScenesDock::_instance_pressed);
  1347. ClassDB::bind_method(D_METHOD("_go_to_file_list"), &FileSystemDock::_go_to_file_list);
  1348. ClassDB::bind_method(D_METHOD("_dir_rmb_pressed"), &FileSystemDock::_dir_rmb_pressed);
  1349. ClassDB::bind_method(D_METHOD("_thumbnail_done"), &FileSystemDock::_thumbnail_done);
  1350. ClassDB::bind_method(D_METHOD("_select_file"), &FileSystemDock::_select_file);
  1351. ClassDB::bind_method(D_METHOD("_go_to_tree"), &FileSystemDock::_go_to_tree);
  1352. ClassDB::bind_method(D_METHOD("navigate_to_path"), &FileSystemDock::navigate_to_path);
  1353. ClassDB::bind_method(D_METHOD("_change_file_display"), &FileSystemDock::_change_file_display);
  1354. ClassDB::bind_method(D_METHOD("_fw_history"), &FileSystemDock::_fw_history);
  1355. ClassDB::bind_method(D_METHOD("_bw_history"), &FileSystemDock::_bw_history);
  1356. ClassDB::bind_method(D_METHOD("_fs_changed"), &FileSystemDock::_fs_changed);
  1357. ClassDB::bind_method(D_METHOD("_dir_selected"), &FileSystemDock::_dir_selected);
  1358. ClassDB::bind_method(D_METHOD("_file_option"), &FileSystemDock::_file_option);
  1359. ClassDB::bind_method(D_METHOD("_folder_option"), &FileSystemDock::_folder_option);
  1360. ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileSystemDock::_make_dir_confirm);
  1361. ClassDB::bind_method(D_METHOD("_move_operation_confirm"), &FileSystemDock::_move_operation_confirm);
  1362. ClassDB::bind_method(D_METHOD("_rename_operation_confirm"), &FileSystemDock::_rename_operation_confirm);
  1363. ClassDB::bind_method(D_METHOD("_duplicate_operation_confirm"), &FileSystemDock::_duplicate_operation_confirm);
  1364. ClassDB::bind_method(D_METHOD("_search_changed"), &FileSystemDock::_search_changed);
  1365. ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &FileSystemDock::get_drag_data_fw);
  1366. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &FileSystemDock::can_drop_data_fw);
  1367. ClassDB::bind_method(D_METHOD("drop_data_fw"), &FileSystemDock::drop_data_fw);
  1368. ClassDB::bind_method(D_METHOD("_files_list_rmb_select"), &FileSystemDock::_files_list_rmb_select);
  1369. ClassDB::bind_method(D_METHOD("_preview_invalidated"), &FileSystemDock::_preview_invalidated);
  1370. ClassDB::bind_method(D_METHOD("_file_selected"), &FileSystemDock::_file_selected);
  1371. ClassDB::bind_method(D_METHOD("_file_multi_selected"), &FileSystemDock::_file_multi_selected);
  1372. ClassDB::bind_method(D_METHOD("_update_import_dock"), &FileSystemDock::_update_import_dock);
  1373. ClassDB::bind_method(D_METHOD("_rmb_pressed"), &FileSystemDock::_rmb_pressed);
  1374. ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::POOL_STRING_ARRAY, "files")));
  1375. ADD_SIGNAL(MethodInfo("open"));
  1376. }
  1377. FileSystemDock::FileSystemDock(EditorNode *p_editor) {
  1378. set_name("FileSystem");
  1379. editor = p_editor;
  1380. path = "res://";
  1381. HBoxContainer *toolbar_hbc = memnew(HBoxContainer);
  1382. add_child(toolbar_hbc);
  1383. button_hist_prev = memnew(ToolButton);
  1384. button_hist_prev->set_disabled(true);
  1385. button_hist_prev->set_focus_mode(FOCUS_NONE);
  1386. button_hist_prev->set_tooltip(TTR("Previous Directory"));
  1387. toolbar_hbc->add_child(button_hist_prev);
  1388. button_hist_next = memnew(ToolButton);
  1389. button_hist_next->set_disabled(true);
  1390. button_hist_next->set_focus_mode(FOCUS_NONE);
  1391. button_hist_next->set_tooltip(TTR("Next Directory"));
  1392. toolbar_hbc->add_child(button_hist_next);
  1393. current_path = memnew(LineEdit);
  1394. current_path->set_h_size_flags(SIZE_EXPAND_FILL);
  1395. toolbar_hbc->add_child(current_path);
  1396. button_reload = memnew(Button);
  1397. button_reload->set_flat(true);
  1398. button_reload->connect("pressed", this, "_rescan");
  1399. button_reload->set_focus_mode(FOCUS_NONE);
  1400. button_reload->set_tooltip(TTR("Re-Scan Filesystem"));
  1401. button_reload->hide();
  1402. toolbar_hbc->add_child(button_reload);
  1403. //toolbar_hbc->add_spacer();
  1404. button_favorite = memnew(Button);
  1405. button_favorite->set_flat(true);
  1406. button_favorite->set_toggle_mode(true);
  1407. button_favorite->connect("pressed", this, "_favorites_pressed");
  1408. button_favorite->set_tooltip(TTR("Toggle folder status as Favorite"));
  1409. button_favorite->set_focus_mode(FOCUS_NONE);
  1410. toolbar_hbc->add_child(button_favorite);
  1411. //Control *spacer = memnew( Control);
  1412. /*
  1413. button_open = memnew( Button );
  1414. button_open->set_flat(true);
  1415. button_open->connect("pressed",this,"_go_to_file_list");
  1416. toolbar_hbc->add_child(button_open);
  1417. button_open->hide();
  1418. button_open->set_focus_mode(FOCUS_NONE);
  1419. button_open->set_tooltip("Open the selected file.\nOpen as scene if a scene, or as resource otherwise.");
  1420. button_instance = memnew( Button );
  1421. button_instance->set_flat(true);
  1422. button_instance->connect("pressed",this,"_instance_pressed");
  1423. toolbar_hbc->add_child(button_instance);
  1424. button_instance->hide();
  1425. button_instance->set_focus_mode(FOCUS_NONE);
  1426. button_instance->set_tooltip(TTR("Instance the selected scene(s) as child of the selected node."));
  1427. */
  1428. file_options = memnew(PopupMenu);
  1429. add_child(file_options);
  1430. folder_options = memnew(PopupMenu);
  1431. add_child(folder_options);
  1432. split_box = memnew(VSplitContainer);
  1433. split_box->set_v_size_flags(SIZE_EXPAND_FILL);
  1434. add_child(split_box);
  1435. tree = memnew(Tree);
  1436. tree->set_hide_root(true);
  1437. tree->set_drag_forwarding(this);
  1438. tree->set_allow_rmb_select(true);
  1439. tree->set_custom_minimum_size(Size2(0, 200 * EDSCALE));
  1440. split_box->add_child(tree);
  1441. tree->connect("item_edited", this, "_favorite_toggled");
  1442. tree->connect("item_activated", this, "_go_to_file_list");
  1443. tree->connect("cell_selected", this, "_dir_selected");
  1444. tree->connect("item_rmb_selected", this, "_dir_rmb_pressed");
  1445. file_list_vb = memnew(VBoxContainer);
  1446. file_list_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  1447. split_box->add_child(file_list_vb);
  1448. path_hb = memnew(HBoxContainer);
  1449. file_list_vb->add_child(path_hb);
  1450. button_tree = memnew(ToolButton);
  1451. button_tree->hide();
  1452. path_hb->add_child(button_tree);
  1453. search_box = memnew(LineEdit);
  1454. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  1455. search_box->connect("text_changed", this, "_search_changed");
  1456. path_hb->add_child(search_box);
  1457. button_display_mode = memnew(ToolButton);
  1458. button_display_mode->set_toggle_mode(true);
  1459. path_hb->add_child(button_display_mode);
  1460. files = memnew(ItemList);
  1461. files->set_v_size_flags(SIZE_EXPAND_FILL);
  1462. files->set_select_mode(ItemList::SELECT_MULTI);
  1463. files->set_drag_forwarding(this);
  1464. files->connect("item_rmb_selected", this, "_files_list_rmb_select");
  1465. files->connect("item_selected", this, "_file_selected");
  1466. files->connect("multi_selected", this, "_file_multi_selected");
  1467. files->connect("rmb_clicked", this, "_rmb_pressed");
  1468. files->set_allow_rmb_select(true);
  1469. file_list_vb->add_child(files);
  1470. scanning_vb = memnew(VBoxContainer);
  1471. scanning_vb->hide();
  1472. add_child(scanning_vb);
  1473. Label *slabel = memnew(Label);
  1474. slabel->set_text(TTR("Scanning Files,\nPlease Wait.."));
  1475. slabel->set_align(Label::ALIGN_CENTER);
  1476. scanning_vb->add_child(slabel);
  1477. scanning_progress = memnew(ProgressBar);
  1478. scanning_vb->add_child(scanning_progress);
  1479. deps_editor = memnew(DependencyEditor);
  1480. add_child(deps_editor);
  1481. owners_editor = memnew(DependencyEditorOwners(editor));
  1482. add_child(owners_editor);
  1483. remove_dialog = memnew(DependencyRemoveDialog);
  1484. add_child(remove_dialog);
  1485. move_dialog = memnew(EditorDirDialog);
  1486. move_dialog->get_ok()->set_text(TTR("Move"));
  1487. add_child(move_dialog);
  1488. move_dialog->connect("dir_selected", this, "_move_operation_confirm");
  1489. rename_dialog = memnew(ConfirmationDialog);
  1490. VBoxContainer *rename_dialog_vb = memnew(VBoxContainer);
  1491. rename_dialog->add_child(rename_dialog_vb);
  1492. rename_dialog_text = memnew(LineEdit);
  1493. rename_dialog_vb->add_margin_child(TTR("Name:"), rename_dialog_text);
  1494. rename_dialog->get_ok()->set_text(TTR("Rename"));
  1495. add_child(rename_dialog);
  1496. rename_dialog->register_text_enter(rename_dialog_text);
  1497. rename_dialog->connect("confirmed", this, "_rename_operation_confirm");
  1498. duplicate_dialog = memnew(ConfirmationDialog);
  1499. VBoxContainer *duplicate_dialog_vb = memnew(VBoxContainer);
  1500. duplicate_dialog->add_child(duplicate_dialog_vb);
  1501. duplicate_dialog_text = memnew(LineEdit);
  1502. duplicate_dialog_vb->add_margin_child(TTR("Name:"), duplicate_dialog_text);
  1503. duplicate_dialog->get_ok()->set_text(TTR("Duplicate"));
  1504. add_child(duplicate_dialog);
  1505. duplicate_dialog->register_text_enter(duplicate_dialog_text);
  1506. duplicate_dialog->connect("confirmed", this, "_duplicate_operation_confirm");
  1507. make_dir_dialog = memnew(ConfirmationDialog);
  1508. make_dir_dialog->set_title(TTR("Create Folder"));
  1509. VBoxContainer *make_folder_dialog_vb = memnew(VBoxContainer);
  1510. make_dir_dialog->add_child(make_folder_dialog_vb);
  1511. make_dir_dialog_text = memnew(LineEdit);
  1512. make_folder_dialog_vb->add_margin_child(TTR("Name:"), make_dir_dialog_text);
  1513. add_child(make_dir_dialog);
  1514. make_dir_dialog->register_text_enter(make_dir_dialog_text);
  1515. make_dir_dialog->connect("confirmed", this, "_make_dir_confirm");
  1516. updating_tree = false;
  1517. initialized = false;
  1518. import_dock_needs_update = false;
  1519. history_pos = 0;
  1520. history_max_size = 20;
  1521. history.push_back("res://");
  1522. low_height_mode = false;
  1523. display_mode = DISPLAY_THUMBNAILS;
  1524. }
  1525. FileSystemDock::~FileSystemDock() {
  1526. }