project_manager.cpp 63 KB

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