Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/project_manager/project_list.cpp
9896 views
1
/**************************************************************************/
2
/* project_list.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_list.h"
32
33
#include "core/config/project_settings.h"
34
#include "core/io/dir_access.h"
35
#include "core/os/time.h"
36
#include "core/version.h"
37
#include "editor/editor_string_names.h"
38
#include "editor/file_system/editor_paths.h"
39
#include "editor/project_manager/project_manager.h"
40
#include "editor/project_manager/project_tag.h"
41
#include "editor/settings/editor_settings.h"
42
#include "editor/themes/editor_scale.h"
43
#include "scene/gui/button.h"
44
#include "scene/gui/dialogs.h"
45
#include "scene/gui/label.h"
46
#include "scene/gui/line_edit.h"
47
#include "scene/gui/progress_bar.h"
48
#include "scene/gui/texture_button.h"
49
#include "scene/gui/texture_rect.h"
50
#include "scene/resources/image_texture.h"
51
52
const char *ProjectList::SIGNAL_LIST_CHANGED = "list_changed";
53
const char *ProjectList::SIGNAL_SELECTION_CHANGED = "selection_changed";
54
const char *ProjectList::SIGNAL_PROJECT_ASK_OPEN = "project_ask_open";
55
56
void ProjectListItemControl::_notification(int p_what) {
57
switch (p_what) {
58
case NOTIFICATION_THEME_CHANGED: {
59
if (icon_needs_reload) {
60
// The project icon may not be loaded by the time the control is displayed,
61
// so use a loading placeholder.
62
project_icon->set_texture(get_editor_theme_icon(SNAME("ProjectIconLoading")));
63
}
64
65
project_title->begin_bulk_theme_override();
66
project_title->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("title"), EditorStringName(EditorFonts)));
67
project_title->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("title_size"), EditorStringName(EditorFonts)));
68
project_title->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("Tree")));
69
project_title->end_bulk_theme_override();
70
71
project_path->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("Tree")));
72
project_unsupported_features->set_texture(get_editor_theme_icon(SNAME("NodeWarning")));
73
74
favorite_button->set_texture_normal(get_editor_theme_icon(SNAME("Favorites")));
75
76
if (project_is_missing) {
77
explore_button->set_button_icon(get_editor_theme_icon(SNAME("FileBroken")));
78
#if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
79
} else {
80
explore_button->set_button_icon(get_editor_theme_icon(SNAME("Load")));
81
#endif
82
}
83
} break;
84
85
case NOTIFICATION_MOUSE_ENTER: {
86
is_hovering = true;
87
queue_redraw();
88
queue_accessibility_update();
89
} break;
90
91
case NOTIFICATION_MOUSE_EXIT: {
92
is_hovering = false;
93
queue_redraw();
94
queue_accessibility_update();
95
} break;
96
97
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
98
RID ae = get_accessibility_element();
99
ERR_FAIL_COND(ae.is_null());
100
101
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_LIST_BOX_OPTION);
102
DisplayServer::get_singleton()->accessibility_update_set_name(ae, TTR("Project") + " " + project_title->get_text());
103
DisplayServer::get_singleton()->accessibility_update_set_value(ae, project_title->get_text());
104
105
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_CLICK, callable_mp(this, &ProjectListItemControl::_accessibility_action_open));
106
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SCROLL_INTO_VIEW, callable_mp(this, &ProjectListItemControl::_accessibility_action_scroll_into_view));
107
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_FOCUS, callable_mp(this, &ProjectListItemControl::_accessibility_action_focus));
108
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_BLUR, callable_mp(this, &ProjectListItemControl::_accessibility_action_blur));
109
110
ProjectList *pl = get_list();
111
if (pl) {
112
DisplayServer::get_singleton()->accessibility_update_set_list_item_index(ae, pl->get_index(this));
113
}
114
DisplayServer::get_singleton()->accessibility_update_set_list_item_level(ae, 0);
115
DisplayServer::get_singleton()->accessibility_update_set_list_item_selected(ae, is_selected);
116
} break;
117
118
case NOTIFICATION_FOCUS_ENTER: {
119
ProjectList *pl = get_list();
120
if (pl) {
121
int idx = pl->get_index(this);
122
if (idx >= 0) {
123
pl->ensure_project_visible(idx);
124
pl->select_project(idx);
125
126
pl->emit_signal(SNAME(ProjectList::SIGNAL_SELECTION_CHANGED));
127
}
128
}
129
} break;
130
131
case NOTIFICATION_DRAW: {
132
if (is_selected) {
133
draw_style_box(get_theme_stylebox(SNAME("selected"), SNAME("Tree")), Rect2(Point2(), get_size()));
134
}
135
if (is_hovering) {
136
draw_style_box(get_theme_stylebox(SNAME("hovered"), SNAME("Tree")), Rect2(Point2(), get_size()));
137
}
138
139
draw_line(Point2(0, get_size().y + 1), Point2(get_size().x, get_size().y + 1), get_theme_color(SNAME("guide_color"), SNAME("Tree")));
140
} break;
141
}
142
}
143
144
ProjectList *ProjectListItemControl::get_list() const {
145
if (!is_inside_tree()) {
146
return nullptr;
147
}
148
ProjectList *pl = Object::cast_to<ProjectList>(get_parent()->get_parent());
149
return pl;
150
}
151
152
void ProjectListItemControl::_accessibility_action_scroll_into_view(const Variant &p_data) {
153
ProjectList *pl = get_list();
154
if (pl) {
155
int idx = pl->get_index(this);
156
if (idx >= 0) {
157
pl->ensure_project_visible(idx);
158
}
159
}
160
}
161
162
void ProjectListItemControl::_accessibility_action_open(const Variant &p_data) {
163
ProjectList *pl = get_list();
164
if (pl && !pl->project_opening_initiated) {
165
pl->emit_signal(SNAME(ProjectList::SIGNAL_PROJECT_ASK_OPEN));
166
}
167
}
168
169
void ProjectListItemControl::_accessibility_action_focus(const Variant &p_data) {
170
ProjectList *pl = get_list();
171
if (pl) {
172
int idx = pl->get_index(this);
173
if (idx >= 0) {
174
pl->ensure_project_visible(idx);
175
pl->select_project(idx);
176
}
177
}
178
}
179
180
void ProjectListItemControl::_accessibility_action_blur(const Variant &p_data) {
181
ProjectList *pl = get_list();
182
if (pl) {
183
int idx = pl->get_index(this);
184
if (idx >= 0) {
185
pl->ensure_project_visible(idx);
186
pl->deselect_project(idx);
187
}
188
}
189
}
190
191
void ProjectListItemControl::_favorite_button_pressed() {
192
emit_signal(SNAME("favorite_pressed"));
193
}
194
195
void ProjectListItemControl::_explore_button_pressed() {
196
emit_signal(SNAME("explore_pressed"));
197
}
198
199
void ProjectListItemControl::set_project_title(const String &p_title) {
200
project_title->set_text(p_title);
201
project_title->set_accessibility_name(TTRC("Project Name"));
202
queue_accessibility_update();
203
}
204
205
void ProjectListItemControl::set_project_path(const String &p_path) {
206
project_path->set_text(p_path);
207
project_path->set_accessibility_name(TTRC("Project Path"));
208
queue_accessibility_update();
209
}
210
211
void ProjectListItemControl::set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list) {
212
for (const String &tag : p_tags) {
213
ProjectTag *tag_control = memnew(ProjectTag(tag));
214
tag_container->add_child(tag_control);
215
tag_control->connect_button_to(callable_mp(p_parent_list, &ProjectList::add_search_tag).bind(tag));
216
}
217
}
218
219
void ProjectListItemControl::set_project_icon(const Ref<Texture2D> &p_icon) {
220
icon_needs_reload = false;
221
222
// The default project icon is 128×128 to look crisp on hiDPI displays,
223
// but we want the actual displayed size to be 64×64 on loDPI displays.
224
project_icon->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
225
project_icon->set_custom_minimum_size(Size2(64, 64) * EDSCALE);
226
project_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
227
228
project_icon->set_texture(p_icon);
229
}
230
231
void ProjectListItemControl::set_last_edited_info(const String &p_info) {
232
last_edited_info->set_text(p_info);
233
}
234
235
void ProjectListItemControl::set_project_version(const String &p_info) {
236
project_version->set_text(p_info);
237
}
238
239
void ProjectListItemControl::set_unsupported_features(PackedStringArray p_features) {
240
if (p_features.size() > 0) {
241
String tooltip_text = "";
242
for (int i = 0; i < p_features.size(); i++) {
243
if (ProjectList::project_feature_looks_like_version(p_features[i])) {
244
PackedStringArray project_version_split = p_features[i].split(".");
245
int project_version_major = 0, project_version_minor = 0;
246
if (project_version_split.size() >= 2) {
247
project_version_major = project_version_split[0].to_int();
248
project_version_minor = project_version_split[1].to_int();
249
}
250
if (GODOT_VERSION_MAJOR != project_version_major || GODOT_VERSION_MINOR <= project_version_minor) {
251
// Don't show a warning if the project was last edited in a previous minor version.
252
tooltip_text += TTR("This project was last edited in a different Godot version: ") + p_features[i] + "\n";
253
}
254
p_features.remove_at(i);
255
i--;
256
}
257
}
258
if (p_features.size() > 0) {
259
String unsupported_features_str = String(", ").join(p_features);
260
tooltip_text += TTR("This project uses features unsupported by the current build:") + "\n" + unsupported_features_str;
261
}
262
if (tooltip_text.is_empty()) {
263
return;
264
}
265
project_version->set_tooltip_text(tooltip_text);
266
project_unsupported_features->set_focus_mode(FOCUS_ACCESSIBILITY);
267
project_unsupported_features->set_tooltip_text(tooltip_text);
268
project_unsupported_features->show();
269
} else {
270
project_unsupported_features->hide();
271
}
272
}
273
274
bool ProjectListItemControl::should_load_project_icon() const {
275
return icon_needs_reload;
276
}
277
278
void ProjectListItemControl::set_selected(bool p_selected) {
279
is_selected = p_selected;
280
queue_redraw();
281
queue_accessibility_update();
282
}
283
284
void ProjectListItemControl::set_is_favorite(bool p_favorite) {
285
favorite_button->set_modulate(p_favorite ? Color(1, 1, 1, 1) : Color(1, 1, 1, 0.2));
286
}
287
288
void ProjectListItemControl::set_is_missing(bool p_missing) {
289
project_is_missing = p_missing;
290
291
if (project_is_missing) {
292
project_icon->set_modulate(Color(1, 1, 1, 0.5));
293
294
explore_button->set_button_icon(get_editor_theme_icon(SNAME("FileBroken")));
295
explore_button->set_tooltip_text(TTRC("Error: Project is missing on the filesystem."));
296
} else {
297
#if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
298
explore_button->set_button_icon(get_editor_theme_icon(SNAME("Load")));
299
explore_button->set_tooltip_text(TTRC("Show in File Manager"));
300
#else
301
// Opening the system file manager is not supported on the Android and web editors.
302
explore_button->hide();
303
#endif
304
}
305
}
306
307
void ProjectListItemControl::set_is_grayed(bool p_grayed) {
308
if (p_grayed) {
309
main_vbox->set_modulate(Color(1, 1, 1, 0.5));
310
// Don't make the icon less prominent if the parent is already grayed out.
311
explore_button->set_modulate(Color(1, 1, 1, 1.0));
312
} else {
313
main_vbox->set_modulate(Color(1, 1, 1, 1.0));
314
explore_button->set_modulate(Color(1, 1, 1, 0.5));
315
}
316
}
317
318
void ProjectListItemControl::_bind_methods() {
319
ADD_SIGNAL(MethodInfo("favorite_pressed"));
320
ADD_SIGNAL(MethodInfo("explore_pressed"));
321
}
322
323
ProjectListItemControl::ProjectListItemControl() {
324
set_focus_mode(FocusMode::FOCUS_ALL);
325
set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
326
327
VBoxContainer *favorite_box = memnew(VBoxContainer);
328
favorite_box->set_alignment(BoxContainer::ALIGNMENT_CENTER);
329
add_child(favorite_box);
330
331
favorite_button = memnew(TextureButton);
332
favorite_button->set_name("FavoriteButton");
333
favorite_button->set_tooltip_text(TTRC("Add to favorites"));
334
favorite_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_ALWAYS);
335
// This makes the project's "hover" style display correctly when hovering the favorite icon.
336
favorite_button->set_mouse_filter(MOUSE_FILTER_PASS);
337
favorite_box->add_child(favorite_button);
338
favorite_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectListItemControl::_favorite_button_pressed));
339
340
project_icon = memnew(TextureRect);
341
project_icon->set_name("ProjectIcon");
342
project_icon->set_v_size_flags(SIZE_SHRINK_CENTER);
343
add_child(project_icon);
344
345
main_vbox = memnew(VBoxContainer);
346
main_vbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
347
add_child(main_vbox);
348
349
Control *ec = memnew(Control);
350
ec->set_custom_minimum_size(Size2(0, 1));
351
ec->set_mouse_filter(MOUSE_FILTER_PASS);
352
main_vbox->add_child(ec);
353
354
// Top half, title, tags and unsupported features labels.
355
{
356
HBoxContainer *title_hb = memnew(HBoxContainer);
357
main_vbox->add_child(title_hb);
358
359
project_title = memnew(Label);
360
project_title->set_focus_mode(FOCUS_ACCESSIBILITY);
361
project_title->set_name("ProjectName");
362
project_title->set_h_size_flags(Control::SIZE_EXPAND_FILL);
363
project_title->set_clip_text(true);
364
title_hb->add_child(project_title);
365
366
tag_container = memnew(HBoxContainer);
367
title_hb->add_child(tag_container);
368
369
Control *spacer = memnew(Control);
370
spacer->set_custom_minimum_size(Size2(10, 10));
371
title_hb->add_child(spacer);
372
}
373
374
// Bottom half, containing the path and view folder button.
375
{
376
HBoxContainer *path_hb = memnew(HBoxContainer);
377
path_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
378
main_vbox->add_child(path_hb);
379
380
explore_button = memnew(Button);
381
explore_button->set_name("ExploreButton");
382
explore_button->set_tooltip_auto_translate_mode(AUTO_TRANSLATE_MODE_ALWAYS);
383
explore_button->set_tooltip_text(TTRC("Open in file manager"));
384
explore_button->set_flat(true);
385
path_hb->add_child(explore_button);
386
explore_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectListItemControl::_explore_button_pressed));
387
388
project_path = memnew(Label);
389
project_path->set_name("ProjectPath");
390
project_path->set_focus_mode(FOCUS_ACCESSIBILITY);
391
project_path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
392
project_path->set_clip_text(true);
393
project_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
394
project_path->set_modulate(Color(1, 1, 1, 0.5));
395
path_hb->add_child(project_path);
396
397
project_unsupported_features = memnew(TextureRect);
398
project_unsupported_features->set_name("ProjectUnsupportedFeatures");
399
project_unsupported_features->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
400
path_hb->add_child(project_unsupported_features);
401
project_unsupported_features->hide();
402
403
project_version = memnew(Label);
404
project_version->set_focus_mode(FOCUS_ACCESSIBILITY);
405
project_version->set_name("ProjectVersion");
406
project_version->set_mouse_filter(Control::MOUSE_FILTER_PASS);
407
path_hb->add_child(project_version);
408
409
last_edited_info = memnew(Label);
410
last_edited_info->set_focus_mode(FOCUS_ACCESSIBILITY);
411
last_edited_info->set_name("LastEditedInfo");
412
last_edited_info->set_mouse_filter(Control::MOUSE_FILTER_PASS);
413
last_edited_info->set_tooltip_auto_translate_mode(AUTO_TRANSLATE_MODE_ALWAYS);
414
last_edited_info->set_tooltip_text(TTRC("Last edited timestamp"));
415
last_edited_info->set_modulate(Color(1, 1, 1, 0.5));
416
path_hb->add_child(last_edited_info);
417
418
Control *spacer = memnew(Control);
419
spacer->set_custom_minimum_size(Size2(10, 10));
420
path_hb->add_child(spacer);
421
}
422
}
423
424
struct ProjectListComparator {
425
ProjectList::FilterOption order_option = ProjectList::FilterOption::EDIT_DATE;
426
427
// operator<
428
_FORCE_INLINE_ bool operator()(const ProjectList::Item &a, const ProjectList::Item &b) const {
429
if (a.favorite && !b.favorite) {
430
return true;
431
}
432
if (b.favorite && !a.favorite) {
433
return false;
434
}
435
switch (order_option) {
436
case ProjectList::PATH:
437
return a.path < b.path;
438
case ProjectList::EDIT_DATE:
439
return a.last_edited > b.last_edited;
440
case ProjectList::TAGS:
441
return a.tag_sort_string < b.tag_sort_string;
442
default:
443
return a.project_name < b.project_name;
444
}
445
}
446
};
447
448
// Helpers.
449
450
bool ProjectList::project_feature_looks_like_version(const String &p_feature) {
451
return p_feature.contains_char('.') && p_feature.substr(0, 3).is_numeric();
452
}
453
454
// Notifications.
455
456
void ProjectList::_notification(int p_what) {
457
switch (p_what) {
458
case NOTIFICATION_TRANSLATION_CHANGED: {
459
if (is_ready()) {
460
// FIXME: Technically this only needs to update some dynamic texts, not the whole list.
461
update_project_list();
462
}
463
} break;
464
465
case NOTIFICATION_PROCESS: {
466
// Load icons as a coroutine to speed up launch when you have hundreds of projects.
467
if (_icon_load_index < _projects.size()) {
468
Item &item = _projects.write[_icon_load_index];
469
if (item.control->should_load_project_icon()) {
470
_load_project_icon(_icon_load_index);
471
}
472
_icon_load_index++;
473
474
// Scan directories in thread to avoid blocking the window.
475
} else if (scan_data && scan_data->scan_in_progress.is_set()) {
476
// Wait for the thread.
477
} else {
478
set_process(false);
479
if (scan_data) {
480
_scan_finished();
481
}
482
}
483
} break;
484
485
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
486
RID ae = get_accessibility_element();
487
ERR_FAIL_COND(ae.is_null());
488
489
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_LIST_BOX);
490
DisplayServer::get_singleton()->accessibility_update_set_list_item_count(ae, _projects.size());
491
DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_MULTISELECTABLE, false);
492
}
493
}
494
}
495
496
// Projects scan.
497
498
void ProjectList::_scan_thread(void *p_scan_data) {
499
ScanData *scan_data = static_cast<ScanData *>(p_scan_data);
500
501
for (const String &base_path : scan_data->paths_to_scan) {
502
print_verbose(vformat("Scanning for projects in \"%s\".", base_path));
503
_scan_folder_recursive(base_path, &scan_data->found_projects, scan_data->scan_in_progress);
504
505
if (!scan_data->scan_in_progress.is_set()) {
506
print_verbose("Scan aborted.");
507
break;
508
}
509
}
510
print_verbose(vformat("Found %d project(s).", scan_data->found_projects.size()));
511
scan_data->scan_in_progress.clear();
512
}
513
514
void ProjectList::_scan_finished() {
515
if (scan_data->scan_in_progress.is_set()) {
516
// Abort scanning.
517
scan_data->scan_in_progress.clear();
518
}
519
520
scan_data->thread->wait_to_finish();
521
memdelete(scan_data->thread);
522
if (scan_progress) {
523
scan_progress->hide();
524
}
525
526
for (const String &E : scan_data->found_projects) {
527
add_project(E, false);
528
}
529
memdelete(scan_data);
530
scan_data = nullptr;
531
532
save_config();
533
534
if (ProjectManager::get_singleton()->is_initialized()) {
535
update_project_list();
536
}
537
}
538
539
// Initialization & loading.
540
541
void ProjectList::_migrate_config() {
542
// Proposal #1637 moved the project list from editor settings to a separate config file
543
// If the new config file doesn't exist, populate it from EditorSettings
544
if (FileAccess::exists(_config_path)) {
545
return;
546
}
547
548
List<PropertyInfo> properties;
549
EditorSettings::get_singleton()->get_property_list(&properties);
550
551
for (const PropertyInfo &E : properties) {
552
// This is actually something like "projects/C:::Documents::Godot::Projects::MyGame"
553
String property_key = E.name;
554
if (!property_key.begins_with("projects/")) {
555
continue;
556
}
557
558
String path = EDITOR_GET(property_key);
559
print_line("Migrating legacy project '" + path + "'.");
560
561
String favoriteKey = "favorite_projects/" + property_key.get_slicec('/', 1);
562
bool favorite = EditorSettings::get_singleton()->has_setting(favoriteKey);
563
add_project(path, favorite);
564
if (favorite) {
565
EditorSettings::get_singleton()->erase(favoriteKey);
566
}
567
EditorSettings::get_singleton()->erase(property_key);
568
}
569
570
save_config();
571
}
572
573
void ProjectList::save_config() {
574
_config.save(_config_path);
575
}
576
577
// Load project data from p_property_key and return it in a ProjectList::Item.
578
// p_favorite is passed directly into the Item.
579
ProjectList::Item ProjectList::load_project_data(const String &p_path, bool p_favorite) {
580
String conf = p_path.path_join("project.godot");
581
bool grayed = false;
582
bool missing = false;
583
bool recovery_mode = false;
584
585
Ref<ConfigFile> cf = memnew(ConfigFile);
586
Error cf_err = cf->load(conf);
587
588
int config_version = 0;
589
String cf_project_name;
590
String project_name = TTR("Unnamed Project");
591
if (cf_err == OK) {
592
cf_project_name = cf->get_value("application", "config/name", "");
593
if (!cf_project_name.is_empty()) {
594
project_name = cf_project_name.xml_unescape();
595
}
596
config_version = (int)cf->get_value("", "config_version", 0);
597
}
598
599
if (config_version > ProjectSettings::CONFIG_VERSION) {
600
// Comes from an incompatible (more recent) Godot version, gray it out.
601
grayed = true;
602
}
603
604
const String description = cf->get_value("application", "config/description", "");
605
const PackedStringArray tags = cf->get_value("application", "config/tags", PackedStringArray());
606
const String main_scene = cf->get_value("application", "run/main_scene", "");
607
608
String icon = cf->get_value("application", "config/icon", "");
609
if (icon.begins_with("uid://")) {
610
Error err;
611
Ref<FileAccess> file = FileAccess::open(p_path.path_join(".godot/uid_cache.bin"), FileAccess::READ, &err);
612
if (err == OK) {
613
icon = ResourceUID::get_path_from_cache(file, icon);
614
if (icon.is_empty()) {
615
WARN_PRINT(vformat("Could not load icon from UID for project at path \"%s\". Make sure UID cache exists.", p_path));
616
}
617
} else {
618
// Cache does not exist yet, so ignore and fallback to default icon.
619
icon = "";
620
}
621
}
622
623
PackedStringArray project_features = cf->get_value("application", "config/features", PackedStringArray());
624
PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features);
625
626
String project_version = "?";
627
for (int i = 0; i < project_features.size(); i++) {
628
if (ProjectList::project_feature_looks_like_version(project_features[i])) {
629
project_version = project_features[i];
630
break;
631
}
632
}
633
634
if (config_version < ProjectSettings::CONFIG_VERSION) {
635
// Previous versions may not have unsupported features.
636
if (config_version == 4) {
637
unsupported_features.push_back("3.x");
638
project_version = "3.x";
639
} else {
640
unsupported_features.push_back(TTR("Unknown version"));
641
}
642
}
643
644
uint64_t last_edited = 0;
645
if (cf_err == OK) {
646
// The modification date marks the date the project was last edited.
647
// This is because the `project.godot` file will always be modified
648
// when editing a project (but not when running it).
649
last_edited = FileAccess::get_modified_time(conf);
650
651
String fscache = p_path.path_join(".fscache");
652
if (FileAccess::exists(fscache)) {
653
uint64_t cache_modified = FileAccess::get_modified_time(fscache);
654
if (cache_modified > last_edited) {
655
last_edited = cache_modified;
656
}
657
}
658
} else {
659
grayed = true;
660
missing = true;
661
}
662
663
for (const String &tag : tags) {
664
ProjectManager::get_singleton()->add_new_tag(tag);
665
}
666
667
// We can't use OS::get_user_dir() because it attempts to load paths from the current loaded project through ProjectSettings,
668
// while here we're parsing project files externally. Therefore, we have to replicate its behavior.
669
String user_dir;
670
if (!cf_project_name.is_empty()) {
671
String appname = OS::get_singleton()->get_safe_dir_name(cf_project_name);
672
bool use_custom_dir = cf->get_value("application", "config/use_custom_user_dir", false);
673
if (use_custom_dir) {
674
String custom_dir = OS::get_singleton()->get_safe_dir_name(cf->get_value("application", "config/custom_user_dir_name", ""), true);
675
if (custom_dir.is_empty()) {
676
custom_dir = appname;
677
}
678
user_dir = custom_dir;
679
} else {
680
user_dir = OS::get_singleton()->get_godot_dir_name().path_join("app_userdata").path_join(appname);
681
}
682
} else {
683
user_dir = OS::get_singleton()->get_godot_dir_name().path_join("app_userdata").path_join("[unnamed project]");
684
}
685
686
String recovery_mode_lock_file = OS::get_singleton()->get_user_data_dir(user_dir).path_join(".recovery_mode_lock");
687
recovery_mode = FileAccess::exists(recovery_mode_lock_file);
688
689
return Item(project_name, description, project_version, tags, p_path, icon, main_scene, unsupported_features, last_edited, p_favorite, grayed, missing, recovery_mode, config_version);
690
}
691
692
void ProjectList::_update_icons_async() {
693
_icon_load_index = 0;
694
set_process(true);
695
}
696
697
void ProjectList::_load_project_icon(int p_index) {
698
Item &item = _projects.write[p_index];
699
700
Ref<Texture2D> default_icon = get_editor_theme_icon(SNAME("DefaultProjectIcon"));
701
Ref<Texture2D> icon;
702
if (!item.icon.is_empty()) {
703
Ref<Image> img;
704
img.instantiate();
705
Error err = img->load(item.icon.replace_first("res://", item.path + "/"));
706
if (err == OK) {
707
img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS);
708
icon = ImageTexture::create_from_image(img);
709
}
710
}
711
if (icon.is_null()) {
712
icon = default_icon;
713
}
714
715
item.control->set_project_icon(icon);
716
}
717
718
// Project list updates.
719
720
void ProjectList::update_project_list() {
721
// This is a full, hard reload of the list. Don't call this unless really required, it's expensive.
722
// If you have 150 projects, it may read through 150 files on your disk at once + load 150 icons.
723
// FIXME: Does it really have to be a full, hard reload? Runtime updates should be made much cheaper.
724
725
if (ProjectManager::get_singleton()->is_initialized()) {
726
// Clear whole list
727
for (int i = 0; i < _projects.size(); ++i) {
728
Item &project = _projects.write[i];
729
CRASH_COND(project.control == nullptr);
730
memdelete(project.control); // Why not queue_free()?
731
}
732
733
_projects.clear();
734
_last_clicked = "";
735
_selected_project_paths.clear();
736
737
load_project_list();
738
}
739
740
// Create controls
741
for (int i = 0; i < _projects.size(); ++i) {
742
_create_project_item_control(i);
743
}
744
745
sort_projects();
746
_update_icons_async();
747
update_dock_menu();
748
749
set_v_scroll(0);
750
emit_signal(SNAME(SIGNAL_LIST_CHANGED));
751
queue_accessibility_update();
752
}
753
754
void ProjectList::sort_projects() {
755
SortArray<Item, ProjectListComparator> sorter;
756
sorter.compare.order_option = _order_option;
757
sorter.sort(_projects.ptrw(), _projects.size());
758
759
String search_term;
760
PackedStringArray tags;
761
762
if (!_search_term.is_empty()) {
763
PackedStringArray search_parts = _search_term.split(" ");
764
if (search_parts.size() > 1 || search_parts[0].begins_with("tag:")) {
765
PackedStringArray remaining;
766
for (const String &part : search_parts) {
767
if (part.begins_with("tag:")) {
768
tags.push_back(part.get_slicec(':', 1));
769
} else {
770
remaining.append(part);
771
}
772
}
773
search_term = String(" ").join(remaining); // Search term without tags.
774
} else {
775
search_term = _search_term;
776
}
777
}
778
779
for (int i = 0; i < _projects.size(); ++i) {
780
Item &item = _projects.write[i];
781
782
bool item_visible = true;
783
if (!_search_term.is_empty()) {
784
String search_path;
785
if (search_term.contains_char('/')) {
786
// Search path will match the whole path
787
search_path = item.path;
788
} else {
789
// Search path will only match the last path component to make searching more strict
790
search_path = item.path.get_file();
791
}
792
793
bool missing_tags = false;
794
for (const String &tag : tags) {
795
if (!item.tags.has(tag)) {
796
missing_tags = true;
797
break;
798
}
799
}
800
801
// When searching, display projects whose name or path contain the search term and whose tags match the searched tags.
802
item_visible = !missing_tags && (search_term.is_empty() || item.project_name.containsn(search_term) || search_path.containsn(search_term));
803
}
804
805
item.control->set_visible(item_visible);
806
}
807
808
for (int i = 0; i < _projects.size(); ++i) {
809
Item &item = _projects.write[i];
810
item.control->get_parent()->move_child(item.control, i);
811
}
812
813
// Rewind the coroutine because order of projects changed
814
_update_icons_async();
815
update_dock_menu();
816
queue_accessibility_update();
817
}
818
819
int ProjectList::get_project_count() const {
820
return _projects.size();
821
}
822
823
void ProjectList::find_projects(const String &p_path) {
824
PackedStringArray paths = { p_path };
825
find_projects_multiple(paths);
826
}
827
828
void ProjectList::find_projects_multiple(const PackedStringArray &p_paths) {
829
if (!scan_progress && is_inside_tree()) {
830
scan_progress = memnew(AcceptDialog);
831
scan_progress->set_title(TTRC("Scanning"));
832
scan_progress->set_ok_button_text(TTRC("Cancel"));
833
834
VBoxContainer *vb = memnew(VBoxContainer);
835
scan_progress->add_child(vb);
836
837
Label *label = memnew(Label);
838
label->set_text(TTRC("Scanning for projects..."));
839
vb->add_child(label);
840
841
ProgressBar *progress = memnew(ProgressBar);
842
progress->set_indeterminate(true);
843
vb->add_child(progress);
844
845
add_child(scan_progress);
846
scan_progress->connect(SceneStringName(confirmed), callable_mp(this, &ProjectList::_scan_finished));
847
scan_progress->connect("canceled", callable_mp(this, &ProjectList::_scan_finished));
848
}
849
850
scan_data = memnew(ScanData);
851
scan_data->paths_to_scan = p_paths;
852
scan_data->scan_in_progress.set();
853
854
scan_data->thread = memnew(Thread);
855
scan_data->thread->start(_scan_thread, scan_data);
856
857
if (scan_progress) {
858
scan_progress->reset_size();
859
scan_progress->popup_centered();
860
}
861
set_process(true);
862
}
863
864
void ProjectList::load_project_list() {
865
_config.load(_config_path);
866
Vector<String> sections = _config.get_sections();
867
868
for (const String &path : sections) {
869
bool favorite = _config.get_value(path, "favorite", false);
870
_projects.push_back(load_project_data(path, favorite));
871
}
872
}
873
874
void ProjectList::_scan_folder_recursive(const String &p_path, List<String> *r_projects, const SafeFlag &p_scan_active) {
875
if (!p_scan_active.is_set()) {
876
return;
877
}
878
879
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
880
Error error = da->change_dir(p_path);
881
ERR_FAIL_COND_MSG(error != OK, vformat("Failed to open the path \"%s\" for scanning (code %d).", p_path, error));
882
883
da->list_dir_begin();
884
String n = da->get_next();
885
while (!n.is_empty()) {
886
if (!p_scan_active.is_set()) {
887
return;
888
}
889
890
if (da->current_is_dir() && n[0] != '.') {
891
_scan_folder_recursive(da->get_current_dir().path_join(n), r_projects, p_scan_active);
892
} else if (n == "project.godot") {
893
r_projects->push_back(da->get_current_dir());
894
}
895
n = da->get_next();
896
}
897
da->list_dir_end();
898
}
899
900
// Project list items.
901
902
void ProjectList::add_project(const String &dir_path, bool favorite) {
903
if (!_config.has_section(dir_path)) {
904
_config.set_value(dir_path, "favorite", favorite);
905
}
906
queue_accessibility_update();
907
}
908
909
void ProjectList::set_project_version(const String &p_project_path, int p_version) {
910
for (ProjectList::Item &E : _projects) {
911
if (E.path == p_project_path) {
912
E.version = p_version;
913
break;
914
}
915
}
916
}
917
918
int ProjectList::refresh_project(const String &dir_path) {
919
// Reloads information about a specific project.
920
// If it wasn't loaded and should be in the list, it is added (i.e new project).
921
// If it isn't in the list anymore, it is removed.
922
// If it is in the list but doesn't exist anymore, it is marked as missing.
923
924
bool should_be_in_list = _config.has_section(dir_path);
925
bool is_favourite = _config.get_value(dir_path, "favorite", false);
926
927
bool was_selected = _selected_project_paths.has(dir_path);
928
929
// Remove item in any case
930
for (int i = 0; i < _projects.size(); ++i) {
931
const Item &existing_item = _projects[i];
932
if (existing_item.path == dir_path) {
933
_remove_project(i, false);
934
break;
935
}
936
}
937
938
int index = -1;
939
if (should_be_in_list) {
940
// Recreate it with updated info
941
942
Item item = load_project_data(dir_path, is_favourite);
943
944
_projects.push_back(item);
945
_create_project_item_control(_projects.size() - 1);
946
947
sort_projects();
948
949
for (int i = 0; i < _projects.size(); ++i) {
950
if (_projects[i].path == dir_path) {
951
if (was_selected) {
952
select_project(i);
953
ensure_project_visible(i);
954
}
955
_load_project_icon(i);
956
957
index = i;
958
break;
959
}
960
}
961
}
962
963
return index;
964
}
965
966
int ProjectList::get_index(const ProjectListItemControl *p_control) const {
967
for (int i = 0; i < _projects.size(); ++i) {
968
if (_projects[i].control == p_control) {
969
return i;
970
}
971
}
972
return -1;
973
}
974
975
void ProjectList::ensure_project_visible(int p_index) {
976
const Item &item = _projects[p_index];
977
ensure_control_visible(item.control);
978
}
979
980
void ProjectList::_create_project_item_control(int p_index) {
981
// Will be added last in the list, so make sure indexes match
982
ERR_FAIL_COND(p_index != project_list_vbox->get_child_count());
983
984
Item &item = _projects.write[p_index];
985
ERR_FAIL_COND(item.control != nullptr); // Already created
986
987
ProjectListItemControl *hb = memnew(ProjectListItemControl);
988
hb->add_theme_constant_override("separation", 10 * EDSCALE);
989
990
hb->set_project_title(!item.missing ? item.project_name : TTR("Missing Project"));
991
hb->set_project_path(item.path);
992
hb->set_tooltip_text(item.description);
993
hb->set_tags(item.tags, this);
994
hb->set_unsupported_features(item.unsupported_features.duplicate());
995
hb->set_project_version(item.project_version);
996
hb->set_last_edited_info(item.get_last_edited_string());
997
998
hb->set_is_favorite(item.favorite);
999
hb->set_is_missing(item.missing);
1000
hb->set_is_grayed(item.grayed);
1001
1002
hb->connect(SceneStringName(gui_input), callable_mp(this, &ProjectList::_list_item_input).bind(hb));
1003
hb->connect("favorite_pressed", callable_mp(this, &ProjectList::_on_favorite_pressed).bind(hb));
1004
1005
#if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
1006
hb->connect("explore_pressed", callable_mp(this, &ProjectList::_on_explore_pressed).bind(item.path));
1007
#endif
1008
1009
project_list_vbox->add_child(hb);
1010
item.control = hb;
1011
}
1012
1013
void ProjectList::_toggle_project(int p_index) {
1014
// This methods adds to the selection or removes from the
1015
// selection.
1016
Item &item = _projects.write[p_index];
1017
1018
if (_selected_project_paths.has(item.path)) {
1019
_deselect_project_nocheck(p_index);
1020
} else {
1021
_select_project_nocheck(p_index);
1022
}
1023
}
1024
1025
void ProjectList::_remove_project(int p_index, bool p_update_config) {
1026
const Item item = _projects[p_index]; // Take a copy
1027
1028
_selected_project_paths.erase(item.path);
1029
1030
if (_last_clicked == item.path) {
1031
_last_clicked = "";
1032
}
1033
1034
memdelete(item.control);
1035
_projects.remove_at(p_index);
1036
1037
if (p_update_config) {
1038
_config.erase_section(item.path);
1039
// Not actually saving the file, in case you are doing more changes to settings
1040
}
1041
1042
queue_accessibility_update();
1043
update_dock_menu();
1044
}
1045
1046
void ProjectList::_list_item_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
1047
Ref<InputEventMouseButton> mb = p_ev;
1048
int clicked_index = p_hb->get_index();
1049
const Item &clicked_project = _projects[clicked_index];
1050
1051
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
1052
if (mb->is_shift_pressed() && _selected_project_paths.size() > 0 && !_last_clicked.is_empty() && clicked_project.path != _last_clicked) {
1053
int anchor_index = -1;
1054
for (int i = 0; i < _projects.size(); ++i) {
1055
const Item &p = _projects[i];
1056
if (p.path == _last_clicked) {
1057
anchor_index = p.control->get_index();
1058
break;
1059
}
1060
}
1061
CRASH_COND(anchor_index == -1);
1062
_select_project_range(anchor_index, clicked_index);
1063
1064
} else if (mb->is_command_or_control_pressed()) {
1065
_toggle_project(clicked_index);
1066
1067
} else {
1068
_last_clicked = clicked_project.path;
1069
select_project(clicked_index);
1070
}
1071
1072
emit_signal(SNAME(SIGNAL_SELECTION_CHANGED));
1073
1074
// Do not allow opening a project more than once using a single project manager instance.
1075
// Opening the same project in several editor instances at once can lead to various issues.
1076
if (!mb->is_command_or_control_pressed() && mb->is_double_click() && !project_opening_initiated) {
1077
emit_signal(SNAME(SIGNAL_PROJECT_ASK_OPEN));
1078
}
1079
}
1080
}
1081
1082
void ProjectList::_on_favorite_pressed(Node *p_hb) {
1083
ProjectListItemControl *control = Object::cast_to<ProjectListItemControl>(p_hb);
1084
1085
int index = control->get_index();
1086
Item item = _projects.write[index]; // Take copy
1087
1088
item.favorite = !item.favorite;
1089
1090
_config.set_value(item.path, "favorite", item.favorite);
1091
save_config();
1092
1093
_projects.write[index] = item;
1094
1095
control->set_is_favorite(item.favorite);
1096
1097
sort_projects();
1098
1099
if (item.favorite) {
1100
for (int i = 0; i < _projects.size(); ++i) {
1101
if (_projects[i].path == item.path) {
1102
ensure_project_visible(i);
1103
break;
1104
}
1105
}
1106
}
1107
1108
update_dock_menu();
1109
}
1110
1111
void ProjectList::_on_explore_pressed(const String &p_path) {
1112
OS::get_singleton()->shell_show_in_file_manager(p_path, true);
1113
}
1114
1115
// Project list selection.
1116
1117
void ProjectList::_clear_project_selection() {
1118
Vector<Item> previous_selected_items = get_selected_projects();
1119
_selected_project_paths.clear();
1120
1121
for (int i = 0; i < previous_selected_items.size(); ++i) {
1122
previous_selected_items[i].control->set_selected(false);
1123
}
1124
queue_accessibility_update();
1125
}
1126
1127
void ProjectList::_select_project_nocheck(int p_index) {
1128
Item &item = _projects.write[p_index];
1129
_selected_project_paths.insert(item.path);
1130
item.control->set_selected(true);
1131
queue_accessibility_update();
1132
}
1133
1134
void ProjectList::_deselect_project_nocheck(int p_index) {
1135
Item &item = _projects.write[p_index];
1136
_selected_project_paths.erase(item.path);
1137
item.control->set_selected(false);
1138
queue_accessibility_update();
1139
}
1140
1141
inline void _sort_project_range(int &a, int &b) {
1142
if (a > b) {
1143
int temp = a;
1144
a = b;
1145
b = temp;
1146
}
1147
}
1148
1149
void ProjectList::_select_project_range(int p_begin, int p_end) {
1150
_clear_project_selection();
1151
1152
_sort_project_range(p_begin, p_end);
1153
for (int i = p_begin; i <= p_end; ++i) {
1154
_select_project_nocheck(i);
1155
}
1156
}
1157
1158
void ProjectList::select_project(int p_index) {
1159
// This method keeps only one project selected.
1160
_clear_project_selection();
1161
_select_project_nocheck(p_index);
1162
}
1163
1164
void ProjectList::deselect_project(int p_index) {
1165
_deselect_project_nocheck(p_index);
1166
}
1167
1168
void ProjectList::select_first_visible_project() {
1169
_clear_project_selection();
1170
1171
for (int i = 0; i < _projects.size(); i++) {
1172
if (_projects[i].control->is_visible()) {
1173
_select_project_nocheck(i);
1174
break;
1175
}
1176
}
1177
}
1178
1179
Vector<ProjectList::Item> ProjectList::get_selected_projects() const {
1180
Vector<Item> items;
1181
if (_selected_project_paths.is_empty()) {
1182
return items;
1183
}
1184
items.resize(_selected_project_paths.size());
1185
int j = 0;
1186
for (int i = 0; i < _projects.size(); ++i) {
1187
const Item &item = _projects[i];
1188
if (_selected_project_paths.has(item.path)) {
1189
items.write[j++] = item;
1190
}
1191
}
1192
ERR_FAIL_COND_V(j != items.size(), items);
1193
return items;
1194
}
1195
1196
const HashSet<String> &ProjectList::get_selected_project_keys() const {
1197
// Faster if that's all you need
1198
return _selected_project_paths;
1199
}
1200
1201
int ProjectList::get_single_selected_index() const {
1202
if (_selected_project_paths.is_empty()) {
1203
// Default selection
1204
return 0;
1205
}
1206
String key;
1207
if (_selected_project_paths.size() == 1) {
1208
// Only one selected
1209
key = *_selected_project_paths.begin();
1210
} else {
1211
// Multiple selected, consider the last clicked one as "main"
1212
key = _last_clicked;
1213
}
1214
for (int i = 0; i < _projects.size(); ++i) {
1215
if (_projects[i].path == key) {
1216
return i;
1217
}
1218
}
1219
return 0;
1220
}
1221
1222
void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
1223
if (_selected_project_paths.is_empty()) {
1224
return;
1225
}
1226
1227
for (int i = 0; i < _projects.size(); ++i) {
1228
Item &item = _projects.write[i];
1229
if (_selected_project_paths.has(item.path) && item.control->is_visible()) {
1230
_config.erase_section(item.path);
1231
1232
// Comment out for now until we have a better warning system to
1233
// ensure users delete their project only.
1234
//if (p_delete_project_contents) {
1235
// OS::get_singleton()->move_to_trash(item.path);
1236
//}
1237
1238
memdelete(item.control);
1239
_projects.remove_at(i);
1240
--i;
1241
}
1242
}
1243
1244
save_config();
1245
_selected_project_paths.clear();
1246
_last_clicked = "";
1247
1248
update_dock_menu();
1249
}
1250
1251
// Missing projects.
1252
1253
bool ProjectList::is_any_project_missing() const {
1254
for (int i = 0; i < _projects.size(); ++i) {
1255
if (_projects[i].missing) {
1256
return true;
1257
}
1258
}
1259
return false;
1260
}
1261
1262
void ProjectList::erase_missing_projects() {
1263
if (_projects.is_empty()) {
1264
return;
1265
}
1266
1267
int deleted_count = 0;
1268
int remaining_count = 0;
1269
1270
for (int i = 0; i < _projects.size(); ++i) {
1271
const Item &item = _projects[i];
1272
1273
if (item.missing) {
1274
_remove_project(i, true);
1275
--i;
1276
++deleted_count;
1277
1278
} else {
1279
++remaining_count;
1280
}
1281
}
1282
1283
print_line("Removed " + itos(deleted_count) + " projects from the list, remaining " + itos(remaining_count) + " projects");
1284
save_config();
1285
}
1286
1287
// Project list sorting and filtering.
1288
1289
void ProjectList::set_search_term(String p_search_term) {
1290
_search_term = p_search_term;
1291
}
1292
1293
void ProjectList::add_search_tag(const String &p_tag) {
1294
const String tag_string = "tag:" + p_tag;
1295
1296
int exists = _search_term.find(tag_string);
1297
if (exists > -1) {
1298
_search_term = _search_term.erase(exists, tag_string.length() + 1);
1299
} else if (_search_term.is_empty() || _search_term.ends_with(" ")) {
1300
_search_term += tag_string;
1301
} else {
1302
_search_term += " " + tag_string;
1303
}
1304
ProjectManager::get_singleton()->get_search_box()->set_text(_search_term);
1305
1306
sort_projects();
1307
}
1308
1309
void ProjectList::set_order_option(int p_option) {
1310
FilterOption selected = (FilterOption)p_option;
1311
EditorSettings::get_singleton()->set("project_manager/sorting_order", p_option);
1312
EditorSettings::get_singleton()->save();
1313
_order_option = selected;
1314
1315
sort_projects();
1316
}
1317
1318
// Global menu integration.
1319
1320
void ProjectList::update_dock_menu() {
1321
if (!NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
1322
return;
1323
}
1324
RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
1325
NativeMenu::get_singleton()->clear(dock_rid);
1326
1327
int favs_added = 0;
1328
int total_added = 0;
1329
for (int i = 0; i < _projects.size(); ++i) {
1330
if (!_projects[i].grayed && !_projects[i].missing) {
1331
if (_projects[i].favorite) {
1332
favs_added++;
1333
} else {
1334
if (favs_added != 0) {
1335
NativeMenu::get_singleton()->add_separator(dock_rid);
1336
}
1337
favs_added = 0;
1338
}
1339
NativeMenu::get_singleton()->add_item(dock_rid, _projects[i].project_name + " ( " + _projects[i].path + " )", callable_mp(this, &ProjectList::_global_menu_open_project), Callable(), i);
1340
total_added++;
1341
}
1342
}
1343
if (total_added != 0) {
1344
NativeMenu::get_singleton()->add_separator(dock_rid);
1345
}
1346
NativeMenu::get_singleton()->add_item(dock_rid, TTR("New Window"), callable_mp(this, &ProjectList::_global_menu_new_window));
1347
}
1348
1349
void ProjectList::_global_menu_new_window(const Variant &p_tag) {
1350
List<String> args;
1351
args.push_back("-p");
1352
OS::get_singleton()->create_instance(args);
1353
}
1354
1355
void ProjectList::_global_menu_open_project(const Variant &p_tag) {
1356
int idx = (int)p_tag;
1357
1358
if (idx >= 0 && idx < _projects.size()) {
1359
String conf = _projects[idx].path.path_join("project.godot");
1360
List<String> args;
1361
args.push_back(conf);
1362
OS::get_singleton()->create_instance(args);
1363
}
1364
}
1365
1366
// Object methods.
1367
1368
void ProjectList::_bind_methods() {
1369
ADD_SIGNAL(MethodInfo(SIGNAL_LIST_CHANGED));
1370
ADD_SIGNAL(MethodInfo(SIGNAL_SELECTION_CHANGED));
1371
ADD_SIGNAL(MethodInfo(SIGNAL_PROJECT_ASK_OPEN));
1372
}
1373
1374
ProjectList::ProjectList() {
1375
project_list_vbox = memnew(VBoxContainer);
1376
project_list_vbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1377
add_child(project_list_vbox);
1378
1379
_config_path = EditorPaths::get_singleton()->get_data_dir().path_join("projects.cfg");
1380
_migrate_config();
1381
}
1382
1383