project_manager.cpp 64 KB

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