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