1 | /**************************************************************************/ |
2 | /* editor_feature_profile.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 EDITOR_FEATURE_PROFILE_H |
32 | #define EDITOR_FEATURE_PROFILE_H |
33 | |
34 | #include "core/io/file_access.h" |
35 | #include "core/object/ref_counted.h" |
36 | #include "editor/editor_help.h" |
37 | #include "scene/gui/dialogs.h" |
38 | #include "scene/gui/option_button.h" |
39 | #include "scene/gui/separator.h" |
40 | #include "scene/gui/split_container.h" |
41 | #include "scene/gui/tree.h" |
42 | |
43 | class EditorFileDialog; |
44 | |
45 | class EditorFeatureProfile : public RefCounted { |
46 | GDCLASS(EditorFeatureProfile, RefCounted); |
47 | |
48 | public: |
49 | enum Feature { |
50 | FEATURE_3D, |
51 | FEATURE_SCRIPT, |
52 | FEATURE_ASSET_LIB, |
53 | FEATURE_SCENE_TREE, |
54 | FEATURE_NODE_DOCK, |
55 | FEATURE_FILESYSTEM_DOCK, |
56 | FEATURE_IMPORT_DOCK, |
57 | FEATURE_HISTORY_DOCK, |
58 | FEATURE_MAX |
59 | }; |
60 | |
61 | private: |
62 | HashSet<StringName> disabled_classes; |
63 | HashSet<StringName> disabled_editors; |
64 | HashMap<StringName, HashSet<StringName>> disabled_properties; |
65 | |
66 | HashSet<StringName> collapsed_classes; |
67 | |
68 | bool features_disabled[FEATURE_MAX]; |
69 | static const char *feature_names[FEATURE_MAX]; |
70 | static const char *feature_descriptions[FEATURE_MAX]; |
71 | static const char *feature_identifiers[FEATURE_MAX]; |
72 | |
73 | String _get_feature_name(Feature p_feature) { return get_feature_name(p_feature); } |
74 | |
75 | protected: |
76 | static void _bind_methods(); |
77 | |
78 | public: |
79 | void set_disable_class(const StringName &p_class, bool p_disabled); |
80 | bool is_class_disabled(const StringName &p_class) const; |
81 | |
82 | void set_disable_class_editor(const StringName &p_class, bool p_disabled); |
83 | bool is_class_editor_disabled(const StringName &p_class) const; |
84 | |
85 | void set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled); |
86 | bool is_class_property_disabled(const StringName &p_class, const StringName &p_property) const; |
87 | bool has_class_properties_disabled(const StringName &p_class) const; |
88 | |
89 | void set_item_collapsed(const StringName &p_class, bool p_collapsed); |
90 | bool is_item_collapsed(const StringName &p_class) const; |
91 | |
92 | void set_disable_feature(Feature p_feature, bool p_disable); |
93 | bool is_feature_disabled(Feature p_feature) const; |
94 | |
95 | Error save_to_file(const String &p_path); |
96 | Error load_from_file(const String &p_path); |
97 | |
98 | static String get_feature_name(Feature p_feature); |
99 | static String get_feature_description(Feature p_feature); |
100 | |
101 | EditorFeatureProfile(); |
102 | }; |
103 | |
104 | VARIANT_ENUM_CAST(EditorFeatureProfile::Feature) |
105 | |
106 | class EditorFeatureProfileManager : public AcceptDialog { |
107 | GDCLASS(EditorFeatureProfileManager, AcceptDialog); |
108 | |
109 | enum Action { |
110 | PROFILE_CLEAR, |
111 | PROFILE_SET, |
112 | PROFILE_IMPORT, |
113 | PROFILE_EXPORT, |
114 | PROFILE_NEW, |
115 | PROFILE_ERASE, |
116 | PROFILE_MAX |
117 | }; |
118 | |
119 | enum ClassOptions { |
120 | CLASS_OPTION_DISABLE_EDITOR |
121 | }; |
122 | |
123 | ConfirmationDialog *erase_profile_dialog = nullptr; |
124 | ConfirmationDialog *new_profile_dialog = nullptr; |
125 | LineEdit *new_profile_name = nullptr; |
126 | |
127 | LineEdit *current_profile_name = nullptr; |
128 | OptionButton *profile_list = nullptr; |
129 | Button *profile_actions[PROFILE_MAX]; |
130 | |
131 | HSplitContainer *h_split = nullptr; |
132 | |
133 | VBoxContainer *class_list_vbc = nullptr; |
134 | Tree *class_list = nullptr; |
135 | VBoxContainer *property_list_vbc = nullptr; |
136 | Tree *property_list = nullptr; |
137 | EditorHelpBit *description_bit = nullptr; |
138 | Label *no_profile_selected_help = nullptr; |
139 | |
140 | EditorFileDialog *import_profiles = nullptr; |
141 | EditorFileDialog *export_profile = nullptr; |
142 | |
143 | void _profile_action(int p_action); |
144 | void _profile_selected(int p_what); |
145 | |
146 | String current_profile; |
147 | void _update_profile_list(const String &p_select_profile = String()); |
148 | void _update_selected_profile(); |
149 | void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected); |
150 | |
151 | Ref<EditorFeatureProfile> current; |
152 | Ref<EditorFeatureProfile> edited; |
153 | |
154 | void _erase_selected_profile(); |
155 | void _create_new_profile(); |
156 | String _get_selected_profile(); |
157 | |
158 | void _import_profiles(const Vector<String> &p_paths); |
159 | void _export_profile(const String &p_path); |
160 | |
161 | bool updating_features = false; |
162 | |
163 | void _class_list_item_selected(); |
164 | void _class_list_item_edited(); |
165 | void _class_list_item_collapsed(Object *p_item); |
166 | void _property_item_edited(); |
167 | void _save_and_update(); |
168 | |
169 | Timer *update_timer = nullptr; |
170 | void _emit_current_profile_changed(); |
171 | |
172 | static EditorFeatureProfileManager *singleton; |
173 | |
174 | protected: |
175 | static void _bind_methods(); |
176 | void _notification(int p_what); |
177 | |
178 | public: |
179 | Ref<EditorFeatureProfile> get_current_profile(); |
180 | String get_current_profile_name() const; |
181 | void set_current_profile(const String &p_profile_name, bool p_validate_profile); |
182 | void notify_changed(); |
183 | |
184 | static EditorFeatureProfileManager *get_singleton() { return singleton; } |
185 | EditorFeatureProfileManager(); |
186 | }; |
187 | |
188 | #endif // EDITOR_FEATURE_PROFILE_H |
189 | |