Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/project_manager/project_list.h
9902 views
1
/**************************************************************************/
2
/* project_list.h */
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
#pragma once
32
33
#include "core/io/config_file.h"
34
#include "core/os/time.h"
35
#include "scene/gui/box_container.h"
36
#include "scene/gui/scroll_container.h"
37
38
class AcceptDialog;
39
class Button;
40
class Label;
41
class ProjectList;
42
class TextureButton;
43
class TextureRect;
44
45
class ProjectListItemControl : public HBoxContainer {
46
GDCLASS(ProjectListItemControl, HBoxContainer)
47
48
VBoxContainer *main_vbox = nullptr;
49
TextureButton *favorite_button = nullptr;
50
Button *explore_button = nullptr;
51
52
TextureRect *project_icon = nullptr;
53
Label *project_title = nullptr;
54
Label *project_path = nullptr;
55
Label *last_edited_info = nullptr;
56
Label *project_version = nullptr;
57
TextureRect *project_unsupported_features = nullptr;
58
HBoxContainer *tag_container = nullptr;
59
60
bool project_is_missing = false;
61
bool icon_needs_reload = true;
62
bool is_selected = false;
63
bool is_hovering = false;
64
65
void _favorite_button_pressed();
66
void _explore_button_pressed();
67
68
ProjectList *get_list() const;
69
70
void _accessibility_action_open(const Variant &p_data);
71
void _accessibility_action_scroll_into_view(const Variant &p_data);
72
void _accessibility_action_focus(const Variant &p_data);
73
void _accessibility_action_blur(const Variant &p_data);
74
75
protected:
76
void _notification(int p_what);
77
static void _bind_methods();
78
79
public:
80
void set_project_title(const String &p_title);
81
void set_project_path(const String &p_path);
82
void set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list);
83
void set_project_icon(const Ref<Texture2D> &p_icon);
84
void set_last_edited_info(const String &p_info);
85
void set_project_version(const String &p_version);
86
void set_unsupported_features(PackedStringArray p_features);
87
88
bool should_load_project_icon() const;
89
void set_selected(bool p_selected);
90
91
void set_is_favorite(bool p_favorite);
92
void set_is_missing(bool p_missing);
93
void set_is_grayed(bool p_grayed);
94
95
ProjectListItemControl();
96
};
97
98
class ProjectList : public ScrollContainer {
99
GDCLASS(ProjectList, ScrollContainer)
100
101
friend class ProjectManager;
102
friend class ProjectListItemControl;
103
104
public:
105
enum FilterOption {
106
EDIT_DATE,
107
NAME,
108
PATH,
109
TAGS,
110
};
111
112
// Can often be passed by copy.
113
struct Item {
114
String project_name;
115
String description;
116
String project_version;
117
PackedStringArray tags;
118
String tag_sort_string;
119
String path;
120
String icon;
121
String main_scene;
122
PackedStringArray unsupported_features;
123
uint64_t last_edited = 0;
124
bool favorite = false;
125
bool grayed = false;
126
bool missing = false;
127
bool recovery_mode = false;
128
int version = 0;
129
130
ProjectListItemControl *control = nullptr;
131
132
Item() {}
133
134
Item(const String &p_name,
135
const String &p_description,
136
const String &p_project_version,
137
const PackedStringArray &p_tags,
138
const String &p_path,
139
const String &p_icon,
140
const String &p_main_scene,
141
const PackedStringArray &p_unsupported_features,
142
uint64_t p_last_edited,
143
bool p_favorite,
144
bool p_grayed,
145
bool p_missing,
146
bool p_recovery_mode,
147
int p_version) {
148
project_name = p_name;
149
description = p_description;
150
project_version = p_project_version;
151
tags = p_tags;
152
path = p_path;
153
icon = p_icon;
154
main_scene = p_main_scene;
155
unsupported_features = p_unsupported_features;
156
last_edited = p_last_edited;
157
favorite = p_favorite;
158
grayed = p_grayed;
159
missing = p_missing;
160
recovery_mode = p_recovery_mode;
161
version = p_version;
162
163
control = nullptr;
164
165
PackedStringArray sorted_tags = tags;
166
sorted_tags.sort();
167
tag_sort_string = String().join(sorted_tags);
168
}
169
170
_FORCE_INLINE_ bool operator==(const Item &l) const {
171
return path == l.path;
172
}
173
174
String get_last_edited_string() const {
175
if (missing) {
176
return TTR("Missing Date");
177
}
178
179
OS::TimeZoneInfo tz = OS::get_singleton()->get_time_zone_info();
180
return Time::get_singleton()->get_datetime_string_from_unix_time(last_edited + tz.bias * 60, true);
181
}
182
};
183
184
private:
185
String _config_path;
186
ConfigFile _config;
187
188
Vector<Item> _projects;
189
190
int _icon_load_index = 0;
191
bool project_opening_initiated = false;
192
193
String _search_term;
194
FilterOption _order_option = FilterOption::EDIT_DATE;
195
HashSet<String> _selected_project_paths;
196
String _last_clicked; // Project key
197
198
VBoxContainer *project_list_vbox = nullptr;
199
200
// Projects scan.
201
202
struct ScanData {
203
Thread *thread = nullptr;
204
PackedStringArray paths_to_scan;
205
List<String> found_projects;
206
SafeFlag scan_in_progress;
207
};
208
ScanData *scan_data = nullptr;
209
AcceptDialog *scan_progress = nullptr;
210
211
static void _scan_thread(void *p_scan_data);
212
void _scan_finished();
213
214
// Initialization & loading.
215
216
void _migrate_config();
217
218
static Item load_project_data(const String &p_property_key, bool p_favorite);
219
void _update_icons_async();
220
void _load_project_icon(int p_index);
221
222
// Project list updates.
223
224
static void _scan_folder_recursive(const String &p_path, List<String> *r_projects, const SafeFlag &p_scan_active);
225
226
// Project list items.
227
228
void _create_project_item_control(int p_index);
229
void _toggle_project(int p_index);
230
void _remove_project(int p_index, bool p_update_settings);
231
232
void _list_item_input(const Ref<InputEvent> &p_ev, Node *p_hb);
233
void _on_favorite_pressed(Node *p_hb);
234
void _on_explore_pressed(const String &p_path);
235
236
// Project list selection.
237
238
void _clear_project_selection();
239
void _select_project_nocheck(int p_index);
240
void _deselect_project_nocheck(int p_index);
241
void _select_project_range(int p_begin, int p_end);
242
243
// Global menu integration.
244
245
void _global_menu_new_window(const Variant &p_tag);
246
void _global_menu_open_project(const Variant &p_tag);
247
248
protected:
249
void _notification(int p_what);
250
static void _bind_methods();
251
252
public:
253
static const char *SIGNAL_LIST_CHANGED;
254
static const char *SIGNAL_SELECTION_CHANGED;
255
static const char *SIGNAL_PROJECT_ASK_OPEN;
256
257
static bool project_feature_looks_like_version(const String &p_feature);
258
259
// Initialization & loading.
260
261
void save_config();
262
263
// Project list updates.
264
265
void load_project_list();
266
void update_project_list();
267
void sort_projects();
268
int get_project_count() const;
269
270
void find_projects(const String &p_path);
271
void find_projects_multiple(const PackedStringArray &p_paths);
272
273
// Project list items.
274
275
void add_project(const String &dir_path, bool favorite);
276
void set_project_version(const String &p_project_path, int version);
277
int refresh_project(const String &dir_path);
278
void ensure_project_visible(int p_index);
279
int get_index(const ProjectListItemControl *p_control) const;
280
281
// Project list selection.
282
283
void select_project(int p_index);
284
void deselect_project(int p_index);
285
void select_first_visible_project();
286
Vector<Item> get_selected_projects() const;
287
const HashSet<String> &get_selected_project_keys() const;
288
int get_single_selected_index() const;
289
void erase_selected_projects(bool p_delete_project_contents);
290
291
// Missing projects.
292
293
bool is_any_project_missing() const;
294
void erase_missing_projects();
295
296
// Project list sorting and filtering.
297
298
void set_search_term(String p_search_term);
299
void add_search_tag(const String &p_tag);
300
void set_order_option(int p_option);
301
302
// Global menu integration.
303
304
void update_dock_menu();
305
306
ProjectList();
307
};
308
309