Debian Codegraph @

editor/settings/editor_settings.h

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_settings.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/input/shortcut.h"
34 #include "core/io/config_file.h"
35 #include "core/io/resource.h"
36 #include "core/os/thread_safe.h"
37
38 class EditorPlugin;
39
40 class EditorSettings : public Resource {
41 GDCLASS(EditorSettings, Resource);
42
43 _THREAD_SAFE_CLASS_
44
45 public:
46 struct Plugin {
47 EditorPlugin *instance = nullptr;
48 String path;
49 String name;
50 String author;
51 String version;
52 String description;
53 bool installs = false;
54 String script;
55 Vector<String> install_files;
56 };
57
58 enum NetworkMode {
59 NETWORK_OFFLINE,
60 NETWORK_ONLINE,
61 };
62
63 enum InitialScreen {
64 INITIAL_SCREEN_AUTO = -5, // Remembers last screen position.
65 INITIAL_SCREEN_WITH_MOUSE_FOCUS = -4,
66 INITIAL_SCREEN_WITH_KEYBOARD_FOCUS = -3,
67 INITIAL_SCREEN_PRIMARY = -2,
68 };
69
70 private:
71 struct VariantContainer {
72 int order = 0;
73 Variant variant;
74 Variant initial;
75 bool basic = false;
76 bool has_default_value = false;
77 bool hide_from_editor = false;
78 bool save = false;
79 bool restart_if_changed = false;
80
81 VariantContainer() {}
82
83 VariantContainer(const Variant &p_variant, int p_order) :
84 order(p_order),
85 variant(p_variant) {
86 }
87 };
88
89 static Ref<EditorSettings> singleton;
90
91 HashSet<String> changed_settings;
92 mutable String auto_language;
93
94 mutable Ref<ConfigFile> project_metadata;
95 bool project_metadata_dirty = false;
96 HashMap<String, PropertyInfo> hints;
97 HashMap<String, VariantContainer> props;
98 int last_order;
99
100 Ref<Resource> clipboard;
101 mutable HashMap<String, Ref<Shortcut>> shortcuts;
102 HashMap<String, List<Ref<InputEvent>>> builtin_action_overrides;
103
104 Vector<String> favorites;
105 HashMap<String, PackedStringArray> favorite_properties;
106 Vector<String> recent_dirs;
107
108 bool save_changed_setting = true;
109 bool optimize_save = true; //do not save stuff that came from config but was not set from engine
110 bool initialized = false;
111
112 bool _set(const StringName &p_name, const Variant &p_value);
113 bool _set_only(const StringName &p_name, const Variant &p_value);
114 bool _get(const StringName &p_name, Variant &r_ret) const;
115 void _initial_set(const StringName &p_name, const Variant &p_value, bool p_basic = false);
116 void _get_property_list(List<PropertyInfo> *p_list) const;
117 void _add_property_info_bind(const Dictionary &p_info);
118 bool _property_can_revert(const StringName &p_name) const;
119 bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
120
121 void _set_initialized();
122 void _load_defaults(Ref<ConfigFile> p_extra_config = Ref<ConfigFile>());
123 void _load_default_visual_shader_editor_theme();
124 static String _guess_exec_args_for_extenal_editor(const String &p_value);
125 const String _get_project_metadata_path() const;
126 #ifndef DISABLE_DEPRECATED
127 void _remove_deprecated_settings();
128 #endif
129
130 // Bind helpers.
131 Vector<String> _get_shortcut_list();
132
133 protected:
134 static void _bind_methods();
135
136 public:
137 enum {
138 NOTIFICATION_EDITOR_SETTINGS_CHANGED = 10000
139 };
140
141 static EditorSettings *get_singleton();
142 static String get_existing_settings_path();
143 static String get_newest_settings_path();
144
145 static void create();
146 void setup_language(bool p_initial_setup);
147 void setup_network();
148 static void save();
149 static void destroy();
150 void set_optimize_save(bool p_optimize);
151
152 bool has_default_value(const String &p_setting) const;
153 void set_setting(const String &p_setting, const Variant &p_value);
154 Variant get_setting(const String &p_setting) const;
155 bool has_setting(const String &p_setting) const;
156 void erase(const String &p_setting);
157 void raise_order(const String &p_setting);
158 void set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current = false);
159 void set_restart_if_changed(const StringName &p_setting, bool p_restart);
160 void set_basic(const StringName &p_setting, bool p_basic);
161 void set_manually(const StringName &p_setting, const Variant &p_value, bool p_emit_signal = false) {
162 if (p_emit_signal) {
163 _set(p_setting, p_value);
164 } else {
165 _set_only(p_setting, p_value);
166 }
167 }
168 void add_property_hint(const PropertyInfo &p_hint);
169 PackedStringArray get_changed_settings() const;
170 bool check_changed_settings_in_group(const String &p_setting_prefix) const;
171 void mark_setting_changed(const String &p_setting);
172
173 void set_resource_clipboard(const Ref<Resource> &p_resource) { clipboard = p_resource; }
174 Ref<Resource> get_resource_clipboard() const { return clipboard; }
175
176 void set_project_metadata(const String &p_section, const String &p_key, const Variant &p_data);
177 Variant get_project_metadata(const String &p_section, const String &p_key, const Variant &p_default) const;
178 void save_project_metadata();
179
180 void set_favorites(const Vector<String> &p_favorites, bool p_update_file_dialog = true);
181 void set_favorites_bind(const Vector<String> &p_favorites);
182 Vector<String> get_favorites() const;
183 Vector<String> get_favorite_folders() const;
184 void set_favorite_properties(const HashMap<String, PackedStringArray> &p_favorite_properties);
185 HashMap<String, PackedStringArray> get_favorite_properties() const;
186 void set_recent_dirs(const Vector<String> &p_recent_dirs, bool p_update_file_dialog = true);
187 void set_recent_dirs_bind(const Vector<String> &p_recent_dirs);
188 Vector<String> get_recent_dirs() const;
189 void load_favorites_and_recent_dirs();
190
191 static HashMap<StringName, Color> get_godot2_text_editor_theme();
192 static bool is_default_text_editor_theme(const String &p_theme_name);
193 void update_text_editor_themes_list();
194
195 Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String());
196 String get_editor_layouts_config() const;
197 static float get_auto_display_scale();
198 String get_language() const;
199
200 void _add_shortcut_default(const String &p_path, const Ref<Shortcut> &p_shortcut);
201 void add_shortcut(const String &p_path, const Ref<Shortcut> &p_shortcut);
202 void remove_shortcut(const String &p_path);
203 bool is_shortcut(const String &p_path, const Ref<InputEvent> &p_event) const;
204 bool has_shortcut(const String &p_path) const;
205 Ref<Shortcut> get_shortcut(const String &p_path) const;
206 void get_shortcut_list(List<String> *r_shortcuts);
207
208 void set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events);
209 const Array get_builtin_action_overrides(const String &p_name) const;
210
211 void notify_changes();
212
213 virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
214
215 EditorSettings();
216 };
217
218 //not a macro any longer
219
220 #define EDITOR_DEF(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val))
221 #define EDITOR_DEF_RST(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val), true)
222 #define EDITOR_DEF_BASIC(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val), false, true)
223 Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed = false, bool p_basic = false);
224
225 #define EDITOR_GET(m_var) _EDITOR_GET(m_var)
226 Variant _EDITOR_GET(const String &p_setting);
227
228 #define ED_IS_SHORTCUT(p_name, p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name, p_ev))
229 Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode = Key::NONE, bool p_physical = false);
230 Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical = false);
231 void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode = Key::NONE, bool p_physical = false);
232 void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical = false);
233 Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path);