project_manager.cpp 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  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/os/keyboard.h"
  36. #include "core/os/os.h"
  37. #include "core/version.h"
  38. #include "editor/asset_library/asset_library_editor_plugin.h"
  39. #include "editor/editor_string_names.h"
  40. #include "editor/gui/editor_about.h"
  41. #include "editor/gui/editor_file_dialog.h"
  42. #include "editor/gui/editor_title_bar.h"
  43. #include "editor/gui/editor_version_button.h"
  44. #include "editor/project_manager/engine_update_label.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/settings/editor_settings.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/flow_container.h"
  55. #include "scene/gui/line_edit.h"
  56. #include "scene/gui/margin_container.h"
  57. #include "scene/gui/option_button.h"
  58. #include "scene/gui/panel_container.h"
  59. #include "scene/gui/rich_text_label.h"
  60. #include "scene/gui/separator.h"
  61. #include "scene/main/window.h"
  62. #include "scene/theme/theme_db.h"
  63. #include "servers/display_server.h"
  64. #include "servers/navigation_server_3d.h"
  65. #ifndef PHYSICS_3D_DISABLED
  66. #include "servers/physics_server_3d.h"
  67. #endif // PHYSICS_3D_DISABLED
  68. #ifndef PHYSICS_2D_DISABLED
  69. #include "servers/physics_server_2d.h"
  70. #endif // PHYSICS_2D_DISABLED
  71. constexpr int GODOT4_CONFIG_VERSION = 5;
  72. ProjectManager *ProjectManager::singleton = nullptr;
  73. // Notifications.
  74. void ProjectManager::_notification(int p_what) {
  75. switch (p_what) {
  76. case NOTIFICATION_ENTER_TREE: {
  77. Engine::get_singleton()->set_editor_hint(false);
  78. Window *main_window = get_window();
  79. if (main_window) {
  80. // Handle macOS fullscreen and extend-to-title changes.
  81. main_window->connect("titlebar_changed", callable_mp(this, &ProjectManager::_titlebar_resized));
  82. }
  83. // Theme has already been created in the constructor, so we can skip that step.
  84. _update_theme(true);
  85. } break;
  86. case NOTIFICATION_READY: {
  87. DisplayServer::get_singleton()->screen_set_keep_on(EDITOR_GET("interface/editor/keep_screen_on"));
  88. const int default_sorting = (int)EDITOR_GET("project_manager/sorting_order");
  89. filter_option->select(default_sorting);
  90. project_list->set_order_option(default_sorting);
  91. _select_main_view(MAIN_VIEW_PROJECTS);
  92. _update_list_placeholder();
  93. _titlebar_resized();
  94. } break;
  95. case NOTIFICATION_TRANSLATION_CHANGED: {
  96. // TRANSLATORS: This refers to the application where users manage their Godot projects.
  97. SceneTree::get_singleton()->get_root()->set_title(GODOT_VERSION_NAME + String(" - ") + TTR("Project Manager", "Application"));
  98. const String line1 = TTR("You don't have any projects yet.");
  99. 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!");
  100. empty_list_message->set_text(vformat("[center][b]%s[/b] %s[/center]", line1, line2));
  101. _titlebar_resized();
  102. } break;
  103. case NOTIFICATION_VISIBILITY_CHANGED: {
  104. set_process_shortcut_input(is_visible_in_tree());
  105. } break;
  106. case NOTIFICATION_WM_CLOSE_REQUEST: {
  107. _dim_window();
  108. } break;
  109. case NOTIFICATION_WM_ABOUT: {
  110. _show_about();
  111. } break;
  112. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  113. if (EditorThemeManager::is_generated_theme_outdated()) {
  114. _update_theme();
  115. }
  116. _update_list_placeholder();
  117. } break;
  118. }
  119. }
  120. // Utility data.
  121. Ref<Texture2D> ProjectManager::_file_dialog_get_icon(const String &p_path) {
  122. if (p_path.get_extension().to_lower() == "godot") {
  123. return singleton->icon_type_cache["GodotMonochrome"];
  124. }
  125. return singleton->icon_type_cache["Object"];
  126. }
  127. Ref<Texture2D> ProjectManager::_file_dialog_get_thumbnail(const String &p_path) {
  128. if (p_path.get_extension().to_lower() == "godot") {
  129. return singleton->icon_type_cache["GodotFile"];
  130. }
  131. return Ref<Texture2D>();
  132. }
  133. void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {
  134. if (p_theme.is_null()) {
  135. return;
  136. }
  137. List<StringName> tl;
  138. p_theme->get_icon_list(EditorStringName(EditorIcons), &tl);
  139. for (const StringName &name : tl) {
  140. icon_type_cache[name] = p_theme->get_icon(name, EditorStringName(EditorIcons));
  141. }
  142. }
  143. // Main layout.
  144. void ProjectManager::_update_size_limits() {
  145. const Size2 minimum_size = Size2(720, 450) * EDSCALE;
  146. // Define a minimum window size to prevent UI elements from overlapping or being cut off.
  147. Window *w = Object::cast_to<Window>(SceneTree::get_singleton()->get_root());
  148. if (w) {
  149. // Calling Window methods this early doesn't sync properties with DS.
  150. w->set_min_size(minimum_size);
  151. DisplayServer::get_singleton()->window_set_min_size(minimum_size);
  152. }
  153. Size2 real_size = DisplayServer::get_singleton()->window_get_size();
  154. Rect2i screen_rect = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen());
  155. if (screen_rect.size != Vector2i()) {
  156. // Center the window on the screen.
  157. Vector2i window_position;
  158. window_position.x = screen_rect.position.x + (screen_rect.size.x - real_size.x) / 2;
  159. window_position.y = screen_rect.position.y + (screen_rect.size.y - real_size.y) / 2;
  160. // Limit popup menus to prevent unusably long lists.
  161. // We try to set it to half the screen resolution, but no smaller than the minimum window size.
  162. Size2 half_screen_rect = (screen_rect.size * EDSCALE) / 2;
  163. Size2 maximum_popup_size = MAX(half_screen_rect, minimum_size);
  164. quick_settings_dialog->update_size_limits(maximum_popup_size);
  165. }
  166. }
  167. void ProjectManager::_update_theme(bool p_skip_creation) {
  168. if (!p_skip_creation) {
  169. theme = EditorThemeManager::generate_theme(theme);
  170. DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
  171. }
  172. Vector<Ref<Theme>> editor_themes;
  173. editor_themes.push_back(theme);
  174. editor_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
  175. ThemeContext *node_tc = ThemeDB::get_singleton()->get_theme_context(this);
  176. if (node_tc) {
  177. node_tc->set_themes(editor_themes);
  178. } else {
  179. ThemeDB::get_singleton()->create_theme_context(this, editor_themes);
  180. }
  181. Window *owner_window = get_window();
  182. if (owner_window) {
  183. ThemeContext *window_tc = ThemeDB::get_singleton()->get_theme_context(owner_window);
  184. if (window_tc) {
  185. window_tc->set_themes(editor_themes);
  186. } else {
  187. ThemeDB::get_singleton()->create_theme_context(owner_window, editor_themes);
  188. }
  189. }
  190. // Update styles.
  191. {
  192. const int top_bar_separation = get_theme_constant(SNAME("top_bar_separation"), EditorStringName(Editor));
  193. root_container->add_theme_constant_override("margin_left", top_bar_separation);
  194. root_container->add_theme_constant_override("margin_top", top_bar_separation);
  195. root_container->add_theme_constant_override("margin_bottom", top_bar_separation);
  196. root_container->add_theme_constant_override("margin_right", top_bar_separation);
  197. main_vbox->add_theme_constant_override("separation", top_bar_separation);
  198. background_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("Background"), EditorStringName(EditorStyles)));
  199. main_view_container->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("TabContainer")));
  200. title_bar_logo->set_button_icon(get_editor_theme_icon(SNAME("TitleBarLogo")));
  201. _set_main_view_icon(MAIN_VIEW_PROJECTS, get_editor_theme_icon(SNAME("ProjectList")));
  202. _set_main_view_icon(MAIN_VIEW_ASSETLIB, get_editor_theme_icon(SNAME("AssetLib")));
  203. // Project list.
  204. {
  205. loading_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)));
  206. project_list_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("project_list"), SNAME("ProjectManager")));
  207. empty_list_create_project->set_button_icon(get_editor_theme_icon(SNAME("Add")));
  208. empty_list_import_project->set_button_icon(get_editor_theme_icon(SNAME("Load")));
  209. empty_list_open_assetlib->set_button_icon(get_editor_theme_icon(SNAME("AssetLib")));
  210. empty_list_online_warning->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("italic"), EditorStringName(EditorFonts)));
  211. empty_list_online_warning->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("font_placeholder_color"), EditorStringName(Editor)));
  212. // Top bar.
  213. search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  214. quick_settings_button->set_button_icon(get_editor_theme_icon(SNAME("Tools")));
  215. // Sidebar.
  216. create_btn->set_button_icon(get_editor_theme_icon(SNAME("Add")));
  217. import_btn->set_button_icon(get_editor_theme_icon(SNAME("Load")));
  218. scan_btn->set_button_icon(get_editor_theme_icon(SNAME("Search")));
  219. open_btn->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
  220. open_options_btn->set_button_icon(get_editor_theme_icon(SNAME("Collapse")));
  221. run_btn->set_button_icon(get_editor_theme_icon(SNAME("Play")));
  222. rename_btn->set_button_icon(get_editor_theme_icon(SNAME("Rename")));
  223. duplicate_btn->set_button_icon(get_editor_theme_icon(SNAME("Duplicate")));
  224. manage_tags_btn->set_button_icon(get_editor_theme_icon("Script"));
  225. erase_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
  226. erase_missing_btn->set_button_icon(get_editor_theme_icon(SNAME("Clear")));
  227. create_tag_btn->set_button_icon(get_editor_theme_icon("Add"));
  228. tag_error->add_theme_color_override(SceneStringName(font_color), get_theme_color("error_color", EditorStringName(Editor)));
  229. tag_edit_error->add_theme_color_override(SceneStringName(font_color), get_theme_color("error_color", EditorStringName(Editor)));
  230. create_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  231. import_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  232. scan_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  233. open_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  234. run_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  235. rename_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  236. duplicate_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  237. manage_tags_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  238. erase_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  239. erase_missing_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
  240. open_btn_container->add_theme_constant_override("separation", 0);
  241. open_options_popup->set_item_icon(0, get_editor_theme_icon(SNAME("Notification")));
  242. open_options_popup->set_item_icon(1, get_editor_theme_icon(SNAME("NodeWarning")));
  243. }
  244. // Dialogs
  245. migration_guide_button->set_button_icon(get_editor_theme_icon(SNAME("ExternalLink")));
  246. // Asset library popup.
  247. if (asset_library) {
  248. // Removes extra border margins.
  249. asset_library->add_theme_style_override(SceneStringName(panel), memnew(StyleBoxEmpty));
  250. }
  251. }
  252. }
  253. Button *ProjectManager::_add_main_view(MainViewTab p_id, const String &p_name, const Ref<Texture2D> &p_icon, Control *p_view_control) {
  254. ERR_FAIL_INDEX_V(p_id, MAIN_VIEW_MAX, nullptr);
  255. ERR_FAIL_COND_V(main_view_map.has(p_id), nullptr);
  256. ERR_FAIL_COND_V(main_view_toggle_map.has(p_id), nullptr);
  257. Button *toggle_button = memnew(Button);
  258. toggle_button->set_flat(true);
  259. toggle_button->set_theme_type_variation("MainScreenButton");
  260. toggle_button->set_toggle_mode(true);
  261. toggle_button->set_button_group(main_view_toggles_group);
  262. toggle_button->set_text(p_name);
  263. toggle_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_select_main_view).bind((int)p_id));
  264. main_view_toggles->add_child(toggle_button);
  265. main_view_toggle_map[p_id] = toggle_button;
  266. _set_main_view_icon(p_id, p_icon);
  267. p_view_control->set_visible(false);
  268. main_view_container->add_child(p_view_control);
  269. main_view_map[p_id] = p_view_control;
  270. return toggle_button;
  271. }
  272. void ProjectManager::_set_main_view_icon(MainViewTab p_id, const Ref<Texture2D> &p_icon) {
  273. ERR_FAIL_INDEX(p_id, MAIN_VIEW_MAX);
  274. ERR_FAIL_COND(!main_view_toggle_map.has(p_id));
  275. Button *toggle_button = main_view_toggle_map[p_id];
  276. Ref<Texture2D> old_icon = toggle_button->get_button_icon();
  277. if (old_icon.is_valid()) {
  278. old_icon->disconnect_changed(callable_mp((Control *)toggle_button, &Control::update_minimum_size));
  279. }
  280. if (p_icon.is_valid()) {
  281. toggle_button->set_button_icon(p_icon);
  282. // Make sure the control is updated if the icon is reimported.
  283. p_icon->connect_changed(callable_mp((Control *)toggle_button, &Control::update_minimum_size));
  284. } else {
  285. toggle_button->set_button_icon(Ref<Texture2D>());
  286. }
  287. }
  288. void ProjectManager::_select_main_view(int p_id) {
  289. MainViewTab view_id = (MainViewTab)p_id;
  290. ERR_FAIL_INDEX(view_id, MAIN_VIEW_MAX);
  291. ERR_FAIL_COND(!main_view_map.has(view_id));
  292. ERR_FAIL_COND(!main_view_toggle_map.has(view_id));
  293. if (current_main_view != view_id) {
  294. main_view_toggle_map[current_main_view]->set_pressed_no_signal(false);
  295. main_view_map[current_main_view]->set_visible(false);
  296. current_main_view = view_id;
  297. }
  298. main_view_toggle_map[current_main_view]->set_pressed_no_signal(true);
  299. main_view_map[current_main_view]->set_visible(true);
  300. #ifndef ANDROID_ENABLED
  301. if (current_main_view == MAIN_VIEW_PROJECTS && search_box->is_inside_tree()) {
  302. // Automatically grab focus when the user moves from the Templates tab
  303. // back to the Projects tab.
  304. search_box->grab_focus();
  305. }
  306. // The Templates tab's search field is focused on display in the asset
  307. // library editor plugin code.
  308. #endif
  309. }
  310. void ProjectManager::_show_about() {
  311. about_dialog->popup_centered(Size2(780, 500) * EDSCALE);
  312. }
  313. void ProjectManager::_open_asset_library_confirmed() {
  314. const int network_mode = EDITOR_GET("network/connection/network_mode");
  315. if (network_mode == EditorSettings::NETWORK_OFFLINE) {
  316. EditorSettings::get_singleton()->set_setting("network/connection/network_mode", EditorSettings::NETWORK_ONLINE);
  317. EditorSettings::get_singleton()->notify_changes();
  318. EditorSettings::get_singleton()->save();
  319. }
  320. asset_library->disable_community_support();
  321. _select_main_view(MAIN_VIEW_ASSETLIB);
  322. }
  323. void ProjectManager::_show_error(const String &p_message, const Size2 &p_min_size) {
  324. error_dialog->set_text(p_message);
  325. error_dialog->popup_centered(p_min_size);
  326. }
  327. void ProjectManager::_dim_window() {
  328. // This method must be called before calling `get_tree()->quit()`.
  329. // Otherwise, its effect won't be visible
  330. // Dim the project manager window while it's quitting to make it clearer that it's busy.
  331. // No transition is applied, as the effect needs to be visible immediately
  332. float c = 0.5f;
  333. Color dim_color = Color(c, c, c);
  334. set_modulate(dim_color);
  335. }
  336. // Quick settings.
  337. void ProjectManager::_show_quick_settings() {
  338. quick_settings_dialog->popup_centered(Size2(640, 200) * EDSCALE);
  339. }
  340. void ProjectManager::_restart_confirmed() {
  341. List<String> args = OS::get_singleton()->get_cmdline_args();
  342. Error err = OS::get_singleton()->create_instance(args);
  343. ERR_FAIL_COND(err);
  344. _dim_window();
  345. get_tree()->quit();
  346. }
  347. // Project list.
  348. void ProjectManager::_update_list_placeholder() {
  349. if (project_list->get_project_count() > 0) {
  350. empty_list_placeholder->hide();
  351. return;
  352. }
  353. empty_list_open_assetlib->set_visible(asset_library);
  354. const int network_mode = EDITOR_GET("network/connection/network_mode");
  355. if (network_mode == EditorSettings::NETWORK_OFFLINE) {
  356. empty_list_open_assetlib->set_text(TTRC("Go Online and Open Asset Library"));
  357. empty_list_online_warning->set_visible(true);
  358. } else {
  359. empty_list_open_assetlib->set_text(TTRC("Open Asset Library"));
  360. empty_list_online_warning->set_visible(false);
  361. }
  362. empty_list_placeholder->show();
  363. }
  364. void ProjectManager::_scan_projects() {
  365. scan_dir->popup_file_dialog();
  366. }
  367. void ProjectManager::_run_project() {
  368. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  369. if (selected_list.size() < 1) {
  370. return;
  371. }
  372. if (selected_list.size() > 1) {
  373. multi_run_ask->set_text(vformat(TTR("Are you sure to run %d projects at once?"), selected_list.size()));
  374. multi_run_ask->popup_centered();
  375. } else {
  376. _run_project_confirm();
  377. }
  378. }
  379. void ProjectManager::_run_project_confirm() {
  380. Vector<ProjectList::Item> selected_list = project_list->get_selected_projects();
  381. for (int i = 0; i < selected_list.size(); ++i) {
  382. const String &selected_main = selected_list[i].main_scene;
  383. if (selected_main.is_empty()) {
  384. _show_error(TTRC("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."));
  385. continue;
  386. }
  387. const String &path = selected_list[i].path;
  388. // `.substr(6)` on `ProjectSettings::get_singleton()->get_imported_files_path()` strips away the leading "res://".
  389. if (!DirAccess::exists(path.path_join(ProjectSettings::get_singleton()->get_imported_files_path().substr(6)))) {
  390. _show_error(TTRC("Can't run project: Assets need to be imported first.\nPlease edit the project to trigger the initial import."));
  391. continue;
  392. }
  393. print_line("Running project: " + path);
  394. List<String> args;
  395. for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT)) {
  396. args.push_back(a);
  397. }
  398. args.push_back("--path");
  399. args.push_back(path);
  400. Error err = OS::get_singleton()->create_instance(args);
  401. ERR_FAIL_COND(err);
  402. }
  403. }
  404. void ProjectManager::_open_selected_projects() {
  405. // Show loading text to tell the user that the project manager is busy loading.
  406. // This is especially important for the Web project manager.
  407. loading_label->show();
  408. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  409. for (const String &path : selected_list) {
  410. String conf = path.path_join("project.godot");
  411. if (!FileAccess::exists(conf)) {
  412. loading_label->hide();
  413. _show_error(vformat(TTR("Can't open project at '%s'.\nProject file doesn't exist or is inaccessible."), path));
  414. return;
  415. }
  416. print_line("Editing project: " + path);
  417. List<String> args;
  418. for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) {
  419. args.push_back(a);
  420. }
  421. args.push_back("--path");
  422. args.push_back(path);
  423. args.push_back("--editor");
  424. if (open_in_recovery_mode) {
  425. args.push_back("--recovery-mode");
  426. }
  427. if (open_in_verbose_mode) {
  428. args.push_back("--verbose");
  429. }
  430. Error err = OS::get_singleton()->create_instance(args);
  431. if (err != OK) {
  432. loading_label->hide();
  433. _show_error(vformat(TTR("Can't open project at '%s'.\nFailed to start the editor."), path));
  434. ERR_PRINT(vformat("Failed to start an editor instance for the project at '%s', error code %d.", path, err));
  435. return;
  436. }
  437. }
  438. project_list->project_opening_initiated = true;
  439. _dim_window();
  440. get_tree()->quit();
  441. }
  442. void ProjectManager::_open_selected_projects_check_warnings() {
  443. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  444. if (selected_list.size() < 1) {
  445. return;
  446. }
  447. const Size2i popup_min_size = Size2i(400.0 * EDSCALE, 0);
  448. if (selected_list.size() > 1) {
  449. 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()));
  450. multi_open_ask->popup_centered(popup_min_size);
  451. return;
  452. }
  453. ProjectList::Item project = project_list->get_selected_projects()[0];
  454. if (project.missing) {
  455. return;
  456. }
  457. // Update the project settings or don't open.
  458. const int config_version = project.version;
  459. PackedStringArray unsupported_features = project.unsupported_features;
  460. ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); // Reset in case of previous center align.
  461. ask_update_backup->set_pressed(false);
  462. full_convert_button->hide();
  463. migration_guide_button->hide();
  464. ask_update_backup->hide();
  465. ask_update_settings->get_ok_button()->set_text("OK");
  466. // Check if the config_version property was empty or 0.
  467. if (config_version == 0) {
  468. ask_update_label->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));
  469. ask_update_settings->popup_centered(popup_min_size);
  470. return;
  471. }
  472. // Check if we need to convert project settings from an earlier engine version.
  473. if (config_version < ProjectSettings::CONFIG_VERSION) {
  474. if (config_version == GODOT4_CONFIG_VERSION - 1 && ProjectSettings::CONFIG_VERSION == GODOT4_CONFIG_VERSION) { // Conversion from Godot 3 to 4.
  475. full_convert_button->show();
  476. ask_update_label->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));
  477. ask_update_settings->get_ok_button()->set_text(TTRC("Convert project.godot Only"));
  478. } else {
  479. ask_update_label->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));
  480. ask_update_settings->get_ok_button()->set_text(TTRC("Convert project.godot"));
  481. }
  482. ask_update_backup->show();
  483. migration_guide_button->show();
  484. ask_update_settings->popup_centered(popup_min_size);
  485. ask_update_settings->get_cancel_button()->grab_focus(); // To prevent accidents.
  486. return;
  487. }
  488. // Check if the file was generated by a newer, incompatible engine version.
  489. if (config_version > ProjectSettings::CONFIG_VERSION) {
  490. _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);
  491. return;
  492. }
  493. // Check if the project is using features not supported by this build of Godot.
  494. if (!unsupported_features.is_empty()) {
  495. String warning_message = "";
  496. for (int i = 0; i < unsupported_features.size(); i++) {
  497. const String &feature = unsupported_features[i];
  498. if (feature == "Double Precision") {
  499. ask_update_backup->show();
  500. 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");
  501. unsupported_features.remove_at(i);
  502. i--;
  503. } else if (feature == "C#") {
  504. 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");
  505. unsupported_features.remove_at(i);
  506. i--;
  507. } else if (ProjectList::project_feature_looks_like_version(feature)) {
  508. ask_update_backup->show();
  509. migration_guide_button->show();
  510. version_convert_feature = feature;
  511. 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(GODOT_VERSION_BRANCH));
  512. unsupported_features.remove_at(i);
  513. i--;
  514. }
  515. }
  516. if (!unsupported_features.is_empty()) {
  517. String unsupported_features_str = String(", ").join(unsupported_features);
  518. 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);
  519. }
  520. warning_message += TTR("Open anyway? Project will be modified.");
  521. ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  522. ask_update_label->set_text(warning_message);
  523. ask_update_settings->popup_centered(popup_min_size);
  524. return;
  525. }
  526. // Open if the project is up-to-date.
  527. _open_selected_projects();
  528. }
  529. void ProjectManager::_open_selected_projects_check_recovery_mode() {
  530. Vector<ProjectList::Item> selected_projects = project_list->get_selected_projects();
  531. if (selected_projects.is_empty()) {
  532. return;
  533. }
  534. const ProjectList::Item &project = selected_projects[0];
  535. if (project.missing) {
  536. return;
  537. }
  538. open_in_verbose_mode = false;
  539. open_in_recovery_mode = false;
  540. // Check if the project failed to load during last startup.
  541. if (project.recovery_mode) {
  542. _open_recovery_mode_ask(false);
  543. return;
  544. }
  545. _open_selected_projects_check_warnings();
  546. }
  547. void ProjectManager::_open_selected_projects_with_migration() {
  548. if (ask_update_backup->is_pressed() && project_list->get_selected_projects().size() == 1) {
  549. ask_update_settings->hide();
  550. ask_update_backup->set_pressed(false);
  551. _duplicate_project_with_action(POST_DUPLICATE_ACTION_OPEN);
  552. return;
  553. }
  554. #ifndef DISABLE_DEPRECATED
  555. if (project_list->get_selected_projects().size() == 1) {
  556. // Only migrate if a single project is opened.
  557. _minor_project_migrate();
  558. }
  559. #endif
  560. _open_selected_projects();
  561. }
  562. void ProjectManager::_install_project(const String &p_zip_path, const String &p_title) {
  563. project_dialog->set_mode(ProjectDialog::MODE_INSTALL);
  564. project_dialog->set_zip_path(p_zip_path);
  565. project_dialog->set_zip_title(p_title);
  566. project_dialog->show_dialog();
  567. }
  568. void ProjectManager::_import_project() {
  569. project_dialog->set_mode(ProjectDialog::MODE_IMPORT);
  570. project_dialog->ask_for_path_and_show();
  571. }
  572. void ProjectManager::_new_project() {
  573. project_dialog->set_mode(ProjectDialog::MODE_NEW);
  574. project_dialog->show_dialog();
  575. }
  576. void ProjectManager::_rename_project() {
  577. const Vector<ProjectList::Item> &selected_list = project_list->get_selected_projects();
  578. if (selected_list.is_empty()) {
  579. return;
  580. }
  581. for (const ProjectList::Item &E : selected_list) {
  582. project_dialog->set_project_name(E.project_name);
  583. project_dialog->set_project_path(E.path);
  584. project_dialog->set_mode(ProjectDialog::MODE_RENAME);
  585. project_dialog->show_dialog();
  586. }
  587. }
  588. void ProjectManager::_duplicate_project() {
  589. _duplicate_project_with_action(POST_DUPLICATE_ACTION_NONE);
  590. }
  591. void ProjectManager::_duplicate_project_with_action(PostDuplicateAction p_post_action) {
  592. Vector<ProjectList::Item> selected_projects = project_list->get_selected_projects();
  593. if (selected_projects.is_empty()) {
  594. return;
  595. }
  596. post_duplicate_action = p_post_action;
  597. const ProjectList::Item &project = selected_projects[0];
  598. project_dialog->set_mode(ProjectDialog::MODE_DUPLICATE);
  599. project_dialog->set_project_name(vformat("%s (%s)", project.project_name, p_post_action == POST_DUPLICATE_ACTION_NONE ? "Copy" : project.project_version));
  600. project_dialog->set_original_project_path(project.path);
  601. project_dialog->set_duplicate_can_edit(p_post_action == POST_DUPLICATE_ACTION_NONE);
  602. project_dialog->show_dialog(false);
  603. }
  604. void ProjectManager::_erase_project() {
  605. const HashSet<String> &selected_list = project_list->get_selected_project_keys();
  606. if (selected_list.is_empty()) {
  607. return;
  608. }
  609. String confirm_message;
  610. if (selected_list.size() >= 2) {
  611. confirm_message = vformat(TTR("Remove %d projects from the list?"), selected_list.size());
  612. } else {
  613. confirm_message = TTRC("Remove this project from the list?");
  614. }
  615. erase_ask_label->set_text(confirm_message);
  616. //delete_project_contents->set_pressed(false);
  617. erase_ask->popup_centered();
  618. }
  619. void ProjectManager::_erase_missing_projects() {
  620. erase_missing_ask->set_text(TTRC("Remove all missing projects from the list?\nThe project folders' contents won't be modified."));
  621. erase_missing_ask->popup_centered();
  622. }
  623. void ProjectManager::_erase_project_confirm() {
  624. project_list->erase_selected_projects(false);
  625. _update_project_buttons();
  626. _update_list_placeholder();
  627. }
  628. void ProjectManager::_erase_missing_projects_confirm() {
  629. project_list->erase_missing_projects();
  630. _update_project_buttons();
  631. _update_list_placeholder();
  632. }
  633. void ProjectManager::_update_project_buttons() {
  634. Vector<ProjectList::Item> selected_projects = project_list->get_selected_projects();
  635. bool empty_selection = selected_projects.is_empty();
  636. bool is_missing_project_selected = false;
  637. for (int i = 0; i < selected_projects.size(); ++i) {
  638. if (selected_projects[i].missing) {
  639. is_missing_project_selected = true;
  640. break;
  641. }
  642. }
  643. erase_btn->set_disabled(empty_selection);
  644. open_btn->set_disabled(empty_selection || is_missing_project_selected);
  645. open_options_btn->set_disabled(empty_selection || is_missing_project_selected);
  646. rename_btn->set_disabled(empty_selection || is_missing_project_selected);
  647. duplicate_btn->set_disabled(empty_selection || is_missing_project_selected);
  648. manage_tags_btn->set_disabled(empty_selection || is_missing_project_selected || selected_projects.size() > 1);
  649. run_btn->set_disabled(empty_selection || is_missing_project_selected);
  650. erase_missing_btn->set_disabled(!project_list->is_any_project_missing());
  651. }
  652. void ProjectManager::_open_options_popup() {
  653. Rect2 rect = open_btn_container->get_screen_rect();
  654. rect.position.y += rect.size.height;
  655. open_options_popup->set_size(Size2(rect.size.width, 0));
  656. open_options_popup->set_position(rect.position);
  657. open_options_popup->popup();
  658. }
  659. void ProjectManager::_open_recovery_mode_ask(bool manual) {
  660. String recovery_mode_details;
  661. // Only show the initial crash preamble if this popup wasn't manually triggered.
  662. if (!manual) {
  663. recovery_mode_details +=
  664. TTR("It looks like Godot crashed when opening this project the last time. If you're having problems editing this project, you can try to open it in Recovery Mode.") +
  665. String::utf8("\n\n");
  666. }
  667. recovery_mode_details +=
  668. TTR("Recovery Mode is a special mode that may help to recover projects that crash the engine during initialization. This mode temporarily disables the following features:") +
  669. String::utf8("\n\n• ") + TTR("Tool scripts") +
  670. String::utf8("\n• ") + TTR("Editor plugins") +
  671. String::utf8("\n• ") + TTR("GDExtension addons") +
  672. String::utf8("\n• ") + TTR("Automatic scene restoring") +
  673. String::utf8("\n\n") + TTR("This mode is intended only for basic editing to troubleshoot such issues, and therefore it will not be possible to run the project during this mode. It is also a good idea to make a backup of your project before proceeding.") +
  674. String::utf8("\n\n") + TTR("Edit the project in Recovery Mode?");
  675. open_recovery_mode_ask->set_text(recovery_mode_details);
  676. open_recovery_mode_ask->popup_centered(Size2(550, 70) * EDSCALE);
  677. }
  678. void ProjectManager::_on_projects_updated() {
  679. Vector<ProjectList::Item> selected_projects = project_list->get_selected_projects();
  680. int index = 0;
  681. for (int i = 0; i < selected_projects.size(); ++i) {
  682. index = project_list->refresh_project(selected_projects[i].path);
  683. }
  684. if (index != -1) {
  685. project_list->ensure_project_visible(index);
  686. }
  687. project_list->update_dock_menu();
  688. }
  689. void ProjectManager::_on_open_options_selected(int p_option) {
  690. switch (p_option) {
  691. case 0: // Edit in verbose mode.
  692. open_in_verbose_mode = true;
  693. _open_selected_projects_check_warnings();
  694. break;
  695. case 1: // Edit in recovery mode.
  696. _open_recovery_mode_ask(true);
  697. break;
  698. }
  699. }
  700. void ProjectManager::_on_recovery_mode_popup_open_normal() {
  701. open_recovery_mode_ask->hide();
  702. open_in_recovery_mode = false;
  703. _open_selected_projects_check_warnings();
  704. }
  705. void ProjectManager::_on_recovery_mode_popup_open_recovery() {
  706. open_in_recovery_mode = true;
  707. _open_selected_projects_check_warnings();
  708. }
  709. void ProjectManager::_on_project_created(const String &dir, bool edit) {
  710. project_list->add_project(dir, false);
  711. project_list->save_config();
  712. search_box->clear();
  713. int i = project_list->refresh_project(dir);
  714. project_list->select_project(i);
  715. project_list->ensure_project_visible(i);
  716. _update_project_buttons();
  717. _update_list_placeholder();
  718. if (edit) {
  719. _open_selected_projects_check_warnings();
  720. }
  721. project_list->update_dock_menu();
  722. }
  723. void ProjectManager::_on_project_duplicated(const String &p_original_path, const String &p_duplicate_path, bool p_edit) {
  724. if (post_duplicate_action == POST_DUPLICATE_ACTION_NONE) {
  725. _on_project_created(p_duplicate_path, p_edit);
  726. } else {
  727. project_list->add_project(p_duplicate_path, false);
  728. project_list->save_config();
  729. if (post_duplicate_action == POST_DUPLICATE_ACTION_OPEN) {
  730. _open_selected_projects_with_migration();
  731. } else if (post_duplicate_action == POST_DUPLICATE_ACTION_FULL_CONVERSION) {
  732. _full_convert_button_pressed();
  733. }
  734. project_list->update_dock_menu();
  735. }
  736. post_duplicate_action = POST_DUPLICATE_ACTION_NONE;
  737. }
  738. void ProjectManager::_on_order_option_changed(int p_idx) {
  739. if (is_inside_tree()) {
  740. project_list->set_order_option(p_idx);
  741. }
  742. }
  743. void ProjectManager::_on_search_term_changed(const String &p_term) {
  744. project_list->set_search_term(p_term);
  745. project_list->sort_projects();
  746. // Select the first visible project in the list.
  747. // This makes it possible to open a project without ever touching the mouse,
  748. // as the search field is automatically focused on startup.
  749. project_list->select_first_visible_project();
  750. _update_project_buttons();
  751. }
  752. void ProjectManager::_on_search_term_submitted(const String &p_text) {
  753. if (current_main_view != MAIN_VIEW_PROJECTS) {
  754. return;
  755. }
  756. _open_selected_projects_check_recovery_mode();
  757. }
  758. LineEdit *ProjectManager::get_search_box() {
  759. return search_box;
  760. }
  761. // Project tag management.
  762. void ProjectManager::_manage_project_tags() {
  763. for (int i = 0; i < project_tags->get_child_count(); i++) {
  764. project_tags->get_child(i)->queue_free();
  765. }
  766. const ProjectList::Item item = project_list->get_selected_projects()[0];
  767. current_project_tags = item.tags;
  768. for (const String &tag : current_project_tags) {
  769. ProjectTag *tag_control = memnew(ProjectTag(tag, true));
  770. project_tags->add_child(tag_control);
  771. tag_control->connect_button_to(callable_mp(this, &ProjectManager::_delete_project_tag).bind(tag));
  772. }
  773. tag_edit_error->hide();
  774. tag_manage_dialog->popup_centered(Vector2i(500, 0) * EDSCALE);
  775. }
  776. void ProjectManager::_add_project_tag(const String &p_tag) {
  777. if (current_project_tags.has(p_tag)) {
  778. return;
  779. }
  780. current_project_tags.append(p_tag);
  781. ProjectTag *tag_control = memnew(ProjectTag(p_tag, true));
  782. project_tags->add_child(tag_control);
  783. tag_control->connect_button_to(callable_mp(this, &ProjectManager::_delete_project_tag).bind(p_tag));
  784. }
  785. void ProjectManager::_delete_project_tag(const String &p_tag) {
  786. current_project_tags.erase(p_tag);
  787. for (int i = 0; i < project_tags->get_child_count(); i++) {
  788. ProjectTag *tag_control = Object::cast_to<ProjectTag>(project_tags->get_child(i));
  789. if (tag_control && tag_control->get_tag() == p_tag) {
  790. memdelete(tag_control);
  791. break;
  792. }
  793. }
  794. }
  795. void ProjectManager::_apply_project_tags() {
  796. PackedStringArray tags;
  797. for (int i = 0; i < project_tags->get_child_count(); i++) {
  798. ProjectTag *tag_control = Object::cast_to<ProjectTag>(project_tags->get_child(i));
  799. if (tag_control) {
  800. tags.append(tag_control->get_tag());
  801. }
  802. }
  803. const String project_godot = project_list->get_selected_projects()[0].path.path_join("project.godot");
  804. ProjectSettings *cfg = memnew(ProjectSettings(project_godot));
  805. if (!cfg->is_project_loaded()) {
  806. memdelete(cfg);
  807. tag_edit_error->set_text(vformat(TTR("Couldn't load project at '%s'. It may be missing or corrupted."), project_godot));
  808. tag_edit_error->show();
  809. callable_mp((Window *)tag_manage_dialog, &Window::show).call_deferred(); // Make sure the dialog does not disappear.
  810. return;
  811. } else {
  812. tags.sort();
  813. cfg->set("application/config/tags", tags);
  814. Error err = cfg->save_custom(project_godot);
  815. memdelete(cfg);
  816. if (err != OK) {
  817. tag_edit_error->set_text(vformat(TTR("Couldn't save project at '%s' (error %d)."), project_godot, err));
  818. tag_edit_error->show();
  819. callable_mp((Window *)tag_manage_dialog, &Window::show).call_deferred();
  820. return;
  821. }
  822. }
  823. _on_projects_updated();
  824. }
  825. void ProjectManager::_set_new_tag_name(const String p_name) {
  826. create_tag_dialog->get_ok_button()->set_disabled(true);
  827. if (p_name.is_empty()) {
  828. tag_error->set_text(TTRC("Tag name can't be empty."));
  829. return;
  830. }
  831. if (p_name.contains_char(' ')) {
  832. tag_error->set_text(TTRC("Tag name can't contain spaces."));
  833. return;
  834. }
  835. for (const String &c : forbidden_tag_characters) {
  836. if (p_name.contains(c)) {
  837. tag_error->set_text(vformat(TTRC("These characters are not allowed in tags: %s."), String(" ").join(forbidden_tag_characters)));
  838. return;
  839. }
  840. }
  841. if (p_name.to_lower() != p_name) {
  842. tag_error->set_text(TTRC("Tag name must be lowercase."));
  843. return;
  844. }
  845. tag_error->set_text("");
  846. create_tag_dialog->get_ok_button()->set_disabled(false);
  847. }
  848. void ProjectManager::_create_new_tag() {
  849. if (!tag_error->get_text().is_empty()) {
  850. return;
  851. }
  852. create_tag_dialog->hide(); // When using text_submitted, need to hide manually.
  853. add_new_tag(new_tag_name->get_text());
  854. _add_project_tag(new_tag_name->get_text());
  855. }
  856. void ProjectManager::add_new_tag(const String &p_tag) {
  857. if (!tag_set.has(p_tag)) {
  858. tag_set.insert(p_tag);
  859. ProjectTag *tag_control = memnew(ProjectTag(p_tag));
  860. all_tags->add_child(tag_control);
  861. all_tags->move_child(tag_control, -2);
  862. tag_control->connect_button_to(callable_mp(this, &ProjectManager::_add_project_tag).bind(p_tag));
  863. }
  864. }
  865. // Project converter/migration tool.
  866. #ifndef DISABLE_DEPRECATED
  867. void ProjectManager::_minor_project_migrate() {
  868. const ProjectList::Item migrated_project = project_list->get_selected_projects()[0];
  869. if (version_convert_feature.begins_with("4.3")) {
  870. // Migrate layout after scale changes.
  871. const float edscale = EDSCALE;
  872. if (edscale != 1.0) {
  873. Ref<ConfigFile> layout_file;
  874. layout_file.instantiate();
  875. const String layout_path = migrated_project.path.path_join(".godot/editor/editor_layout.cfg");
  876. Error err = layout_file->load(layout_path);
  877. if (err == OK) {
  878. for (int i = 0; i < 4; i++) {
  879. const String key = "dock_hsplit_" + itos(i + 1);
  880. int old_value = layout_file->get_value("docks", key, 0);
  881. if (old_value != 0) {
  882. layout_file->set_value("docks", key, old_value / edscale);
  883. }
  884. }
  885. layout_file->save(layout_path);
  886. }
  887. }
  888. }
  889. }
  890. #endif
  891. void ProjectManager::_full_convert_button_pressed() {
  892. ask_update_settings->hide();
  893. if (ask_update_backup->is_pressed()) {
  894. ask_update_backup->set_pressed(false);
  895. _duplicate_project_with_action(POST_DUPLICATE_ACTION_FULL_CONVERSION);
  896. return;
  897. }
  898. ask_full_convert_dialog->popup_centered(Size2i(600.0 * EDSCALE, 0));
  899. ask_full_convert_dialog->get_cancel_button()->grab_focus();
  900. }
  901. void ProjectManager::_migration_guide_button_pressed() {
  902. const String url = vformat("%s/tutorials/migrating/index.html", GODOT_VERSION_DOCS_URL);
  903. OS::get_singleton()->shell_open(url);
  904. }
  905. void ProjectManager::_perform_full_project_conversion() {
  906. Vector<ProjectList::Item> selected_list = project_list->get_selected_projects();
  907. if (selected_list.is_empty()) {
  908. return;
  909. }
  910. const String &path = selected_list[0].path;
  911. print_line("Converting project: " + path);
  912. List<String> args;
  913. args.push_back("--path");
  914. args.push_back(path);
  915. args.push_back("--convert-3to4");
  916. args.push_back("--rendering-driver");
  917. args.push_back(Main::get_rendering_driver_name());
  918. Error err = OS::get_singleton()->create_instance(args);
  919. ERR_FAIL_COND(err);
  920. project_list->set_project_version(path, GODOT4_CONFIG_VERSION);
  921. }
  922. // Input and I/O.
  923. void ProjectManager::shortcut_input(const Ref<InputEvent> &p_ev) {
  924. ERR_FAIL_COND(p_ev.is_null());
  925. Ref<InputEventKey> k = p_ev;
  926. if (k.is_valid()) {
  927. if (!k->is_pressed()) {
  928. return;
  929. }
  930. // Pressing Command + Q quits the Project Manager
  931. // This is handled by the platform implementation on macOS,
  932. // so only define the shortcut on other platforms
  933. #ifndef MACOS_ENABLED
  934. if (k->get_keycode_with_modifiers() == (KeyModifierMask::META | Key::Q)) {
  935. _dim_window();
  936. get_tree()->quit();
  937. }
  938. #endif
  939. if (current_main_view != MAIN_VIEW_PROJECTS) {
  940. return;
  941. }
  942. bool keycode_handled = true;
  943. switch (k->get_keycode()) {
  944. case Key::ENTER: {
  945. _open_selected_projects_check_recovery_mode();
  946. } break;
  947. case Key::HOME: {
  948. if (project_list->get_project_count() > 0) {
  949. project_list->select_project(0);
  950. _update_project_buttons();
  951. }
  952. } break;
  953. case Key::END: {
  954. if (project_list->get_project_count() > 0) {
  955. project_list->select_project(project_list->get_project_count() - 1);
  956. _update_project_buttons();
  957. }
  958. } break;
  959. case Key::UP: {
  960. if (k->is_shift_pressed()) {
  961. break;
  962. }
  963. int index = project_list->get_single_selected_index();
  964. if (index > 0) {
  965. project_list->select_project(index - 1);
  966. project_list->ensure_project_visible(index - 1);
  967. _update_project_buttons();
  968. }
  969. break;
  970. }
  971. case Key::DOWN: {
  972. if (k->is_shift_pressed()) {
  973. break;
  974. }
  975. int index = project_list->get_single_selected_index();
  976. if (index + 1 < project_list->get_project_count()) {
  977. project_list->select_project(index + 1);
  978. project_list->ensure_project_visible(index + 1);
  979. _update_project_buttons();
  980. }
  981. } break;
  982. case Key::F: {
  983. if (k->is_command_or_control_pressed()) {
  984. search_box->grab_focus();
  985. } else {
  986. keycode_handled = false;
  987. }
  988. } break;
  989. default: {
  990. keycode_handled = false;
  991. } break;
  992. }
  993. if (keycode_handled) {
  994. accept_event();
  995. }
  996. }
  997. }
  998. void ProjectManager::_files_dropped(PackedStringArray p_files) {
  999. // TODO: Support installing multiple ZIPs at the same time?
  1000. if (p_files.size() == 1 && p_files[0].ends_with(".zip")) {
  1001. const String &file = p_files[0];
  1002. _install_project(file, file.get_file().get_basename().capitalize());
  1003. return;
  1004. }
  1005. HashSet<String> folders_set;
  1006. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1007. for (int i = 0; i < p_files.size(); i++) {
  1008. const String &file = p_files[i];
  1009. folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir());
  1010. }
  1011. ERR_FAIL_COND(folders_set.is_empty()); // This can't really happen, we consume every dropped file path above.
  1012. PackedStringArray folders;
  1013. for (const String &E : folders_set) {
  1014. folders.push_back(E);
  1015. }
  1016. project_list->find_projects_multiple(folders);
  1017. }
  1018. void ProjectManager::_titlebar_resized() {
  1019. DisplayServer::get_singleton()->window_set_window_buttons_offset(Vector2i(title_bar->get_global_position().y + title_bar->get_size().y / 2, title_bar->get_global_position().y + title_bar->get_size().y / 2), DisplayServer::MAIN_WINDOW_ID);
  1020. const Vector3i &margin = DisplayServer::get_singleton()->window_get_safe_title_margins(DisplayServer::MAIN_WINDOW_ID);
  1021. if (left_menu_spacer) {
  1022. int w = (root_container->is_layout_rtl()) ? margin.y : margin.x;
  1023. left_menu_spacer->set_custom_minimum_size(Size2(w, 0));
  1024. }
  1025. if (right_menu_spacer) {
  1026. int w = (root_container->is_layout_rtl()) ? margin.x : margin.y;
  1027. right_menu_spacer->set_custom_minimum_size(Size2(w, 0));
  1028. }
  1029. if (title_bar) {
  1030. title_bar->set_custom_minimum_size(Size2(0, margin.z - title_bar->get_global_position().y));
  1031. }
  1032. }
  1033. // Object methods.
  1034. ProjectManager::ProjectManager() {
  1035. singleton = this;
  1036. // Turn off some servers we aren't going to be using in the Project Manager.
  1037. NavigationServer3D::get_singleton()->set_active(false);
  1038. PhysicsServer3D::get_singleton()->set_active(false);
  1039. PhysicsServer2D::get_singleton()->set_active(false);
  1040. // Initialize settings.
  1041. {
  1042. if (!EditorSettings::get_singleton()) {
  1043. EditorSettings::create();
  1044. }
  1045. EditorSettings::get_singleton()->set_optimize_save(false); // Just write settings as they come.
  1046. {
  1047. bool agile_input_event_flushing = EDITOR_GET("input/buffering/agile_event_flushing");
  1048. bool use_accumulated_input = EDITOR_GET("input/buffering/use_accumulated_input");
  1049. Input::get_singleton()->set_agile_input_event_flushing(agile_input_event_flushing);
  1050. Input::get_singleton()->set_use_accumulated_input(use_accumulated_input);
  1051. }
  1052. int display_scale = EDITOR_GET("interface/editor/display_scale");
  1053. switch (display_scale) {
  1054. case 0:
  1055. // Try applying a suitable display scale automatically.
  1056. EditorScale::set_scale(EditorSettings::get_auto_display_scale());
  1057. break;
  1058. case 1:
  1059. EditorScale::set_scale(0.75);
  1060. break;
  1061. case 2:
  1062. EditorScale::set_scale(1.0);
  1063. break;
  1064. case 3:
  1065. EditorScale::set_scale(1.25);
  1066. break;
  1067. case 4:
  1068. EditorScale::set_scale(1.5);
  1069. break;
  1070. case 5:
  1071. EditorScale::set_scale(1.75);
  1072. break;
  1073. case 6:
  1074. EditorScale::set_scale(2.0);
  1075. break;
  1076. default:
  1077. EditorScale::set_scale(EDITOR_GET("interface/editor/custom_display_scale"));
  1078. break;
  1079. }
  1080. EditorFileDialog::get_icon_func = &ProjectManager::_file_dialog_get_icon;
  1081. EditorFileDialog::get_thumbnail_func = &ProjectManager::_file_dialog_get_thumbnail;
  1082. EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));
  1083. EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int());
  1084. int swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
  1085. if (swap_cancel_ok != 0) { // 0 is auto, set in register_scene based on DisplayServer.
  1086. // Swap on means OK first.
  1087. AcceptDialog::set_swap_cancel_ok(swap_cancel_ok == 2);
  1088. }
  1089. OS::get_singleton()->set_low_processor_usage_mode(true);
  1090. }
  1091. SceneTree::get_singleton()->get_root()->connect("files_dropped", callable_mp(this, &ProjectManager::_files_dropped));
  1092. // Initialize UI.
  1093. {
  1094. int pm_root_dir = EDITOR_GET("interface/editor/ui_layout_direction");
  1095. Control::set_root_layout_direction(pm_root_dir);
  1096. Window::set_root_layout_direction(pm_root_dir);
  1097. EditorThemeManager::initialize();
  1098. theme = EditorThemeManager::generate_theme();
  1099. DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
  1100. set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  1101. _build_icon_type_cache(theme);
  1102. }
  1103. // Project manager layout.
  1104. background_panel = memnew(Panel);
  1105. add_child(background_panel);
  1106. background_panel->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  1107. root_container = memnew(MarginContainer);
  1108. add_child(root_container);
  1109. root_container->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  1110. main_vbox = memnew(VBoxContainer);
  1111. root_container->add_child(main_vbox);
  1112. // Title bar.
  1113. bool can_expand = bool(EDITOR_GET("interface/editor/expand_to_title")) && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_EXTEND_TO_TITLE);
  1114. {
  1115. title_bar = memnew(EditorTitleBar);
  1116. main_vbox->add_child(title_bar);
  1117. if (can_expand) {
  1118. // Add spacer to avoid other controls under window minimize/maximize/close buttons (left side).
  1119. left_menu_spacer = memnew(Control);
  1120. left_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1121. title_bar->add_child(left_menu_spacer);
  1122. }
  1123. HBoxContainer *left_hbox = memnew(HBoxContainer);
  1124. left_hbox->set_alignment(BoxContainer::ALIGNMENT_BEGIN);
  1125. left_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1126. left_hbox->set_stretch_ratio(1.0);
  1127. title_bar->add_child(left_hbox);
  1128. title_bar_logo = memnew(Button);
  1129. title_bar_logo->set_flat(true);
  1130. title_bar_logo->set_tooltip_text(TTR("About Godot"));
  1131. left_hbox->add_child(title_bar_logo);
  1132. title_bar_logo->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_show_about));
  1133. if (can_expand) {
  1134. // Spacer to center main toggles.
  1135. left_spacer = memnew(Control);
  1136. left_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1137. title_bar->add_child(left_spacer);
  1138. }
  1139. main_view_toggles = memnew(HBoxContainer);
  1140. main_view_toggles->set_alignment(BoxContainer::ALIGNMENT_CENTER);
  1141. main_view_toggles->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1142. main_view_toggles->set_stretch_ratio(2.0);
  1143. title_bar->add_child(main_view_toggles);
  1144. title_bar->set_center_control(main_view_toggles);
  1145. if (can_expand) {
  1146. // Spacer to center main toggles.
  1147. right_spacer = memnew(Control);
  1148. right_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1149. title_bar->add_child(right_spacer);
  1150. }
  1151. main_view_toggles_group.instantiate();
  1152. HBoxContainer *right_hbox = memnew(HBoxContainer);
  1153. right_hbox->set_alignment(BoxContainer::ALIGNMENT_END);
  1154. right_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1155. right_hbox->set_stretch_ratio(1.0);
  1156. title_bar->add_child(right_hbox);
  1157. quick_settings_button = memnew(Button);
  1158. quick_settings_button->set_flat(true);
  1159. quick_settings_button->set_text(TTRC("Settings"));
  1160. right_hbox->add_child(quick_settings_button);
  1161. quick_settings_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_show_quick_settings));
  1162. if (can_expand) {
  1163. // Add spacer to avoid other controls under the window minimize/maximize/close buttons (right side).
  1164. right_menu_spacer = memnew(Control);
  1165. right_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1166. title_bar->add_child(right_menu_spacer);
  1167. }
  1168. }
  1169. main_view_container = memnew(PanelContainer);
  1170. main_view_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1171. main_vbox->add_child(main_view_container);
  1172. // Project list view.
  1173. {
  1174. local_projects_vb = memnew(VBoxContainer);
  1175. local_projects_vb->set_name("LocalProjectsTab");
  1176. _add_main_view(MAIN_VIEW_PROJECTS, TTRC("Projects"), Ref<Texture2D>(), local_projects_vb);
  1177. // Project list's top bar.
  1178. {
  1179. HBoxContainer *hb = memnew(HBoxContainer);
  1180. hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1181. local_projects_vb->add_child(hb);
  1182. create_btn = memnew(Button);
  1183. create_btn->set_text(TTRC("Create"));
  1184. create_btn->set_shortcut(ED_SHORTCUT("project_manager/new_project", TTRC("New Project"), KeyModifierMask::CMD_OR_CTRL | Key::N));
  1185. create_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_new_project));
  1186. hb->add_child(create_btn);
  1187. import_btn = memnew(Button);
  1188. import_btn->set_text(TTRC("Import"));
  1189. import_btn->set_shortcut(ED_SHORTCUT("project_manager/import_project", TTRC("Import Project"), KeyModifierMask::CMD_OR_CTRL | Key::I));
  1190. import_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_import_project));
  1191. hb->add_child(import_btn);
  1192. scan_btn = memnew(Button);
  1193. scan_btn->set_text(TTRC("Scan"));
  1194. scan_btn->set_shortcut(ED_SHORTCUT("project_manager/scan_projects", TTRC("Scan Projects"), KeyModifierMask::CMD_OR_CTRL | Key::S));
  1195. scan_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_scan_projects));
  1196. hb->add_child(scan_btn);
  1197. loading_label = memnew(Label(TTRC("Loading, please wait...")));
  1198. loading_label->set_accessibility_live(DisplayServer::AccessibilityLiveMode::LIVE_ASSERTIVE);
  1199. loading_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1200. loading_label->hide();
  1201. hb->add_child(loading_label);
  1202. search_box = memnew(LineEdit);
  1203. search_box->set_placeholder(TTRC("Filter Projects"));
  1204. search_box->set_accessibility_name(TTRC("Filter Projects"));
  1205. search_box->set_tooltip_text(TTRC("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."));
  1206. search_box->set_clear_button_enabled(true);
  1207. search_box->connect(SceneStringName(text_changed), callable_mp(this, &ProjectManager::_on_search_term_changed));
  1208. search_box->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectManager::_on_search_term_submitted));
  1209. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1210. hb->add_child(search_box);
  1211. sort_label = memnew(Label);
  1212. sort_label->set_text(TTRC("Sort:"));
  1213. hb->add_child(sort_label);
  1214. filter_option = memnew(OptionButton);
  1215. filter_option->set_clip_text(true);
  1216. filter_option->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1217. filter_option->set_stretch_ratio(0.3);
  1218. filter_option->set_accessibility_name(TTRC("Sort:"));
  1219. filter_option->connect(SceneStringName(item_selected), callable_mp(this, &ProjectManager::_on_order_option_changed));
  1220. hb->add_child(filter_option);
  1221. filter_option->add_item(TTRC("Last Edited"));
  1222. filter_option->add_item(TTRC("Name"));
  1223. filter_option->add_item(TTRC("Path"));
  1224. filter_option->add_item(TTRC("Tags"));
  1225. }
  1226. // Project list and its sidebar.
  1227. {
  1228. HBoxContainer *project_list_hbox = memnew(HBoxContainer);
  1229. local_projects_vb->add_child(project_list_hbox);
  1230. project_list_hbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1231. project_list_panel = memnew(PanelContainer);
  1232. project_list_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1233. project_list_hbox->add_child(project_list_panel);
  1234. project_list = memnew(ProjectList);
  1235. project_list->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  1236. project_list_panel->add_child(project_list);
  1237. project_list->connect(ProjectList::SIGNAL_LIST_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons));
  1238. project_list->connect(ProjectList::SIGNAL_LIST_CHANGED, callable_mp(this, &ProjectManager::_update_list_placeholder));
  1239. project_list->connect(ProjectList::SIGNAL_SELECTION_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons));
  1240. project_list->connect(ProjectList::SIGNAL_PROJECT_ASK_OPEN, callable_mp(this, &ProjectManager::_open_selected_projects_check_recovery_mode));
  1241. // Empty project list placeholder.
  1242. {
  1243. empty_list_placeholder = memnew(VBoxContainer);
  1244. empty_list_placeholder->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1245. empty_list_placeholder->add_theme_constant_override("separation", 16 * EDSCALE);
  1246. empty_list_placeholder->hide();
  1247. project_list_panel->add_child(empty_list_placeholder);
  1248. empty_list_message = memnew(RichTextLabel);
  1249. empty_list_message->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1250. empty_list_message->set_use_bbcode(true);
  1251. empty_list_message->set_fit_content(true);
  1252. empty_list_message->set_h_size_flags(SIZE_EXPAND_FILL);
  1253. empty_list_message->add_theme_style_override(CoreStringName(normal), memnew(StyleBoxEmpty));
  1254. empty_list_placeholder->add_child(empty_list_message);
  1255. FlowContainer *empty_list_actions = memnew(FlowContainer);
  1256. empty_list_actions->set_alignment(FlowContainer::ALIGNMENT_CENTER);
  1257. empty_list_placeholder->add_child(empty_list_actions);
  1258. empty_list_create_project = memnew(Button);
  1259. empty_list_create_project->set_text(TTRC("Create New Project"));
  1260. empty_list_create_project->set_theme_type_variation("PanelBackgroundButton");
  1261. empty_list_actions->add_child(empty_list_create_project);
  1262. empty_list_create_project->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_new_project));
  1263. empty_list_import_project = memnew(Button);
  1264. empty_list_import_project->set_text(TTRC("Import Existing Project"));
  1265. empty_list_import_project->set_theme_type_variation("PanelBackgroundButton");
  1266. empty_list_actions->add_child(empty_list_import_project);
  1267. empty_list_import_project->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_import_project));
  1268. empty_list_open_assetlib = memnew(Button);
  1269. empty_list_open_assetlib->set_text(TTRC("Open Asset Library"));
  1270. empty_list_open_assetlib->set_theme_type_variation("PanelBackgroundButton");
  1271. empty_list_actions->add_child(empty_list_open_assetlib);
  1272. empty_list_open_assetlib->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_asset_library_confirmed));
  1273. empty_list_online_warning = memnew(Label);
  1274. empty_list_online_warning->set_focus_mode(FOCUS_ACCESSIBILITY);
  1275. empty_list_online_warning->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
  1276. empty_list_online_warning->set_custom_minimum_size(Size2(220, 0) * EDSCALE);
  1277. empty_list_online_warning->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1278. empty_list_online_warning->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1279. empty_list_online_warning->set_text(TTRC("Note: The Asset Library requires an online connection and involves sending data over the internet."));
  1280. empty_list_placeholder->add_child(empty_list_online_warning);
  1281. }
  1282. // The side bar with the edit, run, rename, etc. buttons.
  1283. VBoxContainer *project_list_sidebar = memnew(VBoxContainer);
  1284. project_list_sidebar->set_custom_minimum_size(Size2(120, 120));
  1285. project_list_hbox->add_child(project_list_sidebar);
  1286. project_list_sidebar->add_child(memnew(HSeparator));
  1287. open_btn_container = memnew(HBoxContainer);
  1288. open_btn_container->set_anchors_preset(Control::PRESET_FULL_RECT);
  1289. project_list_sidebar->add_child(open_btn_container);
  1290. open_btn = memnew(Button);
  1291. open_btn->set_text(TTRC("Edit"));
  1292. open_btn->set_shortcut(ED_SHORTCUT("project_manager/edit_project", TTRC("Edit Project"), KeyModifierMask::CMD_OR_CTRL | Key::E));
  1293. open_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_selected_projects_check_recovery_mode));
  1294. open_btn->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1295. open_btn_container->add_child(open_btn);
  1296. open_btn_container->add_child(memnew(VSeparator));
  1297. open_options_btn = memnew(Button);
  1298. open_options_btn->set_accessibility_name(TTRC("Options"));
  1299. open_options_btn->set_icon_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
  1300. open_options_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_options_popup));
  1301. open_btn_container->add_child(open_options_btn);
  1302. open_options_popup = memnew(PopupMenu);
  1303. open_options_popup->add_item(TTRC("Edit in verbose mode"));
  1304. open_options_popup->add_item(TTRC("Edit in recovery mode"));
  1305. open_options_popup->connect(SceneStringName(id_pressed), callable_mp(this, &ProjectManager::_on_open_options_selected));
  1306. open_options_btn->add_child(open_options_popup);
  1307. open_btn_container->set_custom_minimum_size(Size2(120, open_btn->get_combined_minimum_size().y));
  1308. run_btn = memnew(Button);
  1309. run_btn->set_text(TTRC("Run"));
  1310. run_btn->set_shortcut(ED_SHORTCUT("project_manager/run_project", TTRC("Run Project"), KeyModifierMask::CMD_OR_CTRL | Key::R));
  1311. run_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_run_project));
  1312. project_list_sidebar->add_child(run_btn);
  1313. rename_btn = memnew(Button);
  1314. rename_btn->set_text(TTRC("Rename"));
  1315. // The F2 shortcut isn't overridden with Enter on macOS as Enter is already used to edit a project.
  1316. rename_btn->set_shortcut(ED_SHORTCUT("project_manager/rename_project", TTRC("Rename Project"), Key::F2));
  1317. rename_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_rename_project));
  1318. project_list_sidebar->add_child(rename_btn);
  1319. duplicate_btn = memnew(Button);
  1320. duplicate_btn->set_text(TTRC("Duplicate"));
  1321. duplicate_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_duplicate_project));
  1322. project_list_sidebar->add_child(duplicate_btn);
  1323. manage_tags_btn = memnew(Button);
  1324. manage_tags_btn->set_text(TTRC("Manage Tags"));
  1325. manage_tags_btn->set_shortcut(ED_SHORTCUT("project_manager/project_tags", TTRC("Manage Tags"), KeyModifierMask::CMD_OR_CTRL | Key::T));
  1326. project_list_sidebar->add_child(manage_tags_btn);
  1327. erase_btn = memnew(Button);
  1328. erase_btn->set_text(TTRC("Remove"));
  1329. erase_btn->set_shortcut(ED_SHORTCUT("project_manager/remove_project", TTRC("Remove Project"), Key::KEY_DELETE));
  1330. erase_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_erase_project));
  1331. project_list_sidebar->add_child(erase_btn);
  1332. Control *filler = memnew(Control);
  1333. filler->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1334. project_list_sidebar->add_child(filler);
  1335. erase_missing_btn = memnew(Button);
  1336. erase_missing_btn->set_text(TTRC("Remove Missing"));
  1337. erase_missing_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_erase_missing_projects));
  1338. project_list_sidebar->add_child(erase_missing_btn);
  1339. }
  1340. }
  1341. // Asset library view.
  1342. if (AssetLibraryEditorPlugin::is_available()) {
  1343. asset_library = memnew(EditorAssetLibrary(true));
  1344. asset_library->set_name("AssetLibraryTab");
  1345. _add_main_view(MAIN_VIEW_ASSETLIB, TTRC("Asset Library"), Ref<Texture2D>(), asset_library);
  1346. asset_library->connect("install_asset", callable_mp(this, &ProjectManager::_install_project));
  1347. } else {
  1348. VBoxContainer *asset_library_filler = memnew(VBoxContainer);
  1349. asset_library_filler->set_name("AssetLibraryTab");
  1350. Button *asset_library_toggle = _add_main_view(MAIN_VIEW_ASSETLIB, TTRC("Asset Library"), Ref<Texture2D>(), asset_library_filler);
  1351. asset_library_toggle->set_disabled(true);
  1352. asset_library_toggle->set_tooltip_text(TTRC("Asset Library not available (due to using Web editor, or because SSL support disabled)."));
  1353. }
  1354. // Footer bar.
  1355. {
  1356. HBoxContainer *footer_bar = memnew(HBoxContainer);
  1357. footer_bar->set_alignment(BoxContainer::ALIGNMENT_END);
  1358. footer_bar->add_theme_constant_override("separation", 20 * EDSCALE);
  1359. main_vbox->add_child(footer_bar);
  1360. #ifdef ENGINE_UPDATE_CHECK_ENABLED
  1361. EngineUpdateLabel *update_label = memnew(EngineUpdateLabel);
  1362. footer_bar->add_child(update_label);
  1363. update_label->connect("offline_clicked", callable_mp(this, &ProjectManager::_show_quick_settings));
  1364. #endif
  1365. EditorVersionButton *version_btn = memnew(EditorVersionButton(EditorVersionButton::FORMAT_WITH_BUILD));
  1366. // Fade the version label to be less prominent, but still readable.
  1367. version_btn->set_self_modulate(Color(1, 1, 1, 0.6));
  1368. footer_bar->add_child(version_btn);
  1369. }
  1370. // Dialogs.
  1371. {
  1372. quick_settings_dialog = memnew(QuickSettingsDialog);
  1373. add_child(quick_settings_dialog);
  1374. quick_settings_dialog->connect("restart_required", callable_mp(this, &ProjectManager::_restart_confirmed));
  1375. scan_dir = memnew(EditorFileDialog);
  1376. scan_dir->set_previews_enabled(false);
  1377. scan_dir->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1378. scan_dir->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
  1379. scan_dir->set_title(TTRC("Select a Folder to Scan")); // Must be after mode or it's overridden.
  1380. scan_dir->set_current_dir(EDITOR_GET("filesystem/directories/default_project_path"));
  1381. add_child(scan_dir);
  1382. scan_dir->connect("dir_selected", callable_mp(project_list, &ProjectList::find_projects));
  1383. erase_missing_ask = memnew(ConfirmationDialog);
  1384. erase_missing_ask->set_ok_button_text(TTRC("Remove All"));
  1385. erase_missing_ask->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_erase_missing_projects_confirm));
  1386. add_child(erase_missing_ask);
  1387. erase_ask = memnew(ConfirmationDialog);
  1388. erase_ask->set_ok_button_text(TTRC("Remove"));
  1389. erase_ask->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_erase_project_confirm));
  1390. add_child(erase_ask);
  1391. VBoxContainer *erase_ask_vb = memnew(VBoxContainer);
  1392. erase_ask->add_child(erase_ask_vb);
  1393. erase_ask_label = memnew(Label);
  1394. erase_ask_label->set_focus_mode(FOCUS_ACCESSIBILITY);
  1395. erase_ask_vb->add_child(erase_ask_label);
  1396. // Comment out for now until we have a better warning system to
  1397. // ensure users delete their project only.
  1398. //delete_project_contents = memnew(CheckBox);
  1399. //delete_project_contents->set_text(TTRC("Also delete project contents (no undo!)"));
  1400. //erase_ask_vb->add_child(delete_project_contents);
  1401. multi_open_ask = memnew(ConfirmationDialog);
  1402. multi_open_ask->set_ok_button_text(TTRC("Edit"));
  1403. multi_open_ask->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_selected_projects));
  1404. add_child(multi_open_ask);
  1405. multi_run_ask = memnew(ConfirmationDialog);
  1406. multi_run_ask->set_ok_button_text(TTRC("Run"));
  1407. multi_run_ask->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_run_project_confirm));
  1408. add_child(multi_run_ask);
  1409. open_recovery_mode_ask = memnew(ConfirmationDialog);
  1410. open_recovery_mode_ask->set_min_size(Size2(550, 70) * EDSCALE);
  1411. open_recovery_mode_ask->set_autowrap(true);
  1412. open_recovery_mode_ask->add_button(TTRC("Edit normally"))->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_on_recovery_mode_popup_open_normal));
  1413. open_recovery_mode_ask->set_ok_button_text(TTRC("Edit in Recovery Mode"));
  1414. open_recovery_mode_ask->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_on_recovery_mode_popup_open_recovery));
  1415. add_child(open_recovery_mode_ask);
  1416. ask_update_settings = memnew(ConfirmationDialog);
  1417. add_child(ask_update_settings);
  1418. ask_update_vb = memnew(VBoxContainer);
  1419. ask_update_settings->add_child(ask_update_vb);
  1420. ask_update_label = memnew(Label);
  1421. ask_update_label->set_focus_mode(FOCUS_ACCESSIBILITY);
  1422. ask_update_label->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1423. ask_update_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1424. ask_update_label->set_v_size_flags(SIZE_EXPAND_FILL);
  1425. ask_update_vb->add_child(ask_update_label);
  1426. ask_update_backup = memnew(CheckBox);
  1427. ask_update_backup->set_text(TTRC("Backup project first"));
  1428. ask_update_backup->set_h_size_flags(SIZE_SHRINK_CENTER);
  1429. ask_update_vb->add_child(ask_update_backup);
  1430. ask_update_settings->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_selected_projects_with_migration));
  1431. int ed_swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
  1432. if (ed_swap_cancel_ok == 0) {
  1433. ed_swap_cancel_ok = DisplayServer::get_singleton()->get_swap_cancel_ok() ? 2 : 1;
  1434. }
  1435. full_convert_button = ask_update_settings->add_button(TTRC("Convert Full Project"), ed_swap_cancel_ok != 2);
  1436. full_convert_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_full_convert_button_pressed));
  1437. migration_guide_button = ask_update_settings->add_button(TTRC("See Migration Guide"), ed_swap_cancel_ok != 2);
  1438. migration_guide_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_migration_guide_button_pressed));
  1439. ask_full_convert_dialog = memnew(ConfirmationDialog);
  1440. ask_full_convert_dialog->set_autowrap(true);
  1441. ask_full_convert_dialog->set_text(TTRC("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."));
  1442. ask_full_convert_dialog->connect(SceneStringName(confirmed), callable_mp(this, &ProjectManager::_perform_full_project_conversion));
  1443. add_child(ask_full_convert_dialog);
  1444. project_dialog = memnew(ProjectDialog);
  1445. project_dialog->connect("projects_updated", callable_mp(this, &ProjectManager::_on_projects_updated));
  1446. project_dialog->connect("project_created", callable_mp(this, &ProjectManager::_on_project_created));
  1447. project_dialog->connect("project_duplicated", callable_mp(this, &ProjectManager::_on_project_duplicated));
  1448. add_child(project_dialog);
  1449. error_dialog = memnew(AcceptDialog);
  1450. error_dialog->set_title(TTRC("Error"));
  1451. add_child(error_dialog);
  1452. about_dialog = memnew(EditorAbout);
  1453. add_child(about_dialog);
  1454. }
  1455. // Tag management.
  1456. {
  1457. tag_manage_dialog = memnew(ConfirmationDialog);
  1458. add_child(tag_manage_dialog);
  1459. tag_manage_dialog->set_title(TTRC("Manage Project Tags"));
  1460. tag_manage_dialog->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_apply_project_tags));
  1461. manage_tags_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_manage_project_tags));
  1462. VBoxContainer *tag_vb = memnew(VBoxContainer);
  1463. tag_manage_dialog->add_child(tag_vb);
  1464. Label *label = memnew(Label(TTRC("Project Tags")));
  1465. tag_vb->add_child(label);
  1466. label->set_theme_type_variation("HeaderMedium");
  1467. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1468. label = memnew(Label(TTRC("Click tag to remove it from the project.")));
  1469. tag_vb->add_child(label);
  1470. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1471. project_tags = memnew(HFlowContainer);
  1472. tag_vb->add_child(project_tags);
  1473. project_tags->set_custom_minimum_size(Vector2(0, 100) * EDSCALE);
  1474. tag_vb->add_child(memnew(HSeparator));
  1475. label = memnew(Label(TTRC("All Tags")));
  1476. tag_vb->add_child(label);
  1477. label->set_theme_type_variation("HeaderMedium");
  1478. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1479. label = memnew(Label(TTRC("Click tag to add it to the project.")));
  1480. tag_vb->add_child(label);
  1481. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1482. all_tags = memnew(HFlowContainer);
  1483. tag_vb->add_child(all_tags);
  1484. all_tags->set_custom_minimum_size(Vector2(0, 100) * EDSCALE);
  1485. tag_edit_error = memnew(Label);
  1486. tag_vb->add_child(tag_edit_error);
  1487. tag_edit_error->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1488. create_tag_dialog = memnew(ConfirmationDialog);
  1489. tag_manage_dialog->add_child(create_tag_dialog);
  1490. create_tag_dialog->set_title(TTRC("Create New Tag"));
  1491. create_tag_dialog->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_create_new_tag));
  1492. tag_vb = memnew(VBoxContainer);
  1493. create_tag_dialog->add_child(tag_vb);
  1494. Label *info = memnew(Label(TTRC("Tags are capitalized automatically when displayed.")));
  1495. tag_vb->add_child(info);
  1496. new_tag_name = memnew(LineEdit);
  1497. tag_vb->add_child(new_tag_name);
  1498. new_tag_name->set_accessibility_name(TTRC("New Tag Name"));
  1499. new_tag_name->connect(SceneStringName(text_changed), callable_mp(this, &ProjectManager::_set_new_tag_name));
  1500. new_tag_name->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectManager::_create_new_tag).unbind(1));
  1501. create_tag_dialog->connect("about_to_popup", callable_mp(new_tag_name, &LineEdit::clear));
  1502. create_tag_dialog->connect("about_to_popup", callable_mp((Control *)new_tag_name, &Control::grab_focus), CONNECT_DEFERRED);
  1503. tag_error = memnew(Label);
  1504. tag_error->set_focus_mode(FOCUS_ACCESSIBILITY);
  1505. tag_vb->add_child(tag_error);
  1506. create_tag_btn = memnew(Button);
  1507. create_tag_btn->set_accessibility_name(TTRC("Create Tag"));
  1508. all_tags->add_child(create_tag_btn);
  1509. create_tag_btn->connect(SceneStringName(pressed), callable_mp((Window *)create_tag_dialog, &Window::popup_centered).bind(Vector2i(500, 0) * EDSCALE));
  1510. }
  1511. // Initialize project list.
  1512. {
  1513. project_list->load_project_list();
  1514. Ref<DirAccess> dir_access = DirAccess::create(DirAccess::AccessType::ACCESS_FILESYSTEM);
  1515. String default_project_path = EDITOR_GET("filesystem/directories/default_project_path");
  1516. if (!default_project_path.is_empty() && !dir_access->dir_exists(default_project_path)) {
  1517. Error error = dir_access->make_dir_recursive(default_project_path);
  1518. if (error != OK) {
  1519. ERR_PRINT("Could not create default project directory at: " + default_project_path);
  1520. }
  1521. }
  1522. String autoscan_path = EDITOR_GET("filesystem/directories/autoscan_project_path");
  1523. if (!autoscan_path.is_empty()) {
  1524. if (dir_access->dir_exists(autoscan_path)) {
  1525. project_list->find_projects(autoscan_path);
  1526. } else {
  1527. Error error = dir_access->make_dir_recursive(autoscan_path);
  1528. if (error != OK) {
  1529. ERR_PRINT("Could not create project autoscan directory at: " + autoscan_path);
  1530. }
  1531. }
  1532. }
  1533. project_list->update_project_list();
  1534. initialized = true;
  1535. }
  1536. // Extend menu bar to window title.
  1537. if (can_expand) {
  1538. DisplayServer::get_singleton()->process_events();
  1539. DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE, true, DisplayServer::MAIN_WINDOW_ID);
  1540. title_bar->set_can_move_window(true);
  1541. title_bar->connect(SceneStringName(item_rect_changed), callable_mp(this, &ProjectManager::_titlebar_resized));
  1542. }
  1543. _update_size_limits();
  1544. }
  1545. ProjectManager::~ProjectManager() {
  1546. singleton = nullptr;
  1547. if (EditorSettings::get_singleton()) {
  1548. EditorSettings::destroy();
  1549. }
  1550. EditorThemeManager::finalize();
  1551. }