Debian Codegraph @

editor/project_manager/project_manager.cpp

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