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 | #ifndef DEPENDENCY_EDITOR_H |
32 | #define DEPENDENCY_EDITOR_H |
33 | |
34 | #include "scene/gui/dialogs.h" |
35 | #include "scene/gui/item_list.h" |
36 | #include "scene/gui/tab_container.h" |
37 | #include "scene/gui/tree.h" |
38 | |
39 | class EditorFileDialog; |
40 | class EditorFileSystemDirectory; |
41 | |
42 | class DependencyEditor : public AcceptDialog { |
43 | GDCLASS(DependencyEditor, AcceptDialog); |
44 | |
45 | Tree *tree = nullptr; |
46 | Button *fixdeps = nullptr; |
47 | |
48 | EditorFileDialog *search = nullptr; |
49 | |
50 | String replacing; |
51 | String editing; |
52 | List<String> missing; |
53 | |
54 | void _fix_and_find(EditorFileSystemDirectory *efsd, HashMap<String, HashMap<String, String>> &candidates); |
55 | |
56 | void _searched(const String &p_path); |
57 | void _load_pressed(Object *p_item, int p_cell, int p_button, MouseButton p_mouse_button); |
58 | void _fix_all(); |
59 | void _update_list(); |
60 | |
61 | void _update_file(); |
62 | |
63 | protected: |
64 | static void _bind_methods(); |
65 | |
66 | public: |
67 | void edit(const String &p_path); |
68 | DependencyEditor(); |
69 | }; |
70 | |
71 | class DependencyEditorOwners : public AcceptDialog { |
72 | GDCLASS(DependencyEditorOwners, AcceptDialog); |
73 | |
74 | ItemList *owners = nullptr; |
75 | PopupMenu *file_options = nullptr; |
76 | String editing; |
77 | |
78 | void _fill_owners(EditorFileSystemDirectory *efsd); |
79 | |
80 | static void _bind_methods(); |
81 | void _list_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index); |
82 | void _select_file(int p_idx); |
83 | void _empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index); |
84 | void _file_option(int p_option); |
85 | |
86 | private: |
87 | enum { |
88 | FILE_OPEN |
89 | }; |
90 | |
91 | public: |
92 | void show(const String &p_path); |
93 | DependencyEditorOwners(); |
94 | }; |
95 | |
96 | class DependencyRemoveDialog : public ConfirmationDialog { |
97 | GDCLASS(DependencyRemoveDialog, ConfirmationDialog); |
98 | |
99 | Label *text = nullptr; |
100 | Tree *owners = nullptr; |
101 | |
102 | HashMap<String, String> all_remove_files; |
103 | Vector<String> dirs_to_delete; |
104 | Vector<String> files_to_delete; |
105 | |
106 | struct RemovedDependency { |
107 | String file; |
108 | String file_type; |
109 | String dependency; |
110 | String dependency_folder; |
111 | |
112 | bool operator<(const RemovedDependency &p_other) const { |
113 | if (dependency_folder.is_empty() != p_other.dependency_folder.is_empty()) { |
114 | return p_other.dependency_folder.is_empty(); |
115 | } else { |
116 | return dependency < p_other.dependency; |
117 | } |
118 | } |
119 | }; |
120 | |
121 | void _find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder); |
122 | void _find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed); |
123 | void _find_localization_remaps_of_removed_files(Vector<RemovedDependency> &p_removed); |
124 | void _build_removed_dependency_tree(const Vector<RemovedDependency> &p_removed); |
125 | |
126 | void ok_pressed() override; |
127 | |
128 | static void _bind_methods(); |
129 | |
130 | public: |
131 | void show(const Vector<String> &p_folders, const Vector<String> &p_files); |
132 | DependencyRemoveDialog(); |
133 | }; |
134 | |
135 | class DependencyErrorDialog : public ConfirmationDialog { |
136 | GDCLASS(DependencyErrorDialog, ConfirmationDialog); |
137 | |
138 | public: |
139 | enum Mode { |
140 | MODE_SCENE, |
141 | MODE_RESOURCE, |
142 | }; |
143 | |
144 | private: |
145 | String for_file; |
146 | Mode mode; |
147 | Button *fdep = nullptr; |
148 | Label *text = nullptr; |
149 | Tree *files = nullptr; |
150 | void ok_pressed() override; |
151 | void custom_action(const String &) override; |
152 | |
153 | public: |
154 | void show(Mode p_mode, const String &p_for_file, const Vector<String> &report); |
155 | DependencyErrorDialog(); |
156 | }; |
157 | |
158 | class OrphanResourcesDialog : public ConfirmationDialog { |
159 | GDCLASS(OrphanResourcesDialog, ConfirmationDialog); |
160 | |
161 | DependencyEditor *dep_edit = nullptr; |
162 | Tree *files = nullptr; |
163 | ConfirmationDialog *delete_confirm = nullptr; |
164 | void ok_pressed() override; |
165 | |
166 | bool _fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent); |
167 | |
168 | List<String> paths; |
169 | void _find_to_delete(TreeItem *p_item, List<String> &r_paths); |
170 | void _delete_confirm(); |
171 | void _button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button); |
172 | |
173 | void refresh(); |
174 | static void _bind_methods(); |
175 | |
176 | public: |
177 | void show(); |
178 | OrphanResourcesDialog(); |
179 | }; |
180 | |
181 | #endif // DEPENDENCY_EDITOR_H |
182 | |