project_manager.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. /**************************************************************************/
  2. /* project_manager.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_manager.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/config_file.h"
  33. #include "core/io/dir_access.h"
  34. #include "core/io/file_access.h"
  35. #include "core/io/resource_saver.h"
  36. #include "core/io/stream_peer_tls.h"
  37. #include "core/os/keyboard.h"
  38. #include "core/os/os.h"
  39. #include "core/version.h"
  40. #include "editor/editor_about.h"
  41. #include "editor/editor_settings.h"
  42. #include "editor/editor_string_names.h"
  43. #include "editor/gui/editor_file_dialog.h"
  44. #include "editor/plugins/asset_library_editor_plugin.h"
  45. #include "editor/project_manager/project_dialog.h"
  46. #include "editor/project_manager/project_list.h"
  47. #include "editor/project_manager/project_tag.h"
  48. #include "editor/project_manager/quick_settings_dialog.h"
  49. #include "editor/themes/editor_icons.h"
  50. #include "editor/themes/editor_scale.h"
  51. #include "editor/themes/editor_theme_manager.h"
  52. #include "main/main.h"
  53. #include "scene/gui/check_box.h"
  54. #include "scene/gui/color_rect.h"
  55. #include "scene/gui/flow_container.h"
  56. #include "scene/gui/line_edit.h"
  57. #include "scene/gui/margin_container.h"
  58. #include "scene/gui/option_button.h"
  59. #include "scene/gui/panel_container.h"
  60. #include "scene/gui/rich_text_label.h"
  61. #include "scene/gui/separator.h"
  62. #include "scene/gui/texture_rect.h"
  63. #include "scene/main/window.h"
  64. #include "scene/theme/theme_db.h"
  65. #include "servers/display_server.h"
  66. #include "servers/navigation_server_3d.h"
  67. #include "servers/physics_server_2d.h"
  68. constexpr int GODOT4_CONFIG_VERSION = 5;
  69. ProjectManager *ProjectManager::singleton = nullptr;
  70. // Notifications.
  71. void ProjectManager::_notification(int p_what) {
  72. switch (p_what) {
  73. case NOTIFICATION_ENTER_TREE: {
  74. Engine::get_singleton()->set_editor_hint(false);
  75. // Theme has already been created in the constructor, so we can skip that step.
  76. _update_theme(true);
  77. } break;
  78. case NOTIFICATION_READY: {
  79. const int default_sorting = (int)EDITOR_GET("project_manager/sorting_order");
  80. filter_option->select(default_sorting);
  81. project_list->set_order_option(default_sorting);
  82. _select_main_view(MAIN_VIEW_PROJECTS);
  83. _update_list_placeholder();
  84. } break;
  85. case NOTIFICATION_VISIBILITY_CHANGED: {
  86. set_process_shortcut_input(is_visible_in_tree());
  87. } break;
  88. case NOTIFICATION_WM_CLOSE_REQUEST: {
  89. _dim_window();
  90. } break;
  91. case NOTIFICATION_WM_ABOUT: {
  92. _show_about();
  93. } break;
  94. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  95. if (EditorThemeManager::is_generated_theme_outdated()) {
  96. _update_theme();
  97. }
  98. _update_list_placeholder();
  99. } break;
  100. }
  101. }
  102. // Utility data.
  103. Ref<Texture2D> ProjectManager::_file_dialog_get_icon(const String &p_path) {
  104. if (p_path.get_extension().to_lower() == "godot") {
  105. return singleton->icon_type_cache["GodotMonochrome"];
  106. }
  107. return singleton->icon_type_cache["Object"];
  108. }
  109. Ref<Texture2D> ProjectManager::_file_dialog_get_thumbnail(const String &p_path) {
  110. if (p_path.get_extension().to_lower() == "godot") {
  111. return singleton->icon_type_cache["GodotFile"];
  112. }
  113. return Ref<Texture2D>();
  114. }
  115. void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {
  116. if (p_theme.is_null()) {
  117. return;
  118. }
  119. List<StringName> tl;
  120. p_theme->get_icon_list(EditorStringName(EditorIcons), &tl);
  121. for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
  122. icon_type_cache[E->get()] = p_theme->get_icon(E->get(), EditorStringName(EditorIcons));
  123. }
  124. }
  125. // Main layout.
  126. void ProjectManager::_update_size_limits() {
  127. const Size2 minimum_size = Size2(680, 450) * EDSCALE;
  128. const Size2 default_size = Size2(1024, 600) * EDSCALE;
  129. // Define a minimum window size to prevent UI elements from overlapping or being cut off.
  130. Window *w = Object::cast_to<Window>(SceneTree::get_singleton()->get_root());
  131. if (w) {
  132. // Calling Window methods this early doesn't sync properties with DS.
  133. w->set_min_size(minimum_size);
  134. DisplayServer::get_singleton()->window_set_min_size(minimum_size);
  135. w->set_size(default_size);
  136. DisplayServer::get_singleton()->window_set_size(default_size);
  137. }
  138. Rect2i screen_rect = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen());
  139. if (screen_rect.size != Vector2i()) {
  140. // Center the window on the screen.
  141. Vector2i window_position;
  142. window_position.x = screen_rect.position.x + (screen_rect.size.x - default_size.x) / 2;
  143. window_position.y = screen_rect.position.y + (screen_rect.size.y - default_size.y) / 2;
  144. DisplayServer::get_singleton()->window_set_position(window_position);
  145. // Limit popup menus to prevent unusably long lists.
  146. // We try to set it to half the screen resolution, but no smaller than the minimum window size.
  147. Size2 half_screen_rect = (screen_rect.size * EDSCALE) / 2;
  148. Size2 maximum_popup_size = MAX(half_screen_rect, minimum_size);
  149. quick_settings_dialog->update_size_limits(maximum_popup_size);
  150. }
  151. }
  152. void ProjectManager::_update_theme(bool p_skip_creation) {
  153. if (!p_skip_creation) {
  154. theme = EditorThemeManager::generate_theme(theme);
  155. DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
  156. }
  157. List<Ref<Theme>> editor_themes;
  158. editor_themes.push_back(theme);
  159. editor_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
  160. ThemeContext *node_tc = ThemeDB::get_singleton()->get_theme_context(this);
  161. if (node_tc) {
  162. node_tc->set_themes(editor_themes);
  163. } else {
  164. ThemeDB::get_singleton()->create_theme_context(this, editor_themes);
  165. }
  166. Window *owner_window = get_window();
  167. if (owner_window) {
  168. ThemeContext *window_tc = ThemeDB::get_singleton()->get_theme_context(owner_window);
  169. if (window_tc) {
  170. window_tc->set_themes(editor_themes);
  171. } else {
  172. ThemeDB::get_singleton()->create_theme_context(owner_window, editor_themes);
  173. }
  174. }
  175. // Update styles.
  176. {
  177. const int top_bar_separation = get_theme_constant(SNAME("top_bar_separation"), EditorStringName(Editor));
  178. root_container->add_theme_constant_override("margin_left", top_bar_separation);
  179. root_container->add_theme_constant_override("margin_top", top_bar_separation);
  180. root_container->add_theme_constant_override("margin_bottom", top_bar_separation);
  181. root_container->add_theme_constant_override("margin_right", top_bar_separation);
  182. main_vbox->add_theme_constant_override("separation", top_bar_separation);
  183. background_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("Background"), EditorStringName(EditorStyles)));
  184. main_view_container->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("TabContainer")));
  185. title_bar_logo->set_icon(get_editor_theme_icon(SNAME("TitleBarLogo")));
  186. _set_main_view_icon(MAIN_VIEW_PROJECTS, get_editor_theme_icon(SNAME("ProjectList")));
  187. _set_main_view_icon(MAIN_VIEW_ASSETLIB, get_editor_theme_icon(SNAME("AssetLib")));
  188. // Project list.
  189. {
  190. loading_label->add_theme_font_override("font", get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)));
  191. project_list_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("project_list"), SNAME("ProjectManager")));
  192. empty_list_create_project->set_icon(get_editor_theme_icon(SNAME("Add")));
  193. empty_list_import_project->set_icon(get_editor_theme_icon(SNAME("Load")));
  194. empty_list_open_assetlib->set_icon(get_editor_theme_icon(SNAME("AssetLib")));
  195. empty_list_online_warning->add_theme_font_override("font", get_theme_font(SNAME("italic"), EditorStringName(EditorFonts)));
  196. empty_list_online_warning->add_theme_color_override("font_color", get_theme_color(SNAME("font_placeholder_color"), EditorStringName(Editor)));
  197. // Top bar.
  198. search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  199. quick_settings_button->set_icon(get_editor_theme_icon(SNAME("Tools")));
  200. // Sidebar.
  201. create_btn->set_icon(get_editor_theme_icon(SNAME("Add")));
  202. import_btn->set_icon(get_editor_theme_icon(SNAME("Load")));
  203. scan_btn->set_icon(get_editor_theme_icon(SNAME("Search")));
  204. open_btn->set_icon(get_editor_theme_icon(SNAME("Edit")));
  205. run_btn->set_icon(get_editor_theme_icon(SNAME("Play")));
  206. rename_btn->set_icon(get_editor_theme_icon(SNAME("Rename")));
  207. manage_tags_btn->set_icon(get_editor_theme_icon("Script"));
  208. erase_btn->set_icon(get_editor_theme_icon(SNAME("Remove")));
  209. erase_missing_btn->set_icon(get_editor_theme_icon(SNAME("Clear")));
  210. create_tag_btn->set_icon(get_editor_theme_icon("Add"));
  211. tag_error->add_theme_color_override("font_color", get_theme_color("error_color", EditorStringName(Editor)));
  212. tag_edit_error->add_theme_color_override("font_color", get_theme_color("error_color", EditorStringName(Editor)));
  213. create_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  214. import_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  215. scan_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  216. open_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  217. run_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  218. rename_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  219. manage_tags_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  220. erase_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  221. erase_missing_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  222. }
  223. // Asset library popup.
  224. if (asset_library) {
  225. // Removes extra border margins.
  226. asset_library->add_theme_style_override("panel", memnew(StyleBoxEmpty));
  227. }
  228. }
  229. }
  230. Button *ProjectManager::_add_main_view(MainViewTab p_id, const String &p_name, const Ref<Texture2D> &p_icon, Control *p_view_control) {
  231. ERR_FAIL_INDEX_V(p_id, MAIN_VIEW_MAX, nullptr);
  232. ERR_FAIL_COND_V(main_view_map.has(p_id), nullptr);
  233. ERR_FAIL_COND_V(main_view_toggle_map.has(p_id), nullptr);
  234. Button *toggle_button = memnew(Button);
  235. toggle_button->set_flat(true);
  236. toggle_button->set_theme_type_variation("MainScreenButton");
  237. toggle_button->set_toggle_mode(true);
  238. toggle_button->set_button_group(main_view_toggles_group);
  239. toggle_button->set_text(p_name);
  240. toggle_button->connect("pressed", callable_mp(this, &ProjectManager::_select_main_view).bind((int)p_id));
  241. main_view_toggles->add_child(toggle_button);
  242. main_view_toggle_map[p_id] = toggle_button;
  243. _set_main_view_icon(p_id, p_icon);
  244. p_view_control->set_visible(false);
  245. main_view_container->add_child(p_view_control);
  246. main_view_map[p_id] = p_view_control;
  247. return toggle_button;
  248. }
  249. void ProjectManager::_set_main_view_icon(MainViewTab p_id, const Ref<Texture2D> &p_icon) {
  250. ERR_FAIL_INDEX(p_id, MAIN_VIEW_MAX);
  251. ERR_FAIL_COND(!main_view_toggle_map.has(p_id));
  252. Button *toggle_button = main_view_toggle_map[p_id];
  253. Ref<Texture2D> old_icon = toggle_button->get_icon();
  254. if (old_icon.is_valid()) {
  255. old_icon->disconnect_changed(callable_mp((Control *)toggle_button, &Control::update_minimum_size));
  256. }
  257. if (p_icon.is_valid()) {
  258. toggle_button->set_icon(p_icon);
  259. // Make sure the control is updated if the icon is reimported.
  260. p_icon->connect_changed(callable_mp((Control *)toggle_button, &Control::update_minimum_size));
  261. } else {
  262. toggle_button->set_icon(Ref<Texture2D>());
  263. }
  264. }
  265. void ProjectManager::_select_main_view(int p_id) {
  266. MainViewTab view_id = (MainViewTab)p_id;
  267. ERR_FAIL_INDEX(view_id, MAIN_VIEW_MAX);
  268. ERR_FAIL_COND(!main_view_map.has(view_id));
  269. ERR_FAIL_COND(!main_view_toggle_map.has(view_id));
  270. if (current_main_view != view_id) {
  271. main_view_toggle_map[current_main_view]->set_pressed_no_signal(false);
  272. main_view_map[current_main_view]->set_visible(false);
  273. current_main_view = view_id;
  274. }
  275. main_view_toggle_map[current_main_view]->set_pressed_no_signal(true);
  276. main_view_map[current_main_view]->set_visible(true);
  277. #ifndef ANDROID_ENABLED
  278. if (current_main_view == MAIN_VIEW_PROJECTS && search_box->is_inside_tree()) {
  279. // Automatically grab focus when the user moves from the Templates tab
  280. // back to the Projects tab.
  281. search_box->grab_focus();
  282. }
  283. // The Templates tab's search field is focused on display in the asset
  284. // library editor plugin code.
  285. #endif
  286. }
  287. void ProjectManager::_show_about() {
  288. about_dialog->popup_centered(Size2(780, 500) * EDSCALE);
  289. }
  290. void ProjectManager::_open_asset_library_confirmed() {
  291. const int network_mode = EDITOR_GET("network/connection/network_mode");
  292. if (network_mode == EditorSettings::NETWORK_OFFLINE) {
  293. EditorSettings::get_singleton()->set_setting("network/connection/network_mode", EditorSettings::NETWORK_ONLINE);
  294. EditorSettings::get_singleton()->notify_changes();
  295. EditorSettings::get_singleton()->save();
  296. }
  297. asset_library->disable_community_support();
  298. _select_main_view(MAIN_VIEW_ASSETLIB);
  299. }
  300. void ProjectManager::_show_error(const String &p_message, const Size2 &p_min_size) {
  301. error_dialog->set_text(p_message);
  302. error_dialog->popup_centered(p_min_size);
  303. }
  304. void ProjectManager::_dim_window() {
  305. // This method must be called before calling `get_tree()->quit()`.
  306. // Otherwise, its effect won't be visible
  307. // Dim the project manager window while it's quitting to make it clearer that it's busy.
  308. // No transition is applied, as the effect needs to be visible immediately
  309. float c = 0.5f;
  310. Color dim_color = Color(c, c, c);
  311. set_modulate(dim_color);
  312. }
  313. // Quick settings.
  314. void ProjectManager::_show_quick_settings() {
  315. quick_settings_dialog->popup_centered(Size2(600, 200) * EDSCALE);
  316. }
  317. void ProjectManager::_restart_confirmed() {
  318. List<String> args = OS::get_singleton()->get_cmdline_args();
  319. Error err = OS::get_singleton()->create_instance(args);
  320. ERR_FAIL_COND(err);
  321. _dim_window();
  322. get_tree()->quit();
  323. }
  324. // Footer.
  325. void ProjectManager::_version_button_pressed() {
  326. DisplayServer::get_singleton()->clipboard_set(version_btn->get_text());
  327. }
  328. // Project list.
  329. void ProjectManager::_update_list_placeholder() {
  330. if (project_list->get_project_count() > 0) {
  331. empty_list_placeholder->hide();
  332. return;
  333. }
  334. empty_list_open_assetlib->set_visible(asset_library);
  335. const int network_mode = EDITOR_GET("network/connection/network_mode");
  336. if (network_mode == EditorSettings::NETWORK_OFFLINE) {
  337. empty_list_open_assetlib->set_text(TTR("Go Online and Open Asset Library"));
  338. empty_list_online_warning->set_visible(true);
  339. } else {
  340. empty_list_open_assetlib->set_text(TTR("Open Asset Library"));
  341. empty_list_online_warning->set_visible(false);
  342. }
  343. empty_list_placeholder->show();
  344. }
  345. void ProjectManager::_scan_projects() {
  346. scan_dir->popup_file_dialog();
  347. }
  348. void ProjectManager::_run_project() {
  349. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  350. if (selected_list.size() < 1) {
  351. return;
  352. }
  353. if (selected_list.size() > 1) {
  354. multi_run_ask->set_text(vformat(TTR("Are you sure to run %d projects at once?"), selected_list.size()));
  355. multi_run_ask->popup_centered();
  356. } else {
  357. _run_project_confirm();
  358. }
  359. }
  360. void ProjectManager::_run_project_confirm() {
  361. Vector<ProjectList::Item> selected_list = project_list->get_selected_projects();
  362. for (int i = 0; i < selected_list.size(); ++i) {
  363. const String &selected_main = selected_list[i].main_scene;
  364. if (selected_main.is_empty()) {
  365. _show_error(TTR("Can't run project: Project has no main scene defined.\nPlease edit the project and set the main scene in the Project Settings under the \"Application\" category."));
  366. continue;
  367. }
  368. const String &path = selected_list[i].path;
  369. // `.substr(6)` on `ProjectSettings::get_singleton()->get_imported_files_path()` strips away the leading "res://".
  370. if (!DirAccess::exists(path.path_join(ProjectSettings::get_singleton()->get_imported_files_path().substr(6)))) {
  371. _show_error(TTR("Can't run project: Assets need to be imported first.\nPlease edit the project to trigger the initial import."));
  372. continue;
  373. }
  374. print_line("Running project: " + path);
  375. List<String> args;
  376. for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT)) {
  377. args.push_back(a);
  378. }
  379. args.push_back("--path");
  380. args.push_back(path);
  381. Error err = OS::get_singleton()->create_instance(args);
  382. ERR_FAIL_COND(err);
  383. }
  384. }
  385. void ProjectManager::_open_selected_projects() {
  386. // Show loading text to tell the user that the project manager is busy loading.
  387. // This is especially important for the Web project manager.
  388. loading_label->show();
  389. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  390. for (const String &path : selected_list) {
  391. String conf = path.path_join("project.godot");
  392. if (!FileAccess::exists(conf)) {
  393. loading_label->hide();
  394. _show_error(vformat(TTR("Can't open project at '%s'.\nProject file doesn't exist or is inaccessible."), path));
  395. return;
  396. }
  397. print_line("Editing project: " + path);
  398. List<String> args;
  399. for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) {
  400. args.push_back(a);
  401. }
  402. args.push_back("--path");
  403. args.push_back(path);
  404. args.push_back("--editor");
  405. Error err = OS::get_singleton()->create_instance(args);
  406. if (err != OK) {
  407. loading_label->hide();
  408. _show_error(vformat(TTR("Can't open project at '%s'.\nFailed to start the editor."), path));
  409. ERR_PRINT(vformat("Failed to start an editor instance for the project at '%s', error code %d.", path, err));
  410. return;
  411. }
  412. }
  413. project_list->project_opening_initiated = true;
  414. _dim_window();
  415. get_tree()->quit();
  416. }
  417. void ProjectManager::_open_selected_projects_ask() {
  418. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  419. if (selected_list.size() < 1) {
  420. return;
  421. }
  422. const Size2i popup_min_size = Size2i(600.0 * EDSCALE, 0);
  423. if (selected_list.size() > 1) {
  424. multi_open_ask->set_text(vformat(TTR("You requested to open %d projects in parallel. Do you confirm?\nNote that usual checks for engine version compatibility will be bypassed."), selected_list.size()));
  425. multi_open_ask->popup_centered(popup_min_size);
  426. return;
  427. }
  428. ProjectList::Item project = project_list->get_selected_projects()[0];
  429. if (project.missing) {
  430. return;
  431. }
  432. // Update the project settings or don't open.
  433. const int config_version = project.version;
  434. PackedStringArray unsupported_features = project.unsupported_features;
  435. Label *ask_update_label = ask_update_settings->get_label();
  436. ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); // Reset in case of previous center align.
  437. full_convert_button->hide();
  438. ask_update_settings->get_ok_button()->set_text("OK");
  439. // Check if the config_version property was empty or 0.
  440. if (config_version == 0) {
  441. ask_update_settings->set_text(vformat(TTR("The selected project \"%s\" does not specify its supported Godot version in its configuration file (\"project.godot\").\n\nProject path: %s\n\nIf you proceed with opening it, it will be converted to Godot's current configuration file format.\n\nWarning: You won't be able to open the project with previous versions of the engine anymore."), project.project_name, project.path));
  442. ask_update_settings->popup_centered(popup_min_size);
  443. return;
  444. }
  445. // Check if we need to convert project settings from an earlier engine version.
  446. if (config_version < ProjectSettings::CONFIG_VERSION) {
  447. if (config_version == GODOT4_CONFIG_VERSION - 1 && ProjectSettings::CONFIG_VERSION == GODOT4_CONFIG_VERSION) { // Conversion from Godot 3 to 4.
  448. full_convert_button->show();
  449. ask_update_settings->set_text(vformat(TTR("The selected project \"%s\" was generated by Godot 3.x, and needs to be converted for Godot 4.x.\n\nProject path: %s\n\nYou have three options:\n- Convert only the configuration file (\"project.godot\"). Use this to open the project without attempting to convert its scenes, resources and scripts.\n- Convert the entire project including its scenes, resources and scripts (recommended if you are upgrading).\n- Do nothing and go back.\n\nWarning: If you select a conversion option, you won't be able to open the project with previous versions of the engine anymore."), project.project_name, project.path));
  450. ask_update_settings->get_ok_button()->set_text(TTR("Convert project.godot Only"));
  451. } else {
  452. ask_update_settings->set_text(vformat(TTR("The selected project \"%s\" was generated by an older engine version, and needs to be converted for this version.\n\nProject path: %s\n\nDo you want to convert it?\n\nWarning: You won't be able to open the project with previous versions of the engine anymore."), project.project_name, project.path));
  453. ask_update_settings->get_ok_button()->set_text(TTR("Convert project.godot"));
  454. }
  455. ask_update_settings->popup_centered(popup_min_size);
  456. ask_update_settings->get_cancel_button()->grab_focus(); // To prevent accidents.
  457. return;
  458. }
  459. // Check if the file was generated by a newer, incompatible engine version.
  460. if (config_version > ProjectSettings::CONFIG_VERSION) {
  461. _show_error(vformat(TTR("Can't open project \"%s\" at the following path:\n\n%s\n\nThe project settings were created by a newer engine version, whose settings are not compatible with this version."), project.project_name, project.path), popup_min_size);
  462. return;
  463. }
  464. // Check if the project is using features not supported by this build of Godot.
  465. if (!unsupported_features.is_empty()) {
  466. String warning_message = "";
  467. for (int i = 0; i < unsupported_features.size(); i++) {
  468. String feature = unsupported_features[i];
  469. if (feature == "Double Precision") {
  470. warning_message += TTR("Warning: This project uses double precision floats, but this version of\nGodot uses single precision floats. Opening this project may cause data loss.\n\n");
  471. unsupported_features.remove_at(i);
  472. i--;
  473. } else if (feature == "C#") {
  474. warning_message += TTR("Warning: This project uses C#, but this build of Godot does not have\nthe Mono module. If you proceed you will not be able to use any C# scripts.\n\n");
  475. unsupported_features.remove_at(i);
  476. i--;
  477. } else if (ProjectList::project_feature_looks_like_version(feature)) {
  478. warning_message += vformat(TTR("Warning: This project was last edited in Godot %s. Opening will change it to Godot %s.\n\n"), Variant(feature), Variant(VERSION_BRANCH));
  479. unsupported_features.remove_at(i);
  480. i--;
  481. }
  482. }
  483. if (!unsupported_features.is_empty()) {
  484. String unsupported_features_str = String(", ").join(unsupported_features);
  485. warning_message += vformat(TTR("Warning: This project uses the following features not supported by this build of Godot:\n\n%s\n\n"), unsupported_features_str);
  486. }
  487. warning_message += TTR("Open anyway? Project will be modified.");
  488. ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  489. ask_update_settings->set_text(warning_message);
  490. ask_update_settings->popup_centered(popup_min_size);
  491. return;
  492. }
  493. // Open if the project is up-to-date.
  494. _open_selected_projects();
  495. }
  496. void ProjectManager::_install_project(const String &p_zip_path, const String &p_title) {
  497. project_dialog->set_mode(ProjectDialog::MODE_INSTALL);
  498. project_dialog->set_zip_path(p_zip_path);
  499. project_dialog->set_zip_title(p_title);
  500. project_dialog->show_dialog();
  501. }
  502. void ProjectManager::_import_project() {
  503. project_dialog->set_mode(ProjectDialog::MODE_IMPORT);
  504. project_dialog->ask_for_path_and_show();
  505. }
  506. void ProjectManager::_new_project() {
  507. project_dialog->set_mode(ProjectDialog::MODE_NEW);
  508. project_dialog->show_dialog();
  509. }
  510. void ProjectManager::_rename_project() {
  511. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  512. if (selected_list.size() == 0) {
  513. return;
  514. }
  515. for (const String &E : selected_list) {
  516. project_dialog->set_project_path(E);
  517. project_dialog->set_mode(ProjectDialog::MODE_RENAME);
  518. project_dialog->show_dialog();
  519. }
  520. }
  521. void ProjectManager::_erase_project() {
  522. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  523. if (selected_list.size() == 0) {
  524. return;
  525. }
  526. String confirm_message;
  527. if (selected_list.size() >= 2) {
  528. confirm_message = vformat(TTR("Remove %d projects from the list?"), selected_list.size());
  529. } else {
  530. confirm_message = TTR("Remove this project from the list?");
  531. }
  532. erase_ask_label->set_text(confirm_message);
  533. //delete_project_contents->set_pressed(false);
  534. erase_ask->popup_centered();
  535. }
  536. void ProjectManager::_erase_missing_projects() {
  537. erase_missing_ask->set_text(TTR("Remove all missing projects from the list?\nThe project folders' contents won't be modified."));
  538. erase_missing_ask->popup_centered();
  539. }
  540. void ProjectManager::_erase_project_confirm() {
  541. project_list->erase_selected_projects(false);
  542. _update_project_buttons();
  543. _update_list_placeholder();
  544. }
  545. void ProjectManager::_erase_missing_projects_confirm() {
  546. project_list->erase_missing_projects();
  547. _update_project_buttons();
  548. _update_list_placeholder();
  549. }
  550. void ProjectManager::_update_project_buttons() {
  551. Vector<ProjectList::Item> selected_projects = project_list->get_selected_projects();
  552. bool empty_selection = selected_projects.is_empty();
  553. bool is_missing_project_selected = false;
  554. for (int i = 0; i < selected_projects.size(); ++i) {
  555. if (selected_projects[i].missing) {
  556. is_missing_project_selected = true;
  557. break;
  558. }
  559. }
  560. erase_btn->set_disabled(empty_selection);
  561. open_btn->set_disabled(empty_selection || is_missing_project_selected);
  562. rename_btn->set_disabled(empty_selection || is_missing_project_selected);
  563. manage_tags_btn->set_disabled(empty_selection || is_missing_project_selected || selected_projects.size() > 1);
  564. run_btn->set_disabled(empty_selection || is_missing_project_selected);
  565. erase_missing_btn->set_disabled(!project_list->is_any_project_missing());
  566. }
  567. void ProjectManager::_on_projects_updated() {
  568. Vector<ProjectList::Item> selected_projects = project_list->get_selected_projects();
  569. int index = 0;
  570. for (int i = 0; i < selected_projects.size(); ++i) {
  571. index = project_list->refresh_project(selected_projects[i].path);
  572. }
  573. if (index != -1) {
  574. project_list->ensure_project_visible(index);
  575. }
  576. project_list->update_dock_menu();
  577. }
  578. void ProjectManager::_on_project_created(const String &dir) {
  579. project_list->add_project(dir, false);
  580. project_list->save_config();
  581. search_box->clear();
  582. int i = project_list->refresh_project(dir);
  583. project_list->select_project(i);
  584. project_list->ensure_project_visible(i);
  585. _open_selected_projects_ask();
  586. project_list->update_dock_menu();
  587. }
  588. void ProjectManager::_on_order_option_changed(int p_idx) {
  589. if (is_inside_tree()) {
  590. project_list->set_order_option(p_idx);
  591. }
  592. }
  593. void ProjectManager::_on_search_term_changed(const String &p_term) {
  594. project_list->set_search_term(p_term);
  595. project_list->sort_projects();
  596. // Select the first visible project in the list.
  597. // This makes it possible to open a project without ever touching the mouse,
  598. // as the search field is automatically focused on startup.
  599. project_list->select_first_visible_project();
  600. _update_project_buttons();
  601. }
  602. void ProjectManager::_on_search_term_submitted(const String &p_text) {
  603. if (current_main_view != MAIN_VIEW_PROJECTS) {
  604. return;
  605. }
  606. _open_selected_projects_ask();
  607. }
  608. LineEdit *ProjectManager::get_search_box() {
  609. return search_box;
  610. }
  611. // Project tag management.
  612. void ProjectManager::_manage_project_tags() {
  613. for (int i = 0; i < project_tags->get_child_count(); i++) {
  614. project_tags->get_child(i)->queue_free();
  615. }
  616. const ProjectList::Item item = project_list->get_selected_projects()[0];
  617. current_project_tags = item.tags;
  618. for (const String &tag : current_project_tags) {
  619. ProjectTag *tag_control = memnew(ProjectTag(tag, true));
  620. project_tags->add_child(tag_control);
  621. tag_control->connect_button_to(callable_mp(this, &ProjectManager::_delete_project_tag).bind(tag));
  622. }
  623. tag_edit_error->hide();
  624. tag_manage_dialog->popup_centered(Vector2i(500, 0) * EDSCALE);
  625. }
  626. void ProjectManager::_add_project_tag(const String &p_tag) {
  627. if (current_project_tags.has(p_tag)) {
  628. return;
  629. }
  630. current_project_tags.append(p_tag);
  631. ProjectTag *tag_control = memnew(ProjectTag(p_tag, true));
  632. project_tags->add_child(tag_control);
  633. tag_control->connect_button_to(callable_mp(this, &ProjectManager::_delete_project_tag).bind(p_tag));
  634. }
  635. void ProjectManager::_delete_project_tag(const String &p_tag) {
  636. current_project_tags.erase(p_tag);
  637. for (int i = 0; i < project_tags->get_child_count(); i++) {
  638. ProjectTag *tag_control = Object::cast_to<ProjectTag>(project_tags->get_child(i));
  639. if (tag_control && tag_control->get_tag() == p_tag) {
  640. memdelete(tag_control);
  641. break;
  642. }
  643. }
  644. }
  645. void ProjectManager::_apply_project_tags() {
  646. PackedStringArray tags;
  647. for (int i = 0; i < project_tags->get_child_count(); i++) {
  648. ProjectTag *tag_control = Object::cast_to<ProjectTag>(project_tags->get_child(i));
  649. if (tag_control) {
  650. tags.append(tag_control->get_tag());
  651. }
  652. }
  653. ConfigFile cfg;
  654. const String project_godot = project_list->get_selected_projects()[0].path.path_join("project.godot");
  655. Error err = cfg.load(project_godot);
  656. if (err != OK) {
  657. tag_edit_error->set_text(vformat(TTR("Couldn't load project at '%s' (error %d). It may be missing or corrupted."), project_godot, err));
  658. tag_edit_error->show();
  659. callable_mp((Window *)tag_manage_dialog, &Window::show).call_deferred(); // Make sure the dialog does not disappear.
  660. return;
  661. } else {
  662. tags.sort();
  663. cfg.set_value("application", "config/tags", tags);
  664. err = cfg.save(project_godot);
  665. if (err != OK) {
  666. tag_edit_error->set_text(vformat(TTR("Couldn't save project at '%s' (error %d)."), project_godot, err));
  667. tag_edit_error->show();
  668. callable_mp((Window *)tag_manage_dialog, &Window::show).call_deferred();
  669. return;
  670. }
  671. }
  672. _on_projects_updated();
  673. }
  674. void ProjectManager::_set_new_tag_name(const String p_name) {
  675. create_tag_dialog->get_ok_button()->set_disabled(true);
  676. if (p_name.is_empty()) {
  677. tag_error->set_text(TTR("Tag name can't be empty."));
  678. return;
  679. }
  680. if (p_name.contains(" ")) {
  681. tag_error->set_text(TTR("Tag name can't contain spaces."));
  682. return;
  683. }
  684. for (const String &c : forbidden_tag_characters) {
  685. if (p_name.contains(c)) {
  686. tag_error->set_text(vformat(TTR("These characters are not allowed in tags: %s."), String(" ").join(forbidden_tag_characters)));
  687. return;
  688. }
  689. }
  690. if (p_name.to_lower() != p_name) {
  691. tag_error->set_text(TTR("Tag name must be lowercase."));
  692. return;
  693. }
  694. tag_error->set_text("");
  695. create_tag_dialog->get_ok_button()->set_disabled(false);
  696. }
  697. void ProjectManager::_create_new_tag() {
  698. if (!tag_error->get_text().is_empty()) {
  699. return;
  700. }
  701. create_tag_dialog->hide(); // When using text_submitted, need to hide manually.
  702. add_new_tag(new_tag_name->get_text());
  703. _add_project_tag(new_tag_name->get_text());
  704. }
  705. void ProjectManager::add_new_tag(const String &p_tag) {
  706. if (!tag_set.has(p_tag)) {
  707. tag_set.insert(p_tag);
  708. ProjectTag *tag_control = memnew(ProjectTag(p_tag));
  709. all_tags->add_child(tag_control);
  710. all_tags->move_child(tag_control, -2);
  711. tag_control->connect_button_to(callable_mp(this, &ProjectManager::_add_project_tag).bind(p_tag));
  712. }
  713. }
  714. // Project converter/migration tool.
  715. void ProjectManager::_full_convert_button_pressed() {
  716. ask_update_settings->hide();
  717. ask_full_convert_dialog->popup_centered(Size2i(600.0 * EDSCALE, 0));
  718. ask_full_convert_dialog->get_cancel_button()->grab_focus();
  719. }
  720. void ProjectManager::_perform_full_project_conversion() {
  721. Vector<ProjectList::Item> selected_list = project_list->get_selected_projects();
  722. if (selected_list.is_empty()) {
  723. return;
  724. }
  725. const String &path = selected_list[0].path;
  726. print_line("Converting project: " + path);
  727. List<String> args;
  728. args.push_back("--path");
  729. args.push_back(path);
  730. args.push_back("--convert-3to4");
  731. args.push_back("--rendering-driver");
  732. args.push_back(Main::get_rendering_driver_name());
  733. Error err = OS::get_singleton()->create_instance(args);
  734. ERR_FAIL_COND(err);
  735. project_list->set_project_version(path, GODOT4_CONFIG_VERSION);
  736. }
  737. // Input and I/O.
  738. void ProjectManager::shortcut_input(const Ref<InputEvent> &p_ev) {
  739. ERR_FAIL_COND(p_ev.is_null());
  740. Ref<InputEventKey> k = p_ev;
  741. if (k.is_valid()) {
  742. if (!k->is_pressed()) {
  743. return;
  744. }
  745. // Pressing Command + Q quits the Project Manager
  746. // This is handled by the platform implementation on macOS,
  747. // so only define the shortcut on other platforms
  748. #ifndef MACOS_ENABLED
  749. if (k->get_keycode_with_modifiers() == (KeyModifierMask::META | Key::Q)) {
  750. _dim_window();
  751. get_tree()->quit();
  752. }
  753. #endif
  754. if (current_main_view != MAIN_VIEW_PROJECTS) {
  755. return;
  756. }
  757. bool keycode_handled = true;
  758. switch (k->get_keycode()) {
  759. case Key::ENTER: {
  760. _open_selected_projects_ask();
  761. } break;
  762. case Key::HOME: {
  763. if (project_list->get_project_count() > 0) {
  764. project_list->select_project(0);
  765. _update_project_buttons();
  766. }
  767. } break;
  768. case Key::END: {
  769. if (project_list->get_project_count() > 0) {
  770. project_list->select_project(project_list->get_project_count() - 1);
  771. _update_project_buttons();
  772. }
  773. } break;
  774. case Key::UP: {
  775. if (k->is_shift_pressed()) {
  776. break;
  777. }
  778. int index = project_list->get_single_selected_index();
  779. if (index > 0) {
  780. project_list->select_project(index - 1);
  781. project_list->ensure_project_visible(index - 1);
  782. _update_project_buttons();
  783. }
  784. break;
  785. }
  786. case Key::DOWN: {
  787. if (k->is_shift_pressed()) {
  788. break;
  789. }
  790. int index = project_list->get_single_selected_index();
  791. if (index + 1 < project_list->get_project_count()) {
  792. project_list->select_project(index + 1);
  793. project_list->ensure_project_visible(index + 1);
  794. _update_project_buttons();
  795. }
  796. } break;
  797. case Key::F: {
  798. if (k->is_command_or_control_pressed()) {
  799. search_box->grab_focus();
  800. } else {
  801. keycode_handled = false;
  802. }
  803. } break;
  804. default: {
  805. keycode_handled = false;
  806. } break;
  807. }
  808. if (keycode_handled) {
  809. accept_event();
  810. }
  811. }
  812. }
  813. void ProjectManager::_files_dropped(PackedStringArray p_files) {
  814. // TODO: Support installing multiple ZIPs at the same time?
  815. if (p_files.size() == 1 && p_files[0].ends_with(".zip")) {
  816. const String &file = p_files[0];
  817. _install_project(file, file.get_file().get_basename().capitalize());
  818. return;
  819. }
  820. HashSet<String> folders_set;
  821. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  822. for (int i = 0; i < p_files.size(); i++) {
  823. const String &file = p_files[i];
  824. folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir());
  825. }
  826. ERR_FAIL_COND(folders_set.is_empty()); // This can't really happen, we consume every dropped file path above.
  827. PackedStringArray folders;
  828. for (const String &E : folders_set) {
  829. folders.push_back(E);
  830. }
  831. project_list->find_projects_multiple(folders);
  832. }
  833. // Object methods.
  834. ProjectManager::ProjectManager() {
  835. singleton = this;
  836. // Turn off some servers we aren't going to be using in the Project Manager.
  837. NavigationServer3D::get_singleton()->set_active(false);
  838. PhysicsServer3D::get_singleton()->set_active(false);
  839. PhysicsServer2D::get_singleton()->set_active(false);
  840. // Initialize settings.
  841. {
  842. if (!EditorSettings::get_singleton()) {
  843. EditorSettings::create();
  844. }
  845. EditorSettings::get_singleton()->set_optimize_save(false); // Just write settings as they come.
  846. int display_scale = EDITOR_GET("interface/editor/display_scale");
  847. switch (display_scale) {
  848. case 0:
  849. // Try applying a suitable display scale automatically.
  850. EditorScale::set_scale(EditorSettings::get_singleton()->get_auto_display_scale());
  851. break;
  852. case 1:
  853. EditorScale::set_scale(0.75);
  854. break;
  855. case 2:
  856. EditorScale::set_scale(1.0);
  857. break;
  858. case 3:
  859. EditorScale::set_scale(1.25);
  860. break;
  861. case 4:
  862. EditorScale::set_scale(1.5);
  863. break;
  864. case 5:
  865. EditorScale::set_scale(1.75);
  866. break;
  867. case 6:
  868. EditorScale::set_scale(2.0);
  869. break;
  870. default:
  871. EditorScale::set_scale(EDITOR_GET("interface/editor/custom_display_scale"));
  872. break;
  873. }
  874. EditorFileDialog::get_icon_func = &ProjectManager::_file_dialog_get_icon;
  875. EditorFileDialog::get_thumbnail_func = &ProjectManager::_file_dialog_get_thumbnail;
  876. EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));
  877. EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int());
  878. int swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
  879. if (swap_cancel_ok != 0) { // 0 is auto, set in register_scene based on DisplayServer.
  880. // Swap on means OK first.
  881. AcceptDialog::set_swap_cancel_ok(swap_cancel_ok == 2);
  882. }
  883. OS::get_singleton()->set_low_processor_usage_mode(true);
  884. }
  885. // TRANSLATORS: This refers to the application where users manage their Godot projects.
  886. DisplayServer::get_singleton()->window_set_title(VERSION_NAME + String(" - ") + TTR("Project Manager", "Application"));
  887. SceneTree::get_singleton()->get_root()->connect("files_dropped", callable_mp(this, &ProjectManager::_files_dropped));
  888. // Initialize UI.
  889. {
  890. int pm_root_dir = EDITOR_GET("interface/editor/ui_layout_direction");
  891. Control::set_root_layout_direction(pm_root_dir);
  892. Window::set_root_layout_direction(pm_root_dir);
  893. EditorThemeManager::initialize();
  894. theme = EditorThemeManager::generate_theme();
  895. DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
  896. set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  897. _build_icon_type_cache(theme);
  898. }
  899. // Project manager layout.
  900. background_panel = memnew(Panel);
  901. add_child(background_panel);
  902. background_panel->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  903. root_container = memnew(MarginContainer);
  904. add_child(root_container);
  905. root_container->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  906. main_vbox = memnew(VBoxContainer);
  907. root_container->add_child(main_vbox);
  908. // Title bar.
  909. {
  910. title_bar = memnew(HBoxContainer);
  911. main_vbox->add_child(title_bar);
  912. HBoxContainer *left_hbox = memnew(HBoxContainer);
  913. left_hbox->set_alignment(BoxContainer::ALIGNMENT_BEGIN);
  914. left_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  915. left_hbox->set_stretch_ratio(1.0);
  916. title_bar->add_child(left_hbox);
  917. title_bar_logo = memnew(Button);
  918. title_bar_logo->set_flat(true);
  919. left_hbox->add_child(title_bar_logo);
  920. title_bar_logo->connect("pressed", callable_mp(this, &ProjectManager::_show_about));
  921. main_view_toggles = memnew(HBoxContainer);
  922. main_view_toggles->set_alignment(BoxContainer::ALIGNMENT_CENTER);
  923. main_view_toggles->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  924. main_view_toggles->set_stretch_ratio(2.0);
  925. title_bar->add_child(main_view_toggles);
  926. main_view_toggles_group.instantiate();
  927. HBoxContainer *right_hbox = memnew(HBoxContainer);
  928. right_hbox->set_alignment(BoxContainer::ALIGNMENT_END);
  929. right_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  930. right_hbox->set_stretch_ratio(1.0);
  931. title_bar->add_child(right_hbox);
  932. quick_settings_button = memnew(Button);
  933. quick_settings_button->set_flat(true);
  934. quick_settings_button->set_text(TTR("Settings"));
  935. right_hbox->add_child(quick_settings_button);
  936. quick_settings_button->connect("pressed", callable_mp(this, &ProjectManager::_show_quick_settings));
  937. }
  938. main_view_container = memnew(PanelContainer);
  939. main_view_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  940. main_vbox->add_child(main_view_container);
  941. // Project list view.
  942. {
  943. local_projects_vb = memnew(VBoxContainer);
  944. local_projects_vb->set_name("LocalProjectsTab");
  945. _add_main_view(MAIN_VIEW_PROJECTS, TTR("Projects"), Ref<Texture2D>(), local_projects_vb);
  946. // Project list's top bar.
  947. {
  948. HBoxContainer *hb = memnew(HBoxContainer);
  949. hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  950. local_projects_vb->add_child(hb);
  951. create_btn = memnew(Button);
  952. create_btn->set_text(TTR("Create"));
  953. create_btn->set_shortcut(ED_SHORTCUT("project_manager/new_project", TTR("New Project"), KeyModifierMask::CMD_OR_CTRL | Key::N));
  954. create_btn->connect("pressed", callable_mp(this, &ProjectManager::_new_project));
  955. hb->add_child(create_btn);
  956. import_btn = memnew(Button);
  957. import_btn->set_text(TTR("Import"));
  958. import_btn->set_shortcut(ED_SHORTCUT("project_manager/import_project", TTR("Import Project"), KeyModifierMask::CMD_OR_CTRL | Key::I));
  959. import_btn->connect("pressed", callable_mp(this, &ProjectManager::_import_project));
  960. hb->add_child(import_btn);
  961. scan_btn = memnew(Button);
  962. scan_btn->set_text(TTR("Scan"));
  963. scan_btn->set_shortcut(ED_SHORTCUT("project_manager/scan_projects", TTR("Scan Projects"), KeyModifierMask::CMD_OR_CTRL | Key::S));
  964. scan_btn->connect("pressed", callable_mp(this, &ProjectManager::_scan_projects));
  965. hb->add_child(scan_btn);
  966. loading_label = memnew(Label(TTR("Loading, please wait...")));
  967. loading_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  968. loading_label->hide();
  969. hb->add_child(loading_label);
  970. search_box = memnew(LineEdit);
  971. search_box->set_placeholder(TTR("Filter Projects"));
  972. search_box->set_tooltip_text(TTR("This field filters projects by name and last path component.\nTo filter projects by name and full path, the query must contain at least one `/` character."));
  973. search_box->set_clear_button_enabled(true);
  974. search_box->connect("text_changed", callable_mp(this, &ProjectManager::_on_search_term_changed));
  975. search_box->connect("text_submitted", callable_mp(this, &ProjectManager::_on_search_term_submitted));
  976. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  977. hb->add_child(search_box);
  978. Label *sort_label = memnew(Label);
  979. sort_label->set_text(TTR("Sort:"));
  980. hb->add_child(sort_label);
  981. filter_option = memnew(OptionButton);
  982. filter_option->set_clip_text(true);
  983. filter_option->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  984. filter_option->set_stretch_ratio(0.3);
  985. filter_option->connect("item_selected", callable_mp(this, &ProjectManager::_on_order_option_changed));
  986. hb->add_child(filter_option);
  987. Vector<String> sort_filter_titles;
  988. sort_filter_titles.push_back(TTR("Last Edited"));
  989. sort_filter_titles.push_back(TTR("Name"));
  990. sort_filter_titles.push_back(TTR("Path"));
  991. sort_filter_titles.push_back(TTR("Tags"));
  992. for (int i = 0; i < sort_filter_titles.size(); i++) {
  993. filter_option->add_item(sort_filter_titles[i]);
  994. }
  995. }
  996. // Project list and its sidebar.
  997. {
  998. HBoxContainer *project_list_hbox = memnew(HBoxContainer);
  999. local_projects_vb->add_child(project_list_hbox);
  1000. project_list_hbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1001. project_list_panel = memnew(PanelContainer);
  1002. project_list_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1003. project_list_hbox->add_child(project_list_panel);
  1004. project_list = memnew(ProjectList);
  1005. project_list->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  1006. project_list_panel->add_child(project_list);
  1007. project_list->connect(ProjectList::SIGNAL_LIST_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons));
  1008. project_list->connect(ProjectList::SIGNAL_LIST_CHANGED, callable_mp(this, &ProjectManager::_update_list_placeholder));
  1009. project_list->connect(ProjectList::SIGNAL_SELECTION_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons));
  1010. project_list->connect(ProjectList::SIGNAL_PROJECT_ASK_OPEN, callable_mp(this, &ProjectManager::_open_selected_projects_ask));
  1011. // Empty project list placeholder.
  1012. {
  1013. empty_list_placeholder = memnew(VBoxContainer);
  1014. empty_list_placeholder->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1015. empty_list_placeholder->add_theme_constant_override("separation", 16 * EDSCALE);
  1016. empty_list_placeholder->hide();
  1017. project_list_panel->add_child(empty_list_placeholder);
  1018. RichTextLabel *empty_list_message = memnew(RichTextLabel);
  1019. empty_list_message->set_use_bbcode(true);
  1020. empty_list_message->set_fit_content(true);
  1021. empty_list_message->set_h_size_flags(SIZE_EXPAND_FILL);
  1022. empty_list_message->add_theme_style_override("normal", memnew(StyleBoxEmpty));
  1023. const String line1 = TTR("You don't have any projects yet.");
  1024. const String line2 = TTR("Get started by creating a new one,\nimporting one that exists, or by downloading a project template from the Asset Library!");
  1025. empty_list_message->set_text(vformat("[center][b]%s[/b] %s[/center]", line1, line2));
  1026. empty_list_placeholder->add_child(empty_list_message);
  1027. HBoxContainer *empty_list_actions = memnew(HBoxContainer);
  1028. empty_list_actions->set_alignment(BoxContainer::ALIGNMENT_CENTER);
  1029. empty_list_placeholder->add_child(empty_list_actions);
  1030. empty_list_create_project = memnew(Button);
  1031. empty_list_create_project->set_text(TTR("Create New Project"));
  1032. empty_list_create_project->set_theme_type_variation("PanelBackgroundButton");
  1033. empty_list_actions->add_child(empty_list_create_project);
  1034. empty_list_create_project->connect("pressed", callable_mp(this, &ProjectManager::_new_project));
  1035. empty_list_import_project = memnew(Button);
  1036. empty_list_import_project->set_text(TTR("Import Existing Project"));
  1037. empty_list_import_project->set_theme_type_variation("PanelBackgroundButton");
  1038. empty_list_actions->add_child(empty_list_import_project);
  1039. empty_list_import_project->connect("pressed", callable_mp(this, &ProjectManager::_import_project));
  1040. empty_list_open_assetlib = memnew(Button);
  1041. empty_list_open_assetlib->set_text(TTR("Open Asset Library"));
  1042. empty_list_open_assetlib->set_theme_type_variation("PanelBackgroundButton");
  1043. empty_list_actions->add_child(empty_list_open_assetlib);
  1044. empty_list_open_assetlib->connect("pressed", callable_mp(this, &ProjectManager::_open_asset_library_confirmed));
  1045. empty_list_online_warning = memnew(Label);
  1046. empty_list_online_warning->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
  1047. empty_list_online_warning->set_custom_minimum_size(Size2(220, 0) * EDSCALE);
  1048. empty_list_online_warning->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1049. empty_list_online_warning->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1050. empty_list_online_warning->set_text(TTR("Note: The Asset Library requires an online connection and involves sending data over the internet."));
  1051. empty_list_placeholder->add_child(empty_list_online_warning);
  1052. }
  1053. // The side bar with the edit, run, rename, etc. buttons.
  1054. VBoxContainer *project_list_sidebar = memnew(VBoxContainer);
  1055. project_list_sidebar->set_custom_minimum_size(Size2(120, 120));
  1056. project_list_hbox->add_child(project_list_sidebar);
  1057. project_list_sidebar->add_child(memnew(HSeparator));
  1058. open_btn = memnew(Button);
  1059. open_btn->set_text(TTR("Edit"));
  1060. open_btn->set_shortcut(ED_SHORTCUT("project_manager/edit_project", TTR("Edit Project"), KeyModifierMask::CMD_OR_CTRL | Key::E));
  1061. open_btn->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects_ask));
  1062. project_list_sidebar->add_child(open_btn);
  1063. run_btn = memnew(Button);
  1064. run_btn->set_text(TTR("Run"));
  1065. run_btn->set_shortcut(ED_SHORTCUT("project_manager/run_project", TTR("Run Project"), KeyModifierMask::CMD_OR_CTRL | Key::R));
  1066. run_btn->connect("pressed", callable_mp(this, &ProjectManager::_run_project));
  1067. project_list_sidebar->add_child(run_btn);
  1068. rename_btn = memnew(Button);
  1069. rename_btn->set_text(TTR("Rename"));
  1070. // The F2 shortcut isn't overridden with Enter on macOS as Enter is already used to edit a project.
  1071. rename_btn->set_shortcut(ED_SHORTCUT("project_manager/rename_project", TTR("Rename Project"), Key::F2));
  1072. rename_btn->connect("pressed", callable_mp(this, &ProjectManager::_rename_project));
  1073. project_list_sidebar->add_child(rename_btn);
  1074. manage_tags_btn = memnew(Button);
  1075. manage_tags_btn->set_text(TTR("Manage Tags"));
  1076. project_list_sidebar->add_child(manage_tags_btn);
  1077. erase_btn = memnew(Button);
  1078. erase_btn->set_text(TTR("Remove"));
  1079. erase_btn->set_shortcut(ED_SHORTCUT("project_manager/remove_project", TTR("Remove Project"), Key::KEY_DELETE));
  1080. erase_btn->connect("pressed", callable_mp(this, &ProjectManager::_erase_project));
  1081. project_list_sidebar->add_child(erase_btn);
  1082. Control *filler = memnew(Control);
  1083. filler->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1084. project_list_sidebar->add_child(filler);
  1085. erase_missing_btn = memnew(Button);
  1086. erase_missing_btn->set_text(TTR("Remove Missing"));
  1087. erase_missing_btn->connect("pressed", callable_mp(this, &ProjectManager::_erase_missing_projects));
  1088. project_list_sidebar->add_child(erase_missing_btn);
  1089. }
  1090. }
  1091. // Asset library view.
  1092. if (AssetLibraryEditorPlugin::is_available()) {
  1093. asset_library = memnew(EditorAssetLibrary(true));
  1094. asset_library->set_name("AssetLibraryTab");
  1095. _add_main_view(MAIN_VIEW_ASSETLIB, TTR("Asset Library"), Ref<Texture2D>(), asset_library);
  1096. asset_library->connect("install_asset", callable_mp(this, &ProjectManager::_install_project));
  1097. } else {
  1098. VBoxContainer *asset_library_filler = memnew(VBoxContainer);
  1099. asset_library_filler->set_name("AssetLibraryTab");
  1100. Button *asset_library_toggle = _add_main_view(MAIN_VIEW_ASSETLIB, TTR("Asset Library"), Ref<Texture2D>(), asset_library_filler);
  1101. asset_library_toggle->set_disabled(true);
  1102. asset_library_toggle->set_tooltip_text(TTR("Asset Library not available (due to using Web editor, or because SSL support disabled)."));
  1103. }
  1104. // Footer bar.
  1105. {
  1106. HBoxContainer *footer_bar = memnew(HBoxContainer);
  1107. footer_bar->set_alignment(BoxContainer::ALIGNMENT_END);
  1108. main_vbox->add_child(footer_bar);
  1109. version_btn = memnew(LinkButton);
  1110. String hash = String(VERSION_HASH);
  1111. if (hash.length() != 0) {
  1112. hash = " " + vformat("[%s]", hash.left(9));
  1113. }
  1114. version_btn->set_text("v" VERSION_FULL_BUILD + hash);
  1115. // Fade the version label to be less prominent, but still readable.
  1116. version_btn->set_self_modulate(Color(1, 1, 1, 0.6));
  1117. version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
  1118. version_btn->set_tooltip_text(TTR("Click to copy the version information."));
  1119. version_btn->connect("pressed", callable_mp(this, &ProjectManager::_version_button_pressed));
  1120. footer_bar->add_child(version_btn);
  1121. }
  1122. // Dialogs.
  1123. {
  1124. quick_settings_dialog = memnew(QuickSettingsDialog);
  1125. add_child(quick_settings_dialog);
  1126. quick_settings_dialog->connect("restart_required", callable_mp(this, &ProjectManager::_restart_confirmed));
  1127. scan_dir = memnew(EditorFileDialog);
  1128. scan_dir->set_previews_enabled(false);
  1129. scan_dir->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1130. scan_dir->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
  1131. scan_dir->set_title(TTR("Select a Folder to Scan")); // must be after mode or it's overridden
  1132. scan_dir->set_current_dir(EDITOR_GET("filesystem/directories/default_project_path"));
  1133. add_child(scan_dir);
  1134. scan_dir->connect("dir_selected", callable_mp(project_list, &ProjectList::find_projects));
  1135. erase_missing_ask = memnew(ConfirmationDialog);
  1136. erase_missing_ask->set_ok_button_text(TTR("Remove All"));
  1137. erase_missing_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_erase_missing_projects_confirm));
  1138. add_child(erase_missing_ask);
  1139. erase_ask = memnew(ConfirmationDialog);
  1140. erase_ask->set_ok_button_text(TTR("Remove"));
  1141. erase_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_erase_project_confirm));
  1142. add_child(erase_ask);
  1143. VBoxContainer *erase_ask_vb = memnew(VBoxContainer);
  1144. erase_ask->add_child(erase_ask_vb);
  1145. erase_ask_label = memnew(Label);
  1146. erase_ask_vb->add_child(erase_ask_label);
  1147. // Comment out for now until we have a better warning system to
  1148. // ensure users delete their project only.
  1149. //delete_project_contents = memnew(CheckBox);
  1150. //delete_project_contents->set_text(TTR("Also delete project contents (no undo!)"));
  1151. //erase_ask_vb->add_child(delete_project_contents);
  1152. multi_open_ask = memnew(ConfirmationDialog);
  1153. multi_open_ask->set_ok_button_text(TTR("Edit"));
  1154. multi_open_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects));
  1155. add_child(multi_open_ask);
  1156. multi_run_ask = memnew(ConfirmationDialog);
  1157. multi_run_ask->set_ok_button_text(TTR("Run"));
  1158. multi_run_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_run_project_confirm));
  1159. add_child(multi_run_ask);
  1160. ask_update_settings = memnew(ConfirmationDialog);
  1161. ask_update_settings->set_autowrap(true);
  1162. ask_update_settings->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects));
  1163. full_convert_button = ask_update_settings->add_button(TTR("Convert Full Project"), !GLOBAL_GET("gui/common/swap_cancel_ok"));
  1164. full_convert_button->connect("pressed", callable_mp(this, &ProjectManager::_full_convert_button_pressed));
  1165. add_child(ask_update_settings);
  1166. ask_full_convert_dialog = memnew(ConfirmationDialog);
  1167. ask_full_convert_dialog->set_autowrap(true);
  1168. ask_full_convert_dialog->set_text(TTR("This option will perform full project conversion, updating scenes, resources and scripts from Godot 3 to work in Godot 4.\n\nNote that this is a best-effort conversion, i.e. it makes upgrading the project easier, but it will not open out-of-the-box and will still require manual adjustments.\n\nIMPORTANT: Make sure to backup your project before converting, as this operation makes it impossible to open it in older versions of Godot."));
  1169. ask_full_convert_dialog->connect("confirmed", callable_mp(this, &ProjectManager::_perform_full_project_conversion));
  1170. add_child(ask_full_convert_dialog);
  1171. project_dialog = memnew(ProjectDialog);
  1172. project_dialog->connect("projects_updated", callable_mp(this, &ProjectManager::_on_projects_updated));
  1173. project_dialog->connect("project_created", callable_mp(this, &ProjectManager::_on_project_created));
  1174. add_child(project_dialog);
  1175. error_dialog = memnew(AcceptDialog);
  1176. error_dialog->set_title(TTR("Error"));
  1177. add_child(error_dialog);
  1178. about_dialog = memnew(EditorAbout);
  1179. add_child(about_dialog);
  1180. }
  1181. // Tag management.
  1182. {
  1183. tag_manage_dialog = memnew(ConfirmationDialog);
  1184. add_child(tag_manage_dialog);
  1185. tag_manage_dialog->set_title(TTR("Manage Project Tags"));
  1186. tag_manage_dialog->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_apply_project_tags));
  1187. manage_tags_btn->connect("pressed", callable_mp(this, &ProjectManager::_manage_project_tags));
  1188. VBoxContainer *tag_vb = memnew(VBoxContainer);
  1189. tag_manage_dialog->add_child(tag_vb);
  1190. Label *label = memnew(Label(TTR("Project Tags")));
  1191. tag_vb->add_child(label);
  1192. label->set_theme_type_variation("HeaderMedium");
  1193. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1194. label = memnew(Label(TTR("Click tag to remove it from the project.")));
  1195. tag_vb->add_child(label);
  1196. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1197. project_tags = memnew(HFlowContainer);
  1198. tag_vb->add_child(project_tags);
  1199. project_tags->set_custom_minimum_size(Vector2(0, 100) * EDSCALE);
  1200. tag_vb->add_child(memnew(HSeparator));
  1201. label = memnew(Label(TTR("All Tags")));
  1202. tag_vb->add_child(label);
  1203. label->set_theme_type_variation("HeaderMedium");
  1204. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1205. label = memnew(Label(TTR("Click tag to add it to the project.")));
  1206. tag_vb->add_child(label);
  1207. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1208. all_tags = memnew(HFlowContainer);
  1209. tag_vb->add_child(all_tags);
  1210. all_tags->set_custom_minimum_size(Vector2(0, 100) * EDSCALE);
  1211. tag_edit_error = memnew(Label);
  1212. tag_vb->add_child(tag_edit_error);
  1213. tag_edit_error->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1214. create_tag_dialog = memnew(ConfirmationDialog);
  1215. tag_manage_dialog->add_child(create_tag_dialog);
  1216. create_tag_dialog->set_title(TTR("Create New Tag"));
  1217. create_tag_dialog->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_create_new_tag));
  1218. tag_vb = memnew(VBoxContainer);
  1219. create_tag_dialog->add_child(tag_vb);
  1220. Label *info = memnew(Label(TTR("Tags are capitalized automatically when displayed.")));
  1221. tag_vb->add_child(info);
  1222. new_tag_name = memnew(LineEdit);
  1223. tag_vb->add_child(new_tag_name);
  1224. new_tag_name->connect("text_changed", callable_mp(this, &ProjectManager::_set_new_tag_name));
  1225. new_tag_name->connect("text_submitted", callable_mp(this, &ProjectManager::_create_new_tag).unbind(1));
  1226. create_tag_dialog->connect("about_to_popup", callable_mp(new_tag_name, &LineEdit::clear));
  1227. create_tag_dialog->connect("about_to_popup", callable_mp((Control *)new_tag_name, &Control::grab_focus), CONNECT_DEFERRED);
  1228. tag_error = memnew(Label);
  1229. tag_vb->add_child(tag_error);
  1230. create_tag_btn = memnew(Button);
  1231. all_tags->add_child(create_tag_btn);
  1232. create_tag_btn->connect("pressed", callable_mp((Window *)create_tag_dialog, &Window::popup_centered).bind(Vector2i(500, 0) * EDSCALE));
  1233. }
  1234. // Initialize project list.
  1235. {
  1236. Ref<DirAccess> dir_access = DirAccess::create(DirAccess::AccessType::ACCESS_FILESYSTEM);
  1237. String default_project_path = EDITOR_GET("filesystem/directories/default_project_path");
  1238. if (!default_project_path.is_empty() && !dir_access->dir_exists(default_project_path)) {
  1239. Error error = dir_access->make_dir_recursive(default_project_path);
  1240. if (error != OK) {
  1241. ERR_PRINT("Could not create default project directory at: " + default_project_path);
  1242. }
  1243. }
  1244. bool scanned_for_projects = false; // Scanning will update the list automatically.
  1245. String autoscan_path = EDITOR_GET("filesystem/directories/autoscan_project_path");
  1246. if (!autoscan_path.is_empty()) {
  1247. if (dir_access->dir_exists(autoscan_path)) {
  1248. project_list->find_projects(autoscan_path);
  1249. scanned_for_projects = true;
  1250. } else {
  1251. Error error = dir_access->make_dir_recursive(autoscan_path);
  1252. if (error != OK) {
  1253. ERR_PRINT("Could not create project autoscan directory at: " + autoscan_path);
  1254. }
  1255. }
  1256. }
  1257. if (!scanned_for_projects) {
  1258. project_list->update_project_list();
  1259. }
  1260. }
  1261. _update_size_limits();
  1262. }
  1263. ProjectManager::~ProjectManager() {
  1264. singleton = nullptr;
  1265. if (EditorSettings::get_singleton()) {
  1266. EditorSettings::destroy();
  1267. }
  1268. EditorThemeManager::finalize();
  1269. }