2
0

project_manager.cpp 69 KB

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