project_manager.cpp 64 KB

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