project_list.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. /**************************************************************************/
  2. /* project_list.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "project_list.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/dir_access.h"
  33. #include "core/os/time.h"
  34. #include "core/version.h"
  35. #include "editor/editor_paths.h"
  36. #include "editor/editor_settings.h"
  37. #include "editor/editor_string_names.h"
  38. #include "editor/project_manager.h"
  39. #include "editor/project_manager/project_tag.h"
  40. #include "editor/themes/editor_scale.h"
  41. #include "scene/gui/button.h"
  42. #include "scene/gui/dialogs.h"
  43. #include "scene/gui/label.h"
  44. #include "scene/gui/line_edit.h"
  45. #include "scene/gui/progress_bar.h"
  46. #include "scene/gui/texture_button.h"
  47. #include "scene/gui/texture_rect.h"
  48. #include "scene/resources/image_texture.h"
  49. void ProjectListItemControl::_notification(int p_what) {
  50. switch (p_what) {
  51. case NOTIFICATION_THEME_CHANGED: {
  52. if (icon_needs_reload) {
  53. // The project icon may not be loaded by the time the control is displayed,
  54. // so use a loading placeholder.
  55. project_icon->set_texture(get_editor_theme_icon(SNAME("ProjectIconLoading")));
  56. }
  57. project_title->begin_bulk_theme_override();
  58. project_title->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("title"), EditorStringName(EditorFonts)));
  59. project_title->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("title_size"), EditorStringName(EditorFonts)));
  60. project_title->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("Tree")));
  61. project_title->end_bulk_theme_override();
  62. project_path->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("Tree")));
  63. project_unsupported_features->set_texture(get_editor_theme_icon(SNAME("NodeWarning")));
  64. favorite_button->set_texture_normal(get_editor_theme_icon(SNAME("Favorites")));
  65. if (project_is_missing) {
  66. explore_button->set_button_icon(get_editor_theme_icon(SNAME("FileBroken")));
  67. } else {
  68. explore_button->set_button_icon(get_editor_theme_icon(SNAME("Load")));
  69. }
  70. } break;
  71. case NOTIFICATION_MOUSE_ENTER: {
  72. is_hovering = true;
  73. queue_redraw();
  74. } break;
  75. case NOTIFICATION_MOUSE_EXIT: {
  76. is_hovering = false;
  77. queue_redraw();
  78. } break;
  79. case NOTIFICATION_DRAW: {
  80. if (is_selected) {
  81. draw_style_box(get_theme_stylebox(SNAME("selected"), SNAME("Tree")), Rect2(Point2(), get_size()));
  82. }
  83. if (is_hovering) {
  84. draw_style_box(get_theme_stylebox(SNAME("hovered"), SNAME("Tree")), Rect2(Point2(), get_size()));
  85. }
  86. draw_line(Point2(0, get_size().y + 1), Point2(get_size().x, get_size().y + 1), get_theme_color(SNAME("guide_color"), SNAME("Tree")));
  87. } break;
  88. }
  89. }
  90. void ProjectListItemControl::_favorite_button_pressed() {
  91. emit_signal(SNAME("favorite_pressed"));
  92. }
  93. void ProjectListItemControl::_explore_button_pressed() {
  94. emit_signal(SNAME("explore_pressed"));
  95. }
  96. void ProjectListItemControl::set_project_title(const String &p_title) {
  97. project_title->set_text(p_title);
  98. }
  99. void ProjectListItemControl::set_project_path(const String &p_path) {
  100. project_path->set_text(p_path);
  101. }
  102. void ProjectListItemControl::set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list) {
  103. for (const String &tag : p_tags) {
  104. ProjectTag *tag_control = memnew(ProjectTag(tag));
  105. tag_container->add_child(tag_control);
  106. tag_control->connect_button_to(callable_mp(p_parent_list, &ProjectList::add_search_tag).bind(tag));
  107. }
  108. }
  109. void ProjectListItemControl::set_project_icon(const Ref<Texture2D> &p_icon) {
  110. icon_needs_reload = false;
  111. // The default project icon is 128×128 to look crisp on hiDPI displays,
  112. // but we want the actual displayed size to be 64×64 on loDPI displays.
  113. project_icon->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
  114. project_icon->set_custom_minimum_size(Size2(64, 64) * EDSCALE);
  115. project_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
  116. project_icon->set_texture(p_icon);
  117. }
  118. void ProjectListItemControl::set_last_edited_info(const String &p_info) {
  119. last_edited_info->set_text(p_info);
  120. }
  121. void ProjectListItemControl::set_project_version(const String &p_info) {
  122. project_version->set_text(p_info);
  123. }
  124. void ProjectListItemControl::set_unsupported_features(PackedStringArray p_features) {
  125. if (p_features.size() > 0) {
  126. String tooltip_text = "";
  127. for (int i = 0; i < p_features.size(); i++) {
  128. if (ProjectList::project_feature_looks_like_version(p_features[i])) {
  129. PackedStringArray project_version_split = p_features[i].split(".");
  130. int project_version_major = 0, project_version_minor = 0;
  131. if (project_version_split.size() >= 2) {
  132. project_version_major = project_version_split[0].to_int();
  133. project_version_minor = project_version_split[1].to_int();
  134. }
  135. if (VERSION_MAJOR != project_version_major || VERSION_MINOR <= project_version_minor) {
  136. // Don't show a warning if the project was last edited in a previous minor version.
  137. tooltip_text += TTR("This project was last edited in a different Godot version: ") + p_features[i] + "\n";
  138. }
  139. p_features.remove_at(i);
  140. i--;
  141. }
  142. }
  143. if (p_features.size() > 0) {
  144. String unsupported_features_str = String(", ").join(p_features);
  145. tooltip_text += TTR("This project uses features unsupported by the current build:") + "\n" + unsupported_features_str;
  146. }
  147. if (tooltip_text.is_empty()) {
  148. return;
  149. }
  150. project_version->set_tooltip_text(tooltip_text);
  151. project_unsupported_features->set_tooltip_text(tooltip_text);
  152. project_unsupported_features->show();
  153. } else {
  154. project_unsupported_features->hide();
  155. }
  156. }
  157. bool ProjectListItemControl::should_load_project_icon() const {
  158. return icon_needs_reload;
  159. }
  160. void ProjectListItemControl::set_selected(bool p_selected) {
  161. is_selected = p_selected;
  162. queue_redraw();
  163. }
  164. void ProjectListItemControl::set_is_favorite(bool p_favorite) {
  165. favorite_button->set_modulate(p_favorite ? Color(1, 1, 1, 1) : Color(1, 1, 1, 0.2));
  166. }
  167. void ProjectListItemControl::set_is_missing(bool p_missing) {
  168. if (project_is_missing == p_missing) {
  169. return;
  170. }
  171. project_is_missing = p_missing;
  172. if (project_is_missing) {
  173. project_icon->set_modulate(Color(1, 1, 1, 0.5));
  174. explore_button->set_button_icon(get_editor_theme_icon(SNAME("FileBroken")));
  175. explore_button->set_tooltip_text(TTR("Error: Project is missing on the filesystem."));
  176. } else {
  177. project_icon->set_modulate(Color(1, 1, 1, 1.0));
  178. explore_button->set_button_icon(get_editor_theme_icon(SNAME("Load")));
  179. #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
  180. explore_button->set_tooltip_text(TTR("Show in File Manager"));
  181. #else
  182. // Opening the system file manager is not supported on the Android and web editors.
  183. explore_button->hide();
  184. #endif
  185. }
  186. }
  187. void ProjectListItemControl::set_is_grayed(bool p_grayed) {
  188. if (p_grayed) {
  189. main_vbox->set_modulate(Color(1, 1, 1, 0.5));
  190. // Don't make the icon less prominent if the parent is already grayed out.
  191. explore_button->set_modulate(Color(1, 1, 1, 1.0));
  192. } else {
  193. main_vbox->set_modulate(Color(1, 1, 1, 1.0));
  194. explore_button->set_modulate(Color(1, 1, 1, 0.5));
  195. }
  196. }
  197. void ProjectListItemControl::_bind_methods() {
  198. ADD_SIGNAL(MethodInfo("favorite_pressed"));
  199. ADD_SIGNAL(MethodInfo("explore_pressed"));
  200. }
  201. ProjectListItemControl::ProjectListItemControl() {
  202. set_focus_mode(FocusMode::FOCUS_ALL);
  203. VBoxContainer *favorite_box = memnew(VBoxContainer);
  204. favorite_box->set_alignment(BoxContainer::ALIGNMENT_CENTER);
  205. add_child(favorite_box);
  206. favorite_button = memnew(TextureButton);
  207. favorite_button->set_name("FavoriteButton");
  208. // This makes the project's "hover" style display correctly when hovering the favorite icon.
  209. favorite_button->set_mouse_filter(MOUSE_FILTER_PASS);
  210. favorite_box->add_child(favorite_button);
  211. favorite_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectListItemControl::_favorite_button_pressed));
  212. project_icon = memnew(TextureRect);
  213. project_icon->set_name("ProjectIcon");
  214. project_icon->set_v_size_flags(SIZE_SHRINK_CENTER);
  215. add_child(project_icon);
  216. main_vbox = memnew(VBoxContainer);
  217. main_vbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  218. add_child(main_vbox);
  219. Control *ec = memnew(Control);
  220. ec->set_custom_minimum_size(Size2(0, 1));
  221. ec->set_mouse_filter(MOUSE_FILTER_PASS);
  222. main_vbox->add_child(ec);
  223. // Top half, title, tags and unsupported features labels.
  224. {
  225. HBoxContainer *title_hb = memnew(HBoxContainer);
  226. main_vbox->add_child(title_hb);
  227. project_title = memnew(Label);
  228. project_title->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  229. project_title->set_name("ProjectName");
  230. project_title->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  231. project_title->set_clip_text(true);
  232. title_hb->add_child(project_title);
  233. tag_container = memnew(HBoxContainer);
  234. title_hb->add_child(tag_container);
  235. Control *spacer = memnew(Control);
  236. spacer->set_custom_minimum_size(Size2(10, 10));
  237. title_hb->add_child(spacer);
  238. }
  239. // Bottom half, containing the path and view folder button.
  240. {
  241. HBoxContainer *path_hb = memnew(HBoxContainer);
  242. path_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  243. main_vbox->add_child(path_hb);
  244. explore_button = memnew(Button);
  245. explore_button->set_name("ExploreButton");
  246. explore_button->set_flat(true);
  247. path_hb->add_child(explore_button);
  248. explore_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectListItemControl::_explore_button_pressed));
  249. project_path = memnew(Label);
  250. project_path->set_name("ProjectPath");
  251. project_path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
  252. project_path->set_clip_text(true);
  253. project_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  254. project_path->set_modulate(Color(1, 1, 1, 0.5));
  255. path_hb->add_child(project_path);
  256. project_unsupported_features = memnew(TextureRect);
  257. project_unsupported_features->set_name("ProjectUnsupportedFeatures");
  258. project_unsupported_features->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
  259. path_hb->add_child(project_unsupported_features);
  260. project_unsupported_features->hide();
  261. project_version = memnew(Label);
  262. project_version->set_name("ProjectVersion");
  263. project_version->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  264. path_hb->add_child(project_version);
  265. last_edited_info = memnew(Label);
  266. last_edited_info->set_name("LastEditedInfo");
  267. last_edited_info->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  268. last_edited_info->set_tooltip_text(TTR("Last edited timestamp"));
  269. last_edited_info->set_modulate(Color(1, 1, 1, 0.5));
  270. path_hb->add_child(last_edited_info);
  271. Control *spacer = memnew(Control);
  272. spacer->set_custom_minimum_size(Size2(10, 10));
  273. path_hb->add_child(spacer);
  274. }
  275. }
  276. struct ProjectListComparator {
  277. ProjectList::FilterOption order_option = ProjectList::FilterOption::EDIT_DATE;
  278. // operator<
  279. _FORCE_INLINE_ bool operator()(const ProjectList::Item &a, const ProjectList::Item &b) const {
  280. if (a.favorite && !b.favorite) {
  281. return true;
  282. }
  283. if (b.favorite && !a.favorite) {
  284. return false;
  285. }
  286. switch (order_option) {
  287. case ProjectList::PATH:
  288. return a.path < b.path;
  289. case ProjectList::EDIT_DATE:
  290. return a.last_edited > b.last_edited;
  291. case ProjectList::TAGS:
  292. return a.tag_sort_string < b.tag_sort_string;
  293. default:
  294. return a.project_name < b.project_name;
  295. }
  296. }
  297. };
  298. const char *ProjectList::SIGNAL_LIST_CHANGED = "list_changed";
  299. const char *ProjectList::SIGNAL_SELECTION_CHANGED = "selection_changed";
  300. const char *ProjectList::SIGNAL_PROJECT_ASK_OPEN = "project_ask_open";
  301. // Helpers.
  302. bool ProjectList::project_feature_looks_like_version(const String &p_feature) {
  303. return p_feature.contains_char('.') && p_feature.substr(0, 3).is_numeric();
  304. }
  305. // Notifications.
  306. void ProjectList::_notification(int p_what) {
  307. switch (p_what) {
  308. case NOTIFICATION_PROCESS: {
  309. // Load icons as a coroutine to speed up launch when you have hundreds of projects.
  310. if (_icon_load_index < _projects.size()) {
  311. Item &item = _projects.write[_icon_load_index];
  312. if (item.control->should_load_project_icon()) {
  313. _load_project_icon(_icon_load_index);
  314. }
  315. _icon_load_index++;
  316. // Scan directories in thread to avoid blocking the window.
  317. } else if (scan_data && scan_data->scan_in_progress.is_set()) {
  318. // Wait for the thread.
  319. } else {
  320. set_process(false);
  321. if (scan_data) {
  322. _scan_finished();
  323. }
  324. }
  325. } break;
  326. }
  327. }
  328. // Projects scan.
  329. void ProjectList::_scan_thread(void *p_scan_data) {
  330. ScanData *scan_data = static_cast<ScanData *>(p_scan_data);
  331. for (const String &base_path : scan_data->paths_to_scan) {
  332. print_verbose(vformat("Scanning for projects in \"%s\".", base_path));
  333. _scan_folder_recursive(base_path, &scan_data->found_projects, scan_data->scan_in_progress);
  334. if (!scan_data->scan_in_progress.is_set()) {
  335. print_verbose("Scan aborted.");
  336. break;
  337. }
  338. }
  339. print_verbose(vformat("Found %d project(s).", scan_data->found_projects.size()));
  340. scan_data->scan_in_progress.clear();
  341. }
  342. void ProjectList::_scan_finished() {
  343. if (scan_data->scan_in_progress.is_set()) {
  344. // Abort scanning.
  345. scan_data->scan_in_progress.clear();
  346. }
  347. scan_data->thread->wait_to_finish();
  348. memdelete(scan_data->thread);
  349. if (scan_progress) {
  350. scan_progress->hide();
  351. }
  352. for (const String &E : scan_data->found_projects) {
  353. add_project(E, false);
  354. }
  355. memdelete(scan_data);
  356. scan_data = nullptr;
  357. save_config();
  358. if (ProjectManager::get_singleton()->is_initialized()) {
  359. update_project_list();
  360. }
  361. }
  362. // Initialization & loading.
  363. void ProjectList::_migrate_config() {
  364. // Proposal #1637 moved the project list from editor settings to a separate config file
  365. // If the new config file doesn't exist, populate it from EditorSettings
  366. if (FileAccess::exists(_config_path)) {
  367. return;
  368. }
  369. List<PropertyInfo> properties;
  370. EditorSettings::get_singleton()->get_property_list(&properties);
  371. for (const PropertyInfo &E : properties) {
  372. // This is actually something like "projects/C:::Documents::Godot::Projects::MyGame"
  373. String property_key = E.name;
  374. if (!property_key.begins_with("projects/")) {
  375. continue;
  376. }
  377. String path = EDITOR_GET(property_key);
  378. print_line("Migrating legacy project '" + path + "'.");
  379. String favoriteKey = "favorite_projects/" + property_key.get_slice("/", 1);
  380. bool favorite = EditorSettings::get_singleton()->has_setting(favoriteKey);
  381. add_project(path, favorite);
  382. if (favorite) {
  383. EditorSettings::get_singleton()->erase(favoriteKey);
  384. }
  385. EditorSettings::get_singleton()->erase(property_key);
  386. }
  387. save_config();
  388. }
  389. void ProjectList::save_config() {
  390. _config.save(_config_path);
  391. }
  392. // Load project data from p_property_key and return it in a ProjectList::Item.
  393. // p_favorite is passed directly into the Item.
  394. ProjectList::Item ProjectList::load_project_data(const String &p_path, bool p_favorite) {
  395. String conf = p_path.path_join("project.godot");
  396. bool grayed = false;
  397. bool missing = false;
  398. bool recovery_mode = false;
  399. Ref<ConfigFile> cf = memnew(ConfigFile);
  400. Error cf_err = cf->load(conf);
  401. int config_version = 0;
  402. String cf_project_name;
  403. String project_name = TTR("Unnamed Project");
  404. if (cf_err == OK) {
  405. cf_project_name = cf->get_value("application", "config/name", "");
  406. if (!cf_project_name.is_empty()) {
  407. project_name = cf_project_name.xml_unescape();
  408. }
  409. config_version = (int)cf->get_value("", "config_version", 0);
  410. }
  411. if (config_version > ProjectSettings::CONFIG_VERSION) {
  412. // Comes from an incompatible (more recent) Godot version, gray it out.
  413. grayed = true;
  414. }
  415. const String description = cf->get_value("application", "config/description", "");
  416. const PackedStringArray tags = cf->get_value("application", "config/tags", PackedStringArray());
  417. const String main_scene = cf->get_value("application", "run/main_scene", "");
  418. String icon = cf->get_value("application", "config/icon", "");
  419. if (icon.begins_with("uid://")) {
  420. Error err;
  421. Ref<FileAccess> file = FileAccess::open(p_path.path_join(".godot/uid_cache.bin"), FileAccess::READ, &err);
  422. if (err == OK) {
  423. icon = ResourceUID::get_path_from_cache(file, icon);
  424. if (icon.is_empty()) {
  425. WARN_PRINT(vformat("Could not load icon from UID for project at path \"%s\". Make sure UID cache exists.", p_path));
  426. }
  427. } else {
  428. // Cache does not exist yet, so ignore and fallback to default icon.
  429. icon = "";
  430. }
  431. }
  432. PackedStringArray project_features = cf->get_value("application", "config/features", PackedStringArray());
  433. PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features);
  434. String project_version = "?";
  435. for (int i = 0; i < project_features.size(); i++) {
  436. if (ProjectList::project_feature_looks_like_version(project_features[i])) {
  437. project_version = project_features[i];
  438. break;
  439. }
  440. }
  441. if (config_version < ProjectSettings::CONFIG_VERSION) {
  442. // Previous versions may not have unsupported features.
  443. if (config_version == 4) {
  444. unsupported_features.push_back("3.x");
  445. project_version = "3.x";
  446. } else {
  447. unsupported_features.push_back("Unknown version");
  448. }
  449. }
  450. uint64_t last_edited = 0;
  451. if (cf_err == OK) {
  452. // The modification date marks the date the project was last edited.
  453. // This is because the `project.godot` file will always be modified
  454. // when editing a project (but not when running it).
  455. last_edited = FileAccess::get_modified_time(conf);
  456. String fscache = p_path.path_join(".fscache");
  457. if (FileAccess::exists(fscache)) {
  458. uint64_t cache_modified = FileAccess::get_modified_time(fscache);
  459. if (cache_modified > last_edited) {
  460. last_edited = cache_modified;
  461. }
  462. }
  463. } else {
  464. grayed = true;
  465. missing = true;
  466. print_line("Project is missing: " + conf);
  467. }
  468. for (const String &tag : tags) {
  469. ProjectManager::get_singleton()->add_new_tag(tag);
  470. }
  471. // We can't use OS::get_user_dir() because it attempts to load paths from the current loaded project through ProjectSettings,
  472. // while here we're parsing project files externally. Therefore, we have to replicate its behavior.
  473. String user_dir;
  474. if (!cf_project_name.is_empty()) {
  475. String appname = OS::get_singleton()->get_safe_dir_name(cf_project_name);
  476. bool use_custom_dir = cf->get_value("application", "config/use_custom_user_dir", false);
  477. if (use_custom_dir) {
  478. String custom_dir = OS::get_singleton()->get_safe_dir_name(cf->get_value("application", "config/custom_user_dir_name", ""), true);
  479. if (custom_dir.is_empty()) {
  480. custom_dir = appname;
  481. }
  482. user_dir = custom_dir;
  483. } else {
  484. user_dir = OS::get_singleton()->get_godot_dir_name().path_join("app_userdata").path_join(appname);
  485. }
  486. } else {
  487. user_dir = OS::get_singleton()->get_godot_dir_name().path_join("app_userdata").path_join("[unnamed project]");
  488. }
  489. String recovery_mode_lock_file = OS::get_singleton()->get_user_data_dir(user_dir).path_join(".recovery_mode_lock");
  490. recovery_mode = FileAccess::exists(recovery_mode_lock_file);
  491. return Item(project_name, description, project_version, tags, p_path, icon, main_scene, unsupported_features, last_edited, p_favorite, grayed, missing, recovery_mode, config_version);
  492. }
  493. void ProjectList::_update_icons_async() {
  494. _icon_load_index = 0;
  495. set_process(true);
  496. }
  497. void ProjectList::_load_project_icon(int p_index) {
  498. Item &item = _projects.write[p_index];
  499. Ref<Texture2D> default_icon = get_editor_theme_icon(SNAME("DefaultProjectIcon"));
  500. Ref<Texture2D> icon;
  501. if (!item.icon.is_empty()) {
  502. Ref<Image> img;
  503. img.instantiate();
  504. Error err = img->load(item.icon.replace_first("res://", item.path + "/"));
  505. if (err == OK) {
  506. img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS);
  507. icon = ImageTexture::create_from_image(img);
  508. }
  509. }
  510. if (icon.is_null()) {
  511. icon = default_icon;
  512. }
  513. item.control->set_project_icon(icon);
  514. }
  515. // Project list updates.
  516. void ProjectList::update_project_list() {
  517. // This is a full, hard reload of the list. Don't call this unless really required, it's expensive.
  518. // If you have 150 projects, it may read through 150 files on your disk at once + load 150 icons.
  519. // FIXME: Does it really have to be a full, hard reload? Runtime updates should be made much cheaper.
  520. if (ProjectManager::get_singleton()->is_initialized()) {
  521. // Clear whole list
  522. for (int i = 0; i < _projects.size(); ++i) {
  523. Item &project = _projects.write[i];
  524. CRASH_COND(project.control == nullptr);
  525. memdelete(project.control); // Why not queue_free()?
  526. }
  527. _projects.clear();
  528. _last_clicked = "";
  529. _selected_project_paths.clear();
  530. load_project_list();
  531. }
  532. // Create controls
  533. for (int i = 0; i < _projects.size(); ++i) {
  534. _create_project_item_control(i);
  535. }
  536. sort_projects();
  537. _update_icons_async();
  538. update_dock_menu();
  539. set_v_scroll(0);
  540. emit_signal(SNAME(SIGNAL_LIST_CHANGED));
  541. }
  542. void ProjectList::sort_projects() {
  543. SortArray<Item, ProjectListComparator> sorter;
  544. sorter.compare.order_option = _order_option;
  545. sorter.sort(_projects.ptrw(), _projects.size());
  546. String search_term;
  547. PackedStringArray tags;
  548. if (!_search_term.is_empty()) {
  549. PackedStringArray search_parts = _search_term.split(" ");
  550. if (search_parts.size() > 1 || search_parts[0].begins_with("tag:")) {
  551. PackedStringArray remaining;
  552. for (const String &part : search_parts) {
  553. if (part.begins_with("tag:")) {
  554. tags.push_back(part.get_slice(":", 1));
  555. } else {
  556. remaining.append(part);
  557. }
  558. }
  559. search_term = String(" ").join(remaining); // Search term without tags.
  560. } else {
  561. search_term = _search_term;
  562. }
  563. }
  564. for (int i = 0; i < _projects.size(); ++i) {
  565. Item &item = _projects.write[i];
  566. bool item_visible = true;
  567. if (!_search_term.is_empty()) {
  568. String search_path;
  569. if (search_term.contains_char('/')) {
  570. // Search path will match the whole path
  571. search_path = item.path;
  572. } else {
  573. // Search path will only match the last path component to make searching more strict
  574. search_path = item.path.get_file();
  575. }
  576. bool missing_tags = false;
  577. for (const String &tag : tags) {
  578. if (!item.tags.has(tag)) {
  579. missing_tags = true;
  580. break;
  581. }
  582. }
  583. // When searching, display projects whose name or path contain the search term and whose tags match the searched tags.
  584. item_visible = !missing_tags && (search_term.is_empty() || item.project_name.containsn(search_term) || search_path.containsn(search_term));
  585. }
  586. item.control->set_visible(item_visible);
  587. }
  588. for (int i = 0; i < _projects.size(); ++i) {
  589. Item &item = _projects.write[i];
  590. item.control->get_parent()->move_child(item.control, i);
  591. }
  592. // Rewind the coroutine because order of projects changed
  593. _update_icons_async();
  594. update_dock_menu();
  595. }
  596. int ProjectList::get_project_count() const {
  597. return _projects.size();
  598. }
  599. void ProjectList::find_projects(const String &p_path) {
  600. PackedStringArray paths = { p_path };
  601. find_projects_multiple(paths);
  602. }
  603. void ProjectList::find_projects_multiple(const PackedStringArray &p_paths) {
  604. if (!scan_progress && is_inside_tree()) {
  605. scan_progress = memnew(AcceptDialog);
  606. scan_progress->set_title(TTR("Scanning"));
  607. scan_progress->set_ok_button_text(TTR("Cancel"));
  608. VBoxContainer *vb = memnew(VBoxContainer);
  609. scan_progress->add_child(vb);
  610. Label *label = memnew(Label);
  611. label->set_text(TTR("Scanning for projects..."));
  612. vb->add_child(label);
  613. ProgressBar *progress = memnew(ProgressBar);
  614. progress->set_indeterminate(true);
  615. vb->add_child(progress);
  616. add_child(scan_progress);
  617. scan_progress->connect(SceneStringName(confirmed), callable_mp(this, &ProjectList::_scan_finished));
  618. scan_progress->connect("canceled", callable_mp(this, &ProjectList::_scan_finished));
  619. }
  620. scan_data = memnew(ScanData);
  621. scan_data->paths_to_scan = p_paths;
  622. scan_data->scan_in_progress.set();
  623. scan_data->thread = memnew(Thread);
  624. scan_data->thread->start(_scan_thread, scan_data);
  625. if (scan_progress) {
  626. scan_progress->reset_size();
  627. scan_progress->popup_centered();
  628. }
  629. set_process(true);
  630. }
  631. void ProjectList::load_project_list() {
  632. List<String> sections;
  633. _config.load(_config_path);
  634. _config.get_sections(&sections);
  635. for (const String &path : sections) {
  636. bool favorite = _config.get_value(path, "favorite", false);
  637. _projects.push_back(load_project_data(path, favorite));
  638. }
  639. }
  640. void ProjectList::_scan_folder_recursive(const String &p_path, List<String> *r_projects, const SafeFlag &p_scan_active) {
  641. if (!p_scan_active.is_set()) {
  642. return;
  643. }
  644. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  645. Error error = da->change_dir(p_path);
  646. ERR_FAIL_COND_MSG(error != OK, vformat("Failed to open the path \"%s\" for scanning (code %d).", p_path, error));
  647. da->list_dir_begin();
  648. String n = da->get_next();
  649. while (!n.is_empty()) {
  650. if (!p_scan_active.is_set()) {
  651. return;
  652. }
  653. if (da->current_is_dir() && n[0] != '.') {
  654. _scan_folder_recursive(da->get_current_dir().path_join(n), r_projects, p_scan_active);
  655. } else if (n == "project.godot") {
  656. r_projects->push_back(da->get_current_dir());
  657. }
  658. n = da->get_next();
  659. }
  660. da->list_dir_end();
  661. }
  662. // Project list items.
  663. void ProjectList::add_project(const String &dir_path, bool favorite) {
  664. if (!_config.has_section(dir_path)) {
  665. _config.set_value(dir_path, "favorite", favorite);
  666. }
  667. }
  668. void ProjectList::set_project_version(const String &p_project_path, int p_version) {
  669. for (ProjectList::Item &E : _projects) {
  670. if (E.path == p_project_path) {
  671. E.version = p_version;
  672. break;
  673. }
  674. }
  675. }
  676. int ProjectList::refresh_project(const String &dir_path) {
  677. // Reloads information about a specific project.
  678. // If it wasn't loaded and should be in the list, it is added (i.e new project).
  679. // If it isn't in the list anymore, it is removed.
  680. // If it is in the list but doesn't exist anymore, it is marked as missing.
  681. bool should_be_in_list = _config.has_section(dir_path);
  682. bool is_favourite = _config.get_value(dir_path, "favorite", false);
  683. bool was_selected = _selected_project_paths.has(dir_path);
  684. // Remove item in any case
  685. for (int i = 0; i < _projects.size(); ++i) {
  686. const Item &existing_item = _projects[i];
  687. if (existing_item.path == dir_path) {
  688. _remove_project(i, false);
  689. break;
  690. }
  691. }
  692. int index = -1;
  693. if (should_be_in_list) {
  694. // Recreate it with updated info
  695. Item item = load_project_data(dir_path, is_favourite);
  696. _projects.push_back(item);
  697. _create_project_item_control(_projects.size() - 1);
  698. sort_projects();
  699. for (int i = 0; i < _projects.size(); ++i) {
  700. if (_projects[i].path == dir_path) {
  701. if (was_selected) {
  702. select_project(i);
  703. ensure_project_visible(i);
  704. }
  705. _load_project_icon(i);
  706. index = i;
  707. break;
  708. }
  709. }
  710. }
  711. return index;
  712. }
  713. void ProjectList::ensure_project_visible(int p_index) {
  714. const Item &item = _projects[p_index];
  715. ensure_control_visible(item.control);
  716. }
  717. void ProjectList::_create_project_item_control(int p_index) {
  718. // Will be added last in the list, so make sure indexes match
  719. ERR_FAIL_COND(p_index != project_list_vbox->get_child_count());
  720. Item &item = _projects.write[p_index];
  721. ERR_FAIL_COND(item.control != nullptr); // Already created
  722. ProjectListItemControl *hb = memnew(ProjectListItemControl);
  723. hb->add_theme_constant_override("separation", 10 * EDSCALE);
  724. hb->set_project_title(!item.missing ? item.project_name : TTR("Missing Project"));
  725. hb->set_project_path(item.path);
  726. hb->set_tooltip_text(item.description);
  727. hb->set_tags(item.tags, this);
  728. hb->set_unsupported_features(item.unsupported_features.duplicate());
  729. hb->set_project_version(item.project_version);
  730. hb->set_last_edited_info(!item.missing ? Time::get_singleton()->get_datetime_string_from_unix_time(item.last_edited, true) : TTR("Missing Date"));
  731. hb->set_is_favorite(item.favorite);
  732. hb->set_is_missing(item.missing);
  733. hb->set_is_grayed(item.grayed);
  734. hb->connect(SceneStringName(gui_input), callable_mp(this, &ProjectList::_list_item_input).bind(hb));
  735. hb->connect("favorite_pressed", callable_mp(this, &ProjectList::_on_favorite_pressed).bind(hb));
  736. #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
  737. hb->connect("explore_pressed", callable_mp(this, &ProjectList::_on_explore_pressed).bind(item.path));
  738. #endif
  739. project_list_vbox->add_child(hb);
  740. item.control = hb;
  741. }
  742. void ProjectList::_toggle_project(int p_index) {
  743. // This methods adds to the selection or removes from the
  744. // selection.
  745. Item &item = _projects.write[p_index];
  746. if (_selected_project_paths.has(item.path)) {
  747. _deselect_project_nocheck(p_index);
  748. } else {
  749. _select_project_nocheck(p_index);
  750. }
  751. }
  752. void ProjectList::_remove_project(int p_index, bool p_update_config) {
  753. const Item item = _projects[p_index]; // Take a copy
  754. _selected_project_paths.erase(item.path);
  755. if (_last_clicked == item.path) {
  756. _last_clicked = "";
  757. }
  758. memdelete(item.control);
  759. _projects.remove_at(p_index);
  760. if (p_update_config) {
  761. _config.erase_section(item.path);
  762. // Not actually saving the file, in case you are doing more changes to settings
  763. }
  764. update_dock_menu();
  765. }
  766. void ProjectList::_list_item_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
  767. Ref<InputEventMouseButton> mb = p_ev;
  768. int clicked_index = p_hb->get_index();
  769. const Item &clicked_project = _projects[clicked_index];
  770. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
  771. if (mb->is_shift_pressed() && _selected_project_paths.size() > 0 && !_last_clicked.is_empty() && clicked_project.path != _last_clicked) {
  772. int anchor_index = -1;
  773. for (int i = 0; i < _projects.size(); ++i) {
  774. const Item &p = _projects[i];
  775. if (p.path == _last_clicked) {
  776. anchor_index = p.control->get_index();
  777. break;
  778. }
  779. }
  780. CRASH_COND(anchor_index == -1);
  781. _select_project_range(anchor_index, clicked_index);
  782. } else if (mb->is_command_or_control_pressed()) {
  783. _toggle_project(clicked_index);
  784. } else {
  785. _last_clicked = clicked_project.path;
  786. select_project(clicked_index);
  787. }
  788. emit_signal(SNAME(SIGNAL_SELECTION_CHANGED));
  789. // Do not allow opening a project more than once using a single project manager instance.
  790. // Opening the same project in several editor instances at once can lead to various issues.
  791. if (!mb->is_command_or_control_pressed() && mb->is_double_click() && !project_opening_initiated) {
  792. emit_signal(SNAME(SIGNAL_PROJECT_ASK_OPEN));
  793. }
  794. }
  795. }
  796. void ProjectList::_on_favorite_pressed(Node *p_hb) {
  797. ProjectListItemControl *control = Object::cast_to<ProjectListItemControl>(p_hb);
  798. int index = control->get_index();
  799. Item item = _projects.write[index]; // Take copy
  800. item.favorite = !item.favorite;
  801. _config.set_value(item.path, "favorite", item.favorite);
  802. save_config();
  803. _projects.write[index] = item;
  804. control->set_is_favorite(item.favorite);
  805. sort_projects();
  806. if (item.favorite) {
  807. for (int i = 0; i < _projects.size(); ++i) {
  808. if (_projects[i].path == item.path) {
  809. ensure_project_visible(i);
  810. break;
  811. }
  812. }
  813. }
  814. update_dock_menu();
  815. }
  816. void ProjectList::_on_explore_pressed(const String &p_path) {
  817. OS::get_singleton()->shell_show_in_file_manager(p_path, true);
  818. }
  819. // Project list selection.
  820. void ProjectList::_clear_project_selection() {
  821. Vector<Item> previous_selected_items = get_selected_projects();
  822. _selected_project_paths.clear();
  823. for (int i = 0; i < previous_selected_items.size(); ++i) {
  824. previous_selected_items[i].control->set_selected(false);
  825. }
  826. }
  827. void ProjectList::_select_project_nocheck(int p_index) {
  828. Item &item = _projects.write[p_index];
  829. _selected_project_paths.insert(item.path);
  830. item.control->set_selected(true);
  831. }
  832. void ProjectList::_deselect_project_nocheck(int p_index) {
  833. Item &item = _projects.write[p_index];
  834. _selected_project_paths.erase(item.path);
  835. item.control->set_selected(false);
  836. }
  837. inline void _sort_project_range(int &a, int &b) {
  838. if (a > b) {
  839. int temp = a;
  840. a = b;
  841. b = temp;
  842. }
  843. }
  844. void ProjectList::_select_project_range(int p_begin, int p_end) {
  845. _clear_project_selection();
  846. _sort_project_range(p_begin, p_end);
  847. for (int i = p_begin; i <= p_end; ++i) {
  848. _select_project_nocheck(i);
  849. }
  850. }
  851. void ProjectList::select_project(int p_index) {
  852. // This method keeps only one project selected.
  853. _clear_project_selection();
  854. _select_project_nocheck(p_index);
  855. }
  856. void ProjectList::select_first_visible_project() {
  857. _clear_project_selection();
  858. for (int i = 0; i < _projects.size(); i++) {
  859. if (_projects[i].control->is_visible()) {
  860. _select_project_nocheck(i);
  861. break;
  862. }
  863. }
  864. }
  865. Vector<ProjectList::Item> ProjectList::get_selected_projects() const {
  866. Vector<Item> items;
  867. if (_selected_project_paths.size() == 0) {
  868. return items;
  869. }
  870. items.resize(_selected_project_paths.size());
  871. int j = 0;
  872. for (int i = 0; i < _projects.size(); ++i) {
  873. const Item &item = _projects[i];
  874. if (_selected_project_paths.has(item.path)) {
  875. items.write[j++] = item;
  876. }
  877. }
  878. ERR_FAIL_COND_V(j != items.size(), items);
  879. return items;
  880. }
  881. const HashSet<String> &ProjectList::get_selected_project_keys() const {
  882. // Faster if that's all you need
  883. return _selected_project_paths;
  884. }
  885. int ProjectList::get_single_selected_index() const {
  886. if (_selected_project_paths.size() == 0) {
  887. // Default selection
  888. return 0;
  889. }
  890. String key;
  891. if (_selected_project_paths.size() == 1) {
  892. // Only one selected
  893. key = *_selected_project_paths.begin();
  894. } else {
  895. // Multiple selected, consider the last clicked one as "main"
  896. key = _last_clicked;
  897. }
  898. for (int i = 0; i < _projects.size(); ++i) {
  899. if (_projects[i].path == key) {
  900. return i;
  901. }
  902. }
  903. return 0;
  904. }
  905. void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
  906. if (_selected_project_paths.size() == 0) {
  907. return;
  908. }
  909. for (int i = 0; i < _projects.size(); ++i) {
  910. Item &item = _projects.write[i];
  911. if (_selected_project_paths.has(item.path) && item.control->is_visible()) {
  912. _config.erase_section(item.path);
  913. // Comment out for now until we have a better warning system to
  914. // ensure users delete their project only.
  915. //if (p_delete_project_contents) {
  916. // OS::get_singleton()->move_to_trash(item.path);
  917. //}
  918. memdelete(item.control);
  919. _projects.remove_at(i);
  920. --i;
  921. }
  922. }
  923. save_config();
  924. _selected_project_paths.clear();
  925. _last_clicked = "";
  926. update_dock_menu();
  927. }
  928. // Missing projects.
  929. bool ProjectList::is_any_project_missing() const {
  930. for (int i = 0; i < _projects.size(); ++i) {
  931. if (_projects[i].missing) {
  932. return true;
  933. }
  934. }
  935. return false;
  936. }
  937. void ProjectList::erase_missing_projects() {
  938. if (_projects.is_empty()) {
  939. return;
  940. }
  941. int deleted_count = 0;
  942. int remaining_count = 0;
  943. for (int i = 0; i < _projects.size(); ++i) {
  944. const Item &item = _projects[i];
  945. if (item.missing) {
  946. _remove_project(i, true);
  947. --i;
  948. ++deleted_count;
  949. } else {
  950. ++remaining_count;
  951. }
  952. }
  953. print_line("Removed " + itos(deleted_count) + " projects from the list, remaining " + itos(remaining_count) + " projects");
  954. save_config();
  955. }
  956. // Project list sorting and filtering.
  957. void ProjectList::set_search_term(String p_search_term) {
  958. _search_term = p_search_term;
  959. }
  960. void ProjectList::add_search_tag(const String &p_tag) {
  961. const String tag_string = "tag:" + p_tag;
  962. int exists = _search_term.find(tag_string);
  963. if (exists > -1) {
  964. _search_term = _search_term.erase(exists, tag_string.length() + 1);
  965. } else if (_search_term.is_empty() || _search_term.ends_with(" ")) {
  966. _search_term += tag_string;
  967. } else {
  968. _search_term += " " + tag_string;
  969. }
  970. ProjectManager::get_singleton()->get_search_box()->set_text(_search_term);
  971. sort_projects();
  972. }
  973. void ProjectList::set_order_option(int p_option) {
  974. FilterOption selected = (FilterOption)p_option;
  975. EditorSettings::get_singleton()->set("project_manager/sorting_order", p_option);
  976. EditorSettings::get_singleton()->save();
  977. _order_option = selected;
  978. sort_projects();
  979. }
  980. // Global menu integration.
  981. void ProjectList::update_dock_menu() {
  982. if (!NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
  983. return;
  984. }
  985. RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
  986. NativeMenu::get_singleton()->clear(dock_rid);
  987. int favs_added = 0;
  988. int total_added = 0;
  989. for (int i = 0; i < _projects.size(); ++i) {
  990. if (!_projects[i].grayed && !_projects[i].missing) {
  991. if (_projects[i].favorite) {
  992. favs_added++;
  993. } else {
  994. if (favs_added != 0) {
  995. NativeMenu::get_singleton()->add_separator(dock_rid);
  996. }
  997. favs_added = 0;
  998. }
  999. NativeMenu::get_singleton()->add_item(dock_rid, _projects[i].project_name + " ( " + _projects[i].path + " )", callable_mp(this, &ProjectList::_global_menu_open_project), Callable(), i);
  1000. total_added++;
  1001. }
  1002. }
  1003. if (total_added != 0) {
  1004. NativeMenu::get_singleton()->add_separator(dock_rid);
  1005. }
  1006. NativeMenu::get_singleton()->add_item(dock_rid, TTR("New Window"), callable_mp(this, &ProjectList::_global_menu_new_window));
  1007. }
  1008. void ProjectList::_global_menu_new_window(const Variant &p_tag) {
  1009. List<String> args;
  1010. args.push_back("-p");
  1011. OS::get_singleton()->create_instance(args);
  1012. }
  1013. void ProjectList::_global_menu_open_project(const Variant &p_tag) {
  1014. int idx = (int)p_tag;
  1015. if (idx >= 0 && idx < _projects.size()) {
  1016. String conf = _projects[idx].path.path_join("project.godot");
  1017. List<String> args;
  1018. args.push_back(conf);
  1019. OS::get_singleton()->create_instance(args);
  1020. }
  1021. }
  1022. // Object methods.
  1023. void ProjectList::_bind_methods() {
  1024. ADD_SIGNAL(MethodInfo(SIGNAL_LIST_CHANGED));
  1025. ADD_SIGNAL(MethodInfo(SIGNAL_SELECTION_CHANGED));
  1026. ADD_SIGNAL(MethodInfo(SIGNAL_PROJECT_ASK_OPEN));
  1027. }
  1028. ProjectList::ProjectList() {
  1029. project_list_vbox = memnew(VBoxContainer);
  1030. project_list_vbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1031. add_child(project_list_vbox);
  1032. _config_path = EditorPaths::get_singleton()->get_data_dir().path_join("projects.cfg");
  1033. _migrate_config();
  1034. }