Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/file_system/dependency_editor.h
21052 views
1
/**************************************************************************/
2
/* dependency_editor.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 "scene/gui/dialogs.h"
34
35
class EditorFileDialog;
36
class EditorFileSystemDirectory;
37
class ItemList;
38
class PopupMenu;
39
class Tree;
40
class TreeItem;
41
class VBoxContainer;
42
class LineEdit;
43
class MenuButton;
44
45
enum class DependencyEditorSortBy {
46
TYPE,
47
TYPE_REVERSE,
48
NAME,
49
NAME_REVERSE,
50
PATH,
51
PATH_REVERSE,
52
MAX,
53
};
54
55
enum class Column {
56
TYPE,
57
NAME,
58
PATH,
59
MAX,
60
};
61
62
class DependencyEditor : public AcceptDialog {
63
GDCLASS(DependencyEditor, AcceptDialog);
64
65
Tree *tree = nullptr;
66
Button *fixdeps = nullptr;
67
Label *warning_label = nullptr;
68
LineEdit *filter = nullptr;
69
MenuButton *menu_sort = nullptr;
70
71
EditorFileDialog *search = nullptr;
72
73
DependencyEditorSortBy sort_by = DependencyEditorSortBy::PATH;
74
String replacing;
75
String editing;
76
List<String> missing;
77
78
void _fix_and_find(EditorFileSystemDirectory *efsd, HashMap<String, HashMap<String, String>> &candidates);
79
80
void _searched(const String &p_path);
81
void _load_pressed(Object *p_item, int p_cell, int p_button, MouseButton p_mouse_button);
82
List<String> _filter_deps(const List<String> &p_deps);
83
void _fix_all();
84
void _update_list();
85
86
void _update_menu_sort();
87
void _sort_option_selected(int p_id);
88
void _update_file();
89
90
protected:
91
void _notification(int p_what);
92
93
public:
94
void edit(const String &p_path);
95
DependencyEditor();
96
};
97
98
class DependencyEditorOwners : public AcceptDialog {
99
GDCLASS(DependencyEditorOwners, AcceptDialog);
100
101
Label *owners_count = nullptr;
102
Label *empty = nullptr;
103
MarginContainer *owners_mc = nullptr;
104
ItemList *owners = nullptr;
105
PopupMenu *file_options = nullptr;
106
String editing;
107
108
void _fill_owners(EditorFileSystemDirectory *efsd);
109
110
void _list_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
111
void _select_file(int p_idx);
112
void _empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
113
void _file_option(int p_option);
114
115
private:
116
enum FileMenu {
117
FILE_MENU_OPEN,
118
};
119
120
public:
121
void show(const String &p_path);
122
DependencyEditorOwners();
123
};
124
125
class DependencyRemoveDialog : public ConfirmationDialog {
126
GDCLASS(DependencyRemoveDialog, ConfirmationDialog);
127
128
Label *text = nullptr;
129
Tree *owners = nullptr;
130
VBoxContainer *vb_owners = nullptr;
131
ItemList *files_to_delete_list = nullptr;
132
133
HashMap<String, String> all_remove_files;
134
Vector<String> dirs_to_delete;
135
Vector<String> files_to_delete;
136
137
struct RemovedDependency {
138
String file;
139
String file_type;
140
String dependency;
141
String dependency_folder;
142
143
bool operator<(const RemovedDependency &p_other) const {
144
if (dependency_folder.is_empty() != p_other.dependency_folder.is_empty()) {
145
return p_other.dependency_folder.is_empty();
146
} else {
147
return dependency < p_other.dependency;
148
}
149
}
150
};
151
152
LocalVector<StringName> path_project_settings;
153
154
void _find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder);
155
void _find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed);
156
void _find_localization_remaps_of_removed_files(Vector<RemovedDependency> &p_removed);
157
void _build_removed_dependency_tree(const Vector<RemovedDependency> &p_removed);
158
void _show_files_to_delete_list();
159
160
void ok_pressed() override;
161
162
static void _bind_methods();
163
164
public:
165
void show(const Vector<String> &p_folders, const Vector<String> &p_files);
166
DependencyRemoveDialog();
167
};
168
169
class DependencyErrorDialog : public ConfirmationDialog {
170
GDCLASS(DependencyErrorDialog, ConfirmationDialog);
171
172
StringName icon_name_fail;
173
StringName icon_name_check;
174
175
String for_file;
176
177
TreeItem *replacing_item = nullptr;
178
bool errors_fixed = false;
179
180
Tree *files = nullptr;
181
182
EditorFileDialog *replacement_file_dialog = nullptr;
183
DependencyEditor *deps_editor = nullptr;
184
185
void ok_pressed() override;
186
187
void _on_files_button_clicked(TreeItem *p_item, int p_column, int p_id, MouseButton p_button);
188
void _on_replacement_file_selected(const String &p_path);
189
void _check_for_resolved();
190
191
public:
192
void show(const String &p_for_file, const HashMap<String, HashSet<String>> &p_report);
193
194
DependencyErrorDialog();
195
};
196
197
class OrphanResourcesDialog : public ConfirmationDialog {
198
GDCLASS(OrphanResourcesDialog, ConfirmationDialog);
199
200
DependencyEditor *dep_edit = nullptr;
201
Tree *files = nullptr;
202
ConfirmationDialog *delete_confirm = nullptr;
203
void ok_pressed() override;
204
205
bool _fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent);
206
207
List<String> paths;
208
void _find_to_delete(TreeItem *p_item, List<String> &r_paths);
209
void _delete_confirm();
210
void _button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
211
212
void refresh();
213
214
public:
215
void show();
216
OrphanResourcesDialog();
217
};
218
219