Debian Codegraph @

editor/settings/editor_settings_dialog.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_settings_dialog.cpp */
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 #include "editor_settings_dialog.h"
32
33 #include "core/config/project_settings.h"
34 #include "core/input/input_map.h"
35 #include "core/os/keyboard.h"
36 #include "editor/debugger/editor_debugger_node.h"
37 #include "editor/editor_log.h"
38 #include "editor/editor_node.h"
39 #include "editor/editor_string_names.h"
40 #include "editor/editor_undo_redo_manager.h"
41 #include "editor/inspector/editor_property_name_processor.h"
42 #include "editor/inspector/editor_sectioned_inspector.h"
43 #include "editor/scene/3d/node_3d_editor_plugin.h"
44 #include "editor/settings/editor_event_search_bar.h"
45 #include "editor/settings/editor_settings.h"
46 #include "editor/settings/event_listener_line_edit.h"
47 #include "editor/settings/input_event_configuration_dialog.h"
48 #include "editor/themes/editor_scale.h"
49 #include "editor/themes/editor_theme_manager.h"
50 #include "scene/gui/check_button.h"
51 #include "scene/gui/panel_container.h"
52 #include "scene/gui/tab_container.h"
53 #include "scene/gui/texture_rect.h"
54 #include "scene/gui/tree.h"
55
56 void EditorSettingsDialog::ok_pressed() {
57 if (!EditorSettings::get_singleton()) {
58 return;
59 }
60 _settings_save();
61 }
62
63 void EditorSettingsDialog::_settings_changed() {
64 timer->start();
65 }
66
67 void EditorSettingsDialog::_settings_property_edited() {
68 Vector<String> changed = EditorSettings::get_singleton()->get_changed_settings();
69 if (changed.is_empty()) {
70 return;
71 }
72
73 const String full_name = changed[changed.size() - 1];
74
75 // Set theme presets to Custom when controlled settings change.
76
77 if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders" || full_name == "interface/theme/icon_saturation" || full_name == "interface/theme/draw_relationship_lines" || full_name == "interface/theme/corner_radius") {
78 EditorSettings::get_singleton()->set_manually("interface/theme/color_preset", "Custom");
79 } else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {
80 EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");
81 } else if (full_name.begins_with("text_editor/theme/highlighting")) {
82 EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
83 } else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {
84 EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");
85 } else if (full_name == "editors/3d/navigation/orbit_mouse_button" || full_name == "editors/3d/navigation/pan_mouse_button" || full_name == "editors/3d/navigation/zoom_mouse_button" || full_name == "editors/3d/navigation/emulate_3_button_mouse") {
86 EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
87 } else if (full_name == "editors/3d/navigation/navigation_scheme") {
88 update_navigation_preset();
89 _update_shortcuts();
90 }
91 }
92
93 void EditorSettingsDialog::update_navigation_preset() {
94 Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();
95 Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
96 Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
97 Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
98 bool set_3_button_mouse = false;
99 Ref<InputEventKey> orbit_mod_key_1;
100 Ref<InputEventKey> orbit_mod_key_2;
101 Ref<InputEventKey> pan_mod_key_1;
102 Ref<InputEventKey> pan_mod_key_2;
103 Ref<InputEventKey> zoom_mod_key_1;
104 Ref<InputEventKey> zoom_mod_key_2;
105 Ref<InputEventKey> orbit_snap_mod_key_1;
106 Ref<InputEventKey> orbit_snap_mod_key_2;
107 bool set_preset = false;
108
109 if (nav_scheme == Node3DEditorViewport::NAVIGATION_GODOT) {
110 set_preset = true;
111 set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
112 set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
113 set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
114 set_3_button_mouse = false;
115 orbit_mod_key_1 = InputEventKey::create_reference(Key::NONE);
116 orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
117 pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
118 pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
119 zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);
120 zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
121 orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::ALT);
122 orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);
123 } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA) {
124 set_preset = true;
125 set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
126 set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
127 set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_RIGHT_MOUSE;
128 set_3_button_mouse = false;
129 orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
130 orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
131 pan_mod_key_1 = InputEventKey::create_reference(Key::NONE);
132 pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
133 zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
134 zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
135 orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::NONE);
136 orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);
137 } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) {
138 set_preset = true;
139 set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
140 set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
141 set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
142 set_3_button_mouse = false;
143 orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
144 orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
145 pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
146 pan_mod_key_2 = InputEventKey::create_reference(Key::ALT);
147 zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
148 zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);
149 orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::NONE);
150 orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);
151 } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_TABLET) {
152 set_preset = true;
153 set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
154 set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
155 set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
156 set_3_button_mouse = true;
157 orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
158 orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
159 pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
160 pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
161 zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);
162 zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
163 orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::NONE);
164 orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);
165 }
166 // Set settings to the desired preset values.
167 if (set_preset) {
168 EditorSettings::get_singleton()->set_manually("editors/3d/navigation/orbit_mouse_button", (int)set_orbit_mouse_button);
169 EditorSettings::get_singleton()->set_manually("editors/3d/navigation/pan_mouse_button", (int)set_pan_mouse_button);
170 EditorSettings::get_singleton()->set_manually("editors/3d/navigation/zoom_mouse_button", (int)set_zoom_mouse_button);
171 EditorSettings::get_singleton()->set_manually("editors/3d/navigation/emulate_3_button_mouse", set_3_button_mouse);
172 _set_shortcut_input("spatial_editor/viewport_orbit_modifier_1", orbit_mod_key_1);
173 _set_shortcut_input("spatial_editor/viewport_orbit_modifier_2", orbit_mod_key_2);
174 _set_shortcut_input("spatial_editor/viewport_pan_modifier_1", pan_mod_key_1);
175 _set_shortcut_input("spatial_editor/viewport_pan_modifier_2", pan_mod_key_2);
176 _set_shortcut_input("spatial_editor/viewport_zoom_modifier_1", zoom_mod_key_1);
177 _set_shortcut_input("spatial_editor/viewport_zoom_modifier_2", zoom_mod_key_2);
178 _set_shortcut_input("spatial_editor/viewport_orbit_snap_modifier_1", orbit_snap_mod_key_1);
179 _set_shortcut_input("spatial_editor/viewport_orbit_snap_modifier_2", orbit_snap_mod_key_2);
180 }
181 }
182
183 void EditorSettingsDialog::_set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event) {
184 Array sc_events;
185 if (p_event->get_keycode() != Key::NONE) {
186 sc_events.push_back((Variant)p_event);
187 }
188
189 Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_name);
190 sc->set_events(sc_events);
191 }
192
193 void EditorSettingsDialog::_settings_save() {
194 if (!timer->is_stopped()) {
195 timer->stop();
196 }
197 EditorSettings::get_singleton()->notify_changes();
198 EditorSettings::get_singleton()->save();
199 }
200
201 void EditorSettingsDialog::cancel_pressed() {
202 if (!EditorSettings::get_singleton()) {
203 return;
204 }
205
206 EditorSettings::get_singleton()->notify_changes();
207 }
208
209 void EditorSettingsDialog::popup_edit_settings() {
210 if (!EditorSettings::get_singleton()) {
211 return;
212 }
213
214 EditorSettings::get_singleton()->update_text_editor_themes_list(); // Make sure we have an up to date list of themes.
215
216 _update_dynamic_property_hints();
217
218 inspector->edit(EditorSettings::get_singleton());
219 inspector->get_inspector()->update_tree();
220
221 _update_shortcuts();
222 set_process_shortcut_input(true);
223
224 // Restore valid window bounds or pop up at default size.
225 Rect2 saved_size;
226 if (!_is_in_project_manager()) {
227 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
228 }
229
230 if (saved_size != Rect2()) {
231 popup(saved_size);
232 } else if (_is_in_project_manager()) {
233 popup_centered_clamped(Size2(800, 600) * EDSCALE, 0.8); // Make it smaller that the default Project Manager size.
234 } else {
235 popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
236 }
237
238 _focus_current_search_box();
239 }
240
241 void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {
242 EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
243 }
244
245 void EditorSettingsDialog::_notification(int p_what) {
246 switch (p_what) {
247 case NOTIFICATION_VISIBILITY_CHANGED: {
248 if (!is_visible() && !_is_in_project_manager()) {
249 EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));
250 set_process_shortcut_input(false);
251 }
252 } break;
253
254 case NOTIFICATION_READY: {
255 EditorSettingsPropertyWrapper::restart_request_callback = callable_mp(this, &EditorSettingsDialog::_editor_restart_request);
256
257 if (_is_in_project_manager()) {
258 return;
259 }
260 EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
261 undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_method_notify_callback(EditorDebuggerNode::_methods_changed, nullptr);
262 undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_property_notify_callback(EditorDebuggerNode::_properties_changed, nullptr);
263 undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
264 } break;
265
266 case NOTIFICATION_ENTER_TREE: {
267 _update_icons();
268 } break;
269
270 case NOTIFICATION_THEME_CHANGED: {
271 _update_shortcuts();
272 } break;
273
274 case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
275 if (EditorThemeManager::is_generated_theme_outdated()) {
276 _update_icons();
277 }
278
279 bool update_shortcuts_tab =
280 EditorSettings::get_singleton()->check_changed_settings_in_group("shortcuts") ||
281 EditorSettings::get_singleton()->check_changed_settings_in_group("builtin_action_overrides");
282 if (update_shortcuts_tab) {
283 _update_shortcuts();
284 }
285
286 if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d/navigation")) {
287 // Shortcuts may have changed, so dynamic hint values must update.
288 _update_dynamic_property_hints();
289 inspector->get_inspector()->update_tree();
290 }
291
292 if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {
293 inspector->update_category_list();
294 }
295 } break;
296 }
297 }
298
299 void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
300 const Ref<InputEventKey> k = p_event;
301 if (k.is_valid() && k->is_pressed()) {
302 bool handled = false;
303
304 if (EditorNode::get_singleton()) {
305 if (ED_IS_SHORTCUT("ui_undo", p_event)) {
306 EditorNode::get_singleton()->undo();
307 handled = true;
308 }
309
310 if (ED_IS_SHORTCUT("ui_redo", p_event)) {
311 EditorNode::get_singleton()->redo();
312 handled = true;
313 }
314 }
315
316 if (k->is_match(InputEventKey::create_reference(KeyModifierMask::CMD_OR_CTRL | Key::F))) {
317 _focus_current_search_box();
318 handled = true;
319 }
320
321 if (handled) {
322 set_input_as_handled();
323 }
324 }
325 }
326
327 void EditorSettingsDialog::_update_icons() {
328 search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
329 search_box->set_clear_button_enabled(true);
330
331 restart_close_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
332 restart_container->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
333 restart_icon->set_texture(get_editor_theme_icon(SNAME("StatusWarning")));
334 restart_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
335 }
336
337 void EditorSettingsDialog::_event_config_confirmed() {
338 Ref<InputEventKey> k = shortcut_editor->get_event();
339 if (k.is_null()) {
340 return;
341 }
342
343 if (current_event_index == -1) {
344 // Add new event
345 current_events.push_back(k);
346 } else {
347 // Edit existing event
348 current_events[current_event_index] = k;
349 }
350
351 if (is_editing_action) {
352 _update_builtin_action(current_edited_identifier, current_events);
353 } else {
354 _update_shortcut_events(current_edited_identifier, current_events);
355 }
356 }
357
358 bool EditorSettingsDialog::_is_in_project_manager() const {
359 return !ProjectSettings::get_singleton()->is_project_loaded();
360 }
361
362 void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
363 Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);
364 if (old_input_array.is_empty()) {
365 List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
366 old_input_array = _event_list_to_array_helper(defaults);
367 }
368
369 if (_is_in_project_manager()) {
370 // Project Manager doesn't have EditorUndoRedoManager, so apply changes directly.
371 EditorSettings::get_singleton()->mark_setting_changed("builtin_action_overrides");
372 EditorSettings::get_singleton()->set_builtin_action_override(p_name, p_events);
373 _update_shortcuts();
374 _settings_changed();
375 } else {
376 EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
377 undo_redo->create_action(vformat(TTR("Edit Built-in Action: %s"), p_name));
378 undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
379 undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
380 undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);
381 undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);
382 undo_redo->add_do_method(this, "_update_shortcuts");
383 undo_redo->add_undo_method(this, "_update_shortcuts");
384 undo_redo->add_do_method(this, "_settings_changed");
385 undo_redo->add_undo_method(this, "_settings_changed");
386 undo_redo->commit_action();
387 }
388 }
389
390 void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {
391 Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);
392
393 if (_is_in_project_manager()) {
394 // Project Manager doesn't have EditorUndoRedoManager, so apply changes directly.
395 current_sc->set_events(p_events);
396 EditorSettings::get_singleton()->mark_setting_changed("shortcuts");
397 _update_shortcuts();
398 _settings_changed();
399 } else {
400 EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
401 undo_redo->create_action(vformat(TTR("Edit Shortcut: %s"), p_path), UndoRedo::MERGE_DISABLE, EditorSettings::get_singleton());
402 // History must be fixed based on the EditorSettings object because current_sc would
403 // incorrectly make this action use the scene history.
404 undo_redo->force_fixed_history();
405 undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);
406 undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());
407 undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
408 undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
409 undo_redo->add_do_method(this, "_update_shortcuts");
410 undo_redo->add_undo_method(this, "_update_shortcuts");
411 undo_redo->add_do_method(this, "_settings_changed");
412 undo_redo->add_undo_method(this, "_settings_changed");
413 undo_redo->commit_action();
414 }
415
416 bool path_is_orbit_mod = p_path == "spatial_editor/viewport_orbit_modifier_1" || p_path == "spatial_editor/viewport_orbit_modifier_2";
417 bool path_is_pan_mod = p_path == "spatial_editor/viewport_pan_modifier_1" || p_path == "spatial_editor/viewport_pan_modifier_2";
418 bool path_is_zoom_mod = p_path == "spatial_editor/viewport_zoom_modifier_1" || p_path == "spatial_editor/viewport_zoom_modifier_2";
419 if (path_is_orbit_mod || path_is_pan_mod || path_is_zoom_mod) {
420 EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
421 }
422 }
423
424 Array EditorSettingsDialog::_event_list_to_array_helper(const List<Ref<InputEvent>> &p_events) {
425 Array events;
426
427 // Convert the list to an array, and only keep key events as this is for the editor.
428 for (const List<Ref<InputEvent>>::Element *E = p_events.front(); E; E = E->next()) {
429 Ref<InputEventKey> k = E->get();
430 if (k.is_valid()) {
431 events.append(E->get());
432 }
433 }
434
435 return events;
436 }
437
438 TreeItem *EditorSettingsDialog::_create_shortcut_treeitem(TreeItem *p_parent, const String &p_shortcut_identifier, const String &p_display, Array &p_events, bool p_allow_revert, bool p_is_action, bool p_is_collapsed) {
439 TreeItem *shortcut_item = shortcuts->create_item(p_parent);
440 shortcut_item->set_collapsed(p_is_collapsed);
441 shortcut_item->set_text(0, p_display);
442
443 Ref<InputEvent> primary = p_events.size() > 0 ? Ref<InputEvent>(p_events[0]) : Ref<InputEvent>();
444 Ref<InputEvent> secondary = p_events.size() > 1 ? Ref<InputEvent>(p_events[1]) : Ref<InputEvent>();
445
446 String sc_text = TTRC("None");
447 if (primary.is_valid()) {
448 sc_text = primary->as_text();
449
450 if (secondary.is_valid()) {
451 sc_text += ", " + secondary->as_text();
452
453 if (p_events.size() > 2) {
454 sc_text += " (+" + itos(p_events.size() - 2) + ")";
455 }
456 }
457 shortcut_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);
458 }
459
460 shortcut_item->set_text(1, sc_text);
461 if (sc_text == "None") {
462 // Fade out unassigned shortcut labels for easier visual grepping.
463 shortcut_item->set_custom_color(1, get_theme_color(SceneStringName(font_color), SNAME("Label")) * Color(1, 1, 1, 0.5));
464 }
465
466 if (p_allow_revert) {
467 shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Reload")), SHORTCUT_REVERT);
468 }
469
470 shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Add")), SHORTCUT_ADD);
471 shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE, p_events.is_empty());
472
473 shortcut_item->set_meta("is_action", p_is_action);
474 shortcut_item->set_meta("type", "shortcut");
475 shortcut_item->set_meta("shortcut_identifier", p_shortcut_identifier);
476 shortcut_item->set_meta("events", p_events);
477
478 // Shortcut Input Events
479 for (int i = 0; i < p_events.size(); i++) {
480 Ref<InputEvent> ie = p_events[i];
481 if (ie.is_null()) {
482 continue;
483 }
484
485 TreeItem *event_item = shortcuts->create_item(shortcut_item);
486
487 // TRANSLATORS: This is the label for the main input event of a shortcut.
488 event_item->set_text(0, shortcut_item->get_child_count() == 1 ? TTRC("Primary") : "");
489 event_item->set_text(1, ie->as_text());
490 event_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);
491
492 event_item->add_button(1, get_editor_theme_icon(SNAME("Edit")), SHORTCUT_EDIT);
493 event_item->add_button(1, get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
494
495 event_item->set_custom_bg_color(0, get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
496 event_item->set_custom_bg_color(1, get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
497
498 event_item->set_meta("is_action", p_is_action);
499 event_item->set_meta("type", "event");
500 event_item->set_meta("event_index", i);
501 }
502
503 return shortcut_item;
504 }
505
506 bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const {
507 const Ref<InputEvent> search_ev = shortcut_search_bar->get_event();
508 if (search_ev.is_valid()) {
509 bool event_match = false;
510 for (int i = 0; i < p_events.size(); ++i) {
511 const Ref<InputEvent> ev = p_events[i];
512 if (ev.is_valid() && ev->is_match(search_ev, true)) {
513 event_match = true;
514 break;
515 }
516 }
517 if (!event_match) {
518 return false;
519 }
520 }
521
522 const String &search_text = shortcut_search_bar->get_name();
523 if (search_text.is_empty()) {
524 return true;
525 }
526 if (search_text.is_subsequence_ofn(p_name)) {
527 return true;
528 }
529 if (p_match_localized_name && search_text.is_subsequence_ofn(TTR(p_name))) {
530 return true;
531 }
532
533 return false;
534 }
535
536 void EditorSettingsDialog::_update_shortcuts() {
537 // Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.
538 HashMap<String, bool> collapsed;
539
540 if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {
541 TreeItem *ti = shortcuts->get_root()->get_first_child();
542 while (ti) {
543 // Not all items have valid or unique text in the first column - so if it has an identifier, use that, as it should be unique.
544 if (ti->get_first_child() && ti->has_meta("shortcut_identifier")) {
545 collapsed[ti->get_meta("shortcut_identifier")] = ti->is_collapsed();
546 } else {
547 collapsed[ti->get_text(0)] = ti->is_collapsed();
548 }
549
550 // Try go down tree
551 TreeItem *ti_next = ti->get_first_child();
552 // Try go to the next node via in-order traversal
553 if (!ti_next) {
554 ti_next = ti;
555 while (ti_next && !ti_next->get_next()) {
556 ti_next = ti_next->get_parent();
557 }
558 if (ti_next) {
559 ti_next = ti_next->get_next();
560 }
561 }
562
563 ti = ti_next;
564 }
565 }
566
567 String prev_selected_shortcut;
568 if (shortcuts->get_selected()) {
569 prev_selected_shortcut = shortcuts->get_selected()->get_text(0);
570 }
571
572 shortcuts->clear();
573
574 TreeItem *root = shortcuts->create_item();
575 HashMap<String, TreeItem *> sections;
576
577 // Set up section for Common/Built-in actions
578 TreeItem *common_section = shortcuts->create_item(root);
579 sections["Common"] = common_section;
580 common_section->set_text(0, TTRC("Common"));
581 common_section->set_selectable(0, false);
582 common_section->set_selectable(1, false);
583 if (collapsed.has("Common")) {
584 common_section->set_collapsed(collapsed["Common"]);
585 }
586 common_section->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
587 common_section->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
588
589 // Get the action map for the editor, and add each item to the "Common" section.
590 for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {
591 const String &action_name = E.key;
592 const InputMap::Action &action = E.value;
593
594 // Skip non-builtin actions.
595 if (!InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().has(action_name)) {
596 continue;
597 }
598
599 const List<Ref<InputEvent>> &all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name)->value;
600 Array action_events = _event_list_to_array_helper(action.inputs);
601 if (!_should_display_shortcut(action_name, action_events, false)) {
602 continue;
603 }
604
605 Array default_events = _event_list_to_array_helper(all_default_events);
606 bool same_as_defaults = Shortcut::is_event_array_equal(default_events, action_events);
607 bool collapse = !collapsed.has(action_name) || (collapsed.has(action_name) && collapsed[action_name]);
608
609 TreeItem *item = _create_shortcut_treeitem(common_section, action_name, action_name, action_events, !same_as_defaults, true, collapse);
610 item->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // `ui_*` input action names are untranslatable identifiers.
611 if (!prev_selected_shortcut.is_empty() && action_name == prev_selected_shortcut) {
612 item->select(0);
613 }
614 }
615
616 // Editor Shortcuts
617
618 List<String> slist;
619 EditorSettings::get_singleton()->get_shortcut_list(&slist);
620 slist.sort(); // Sort alphabetically.
621
622 const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
623 const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
624
625 // Create all sections first.
626 for (const String &E : slist) {
627 Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
628 String section_name = E.get_slicec('/', 0);
629
630 if (sections.has(section_name)) {
631 continue;
632 }
633
634 TreeItem *section = shortcuts->create_item(root);
635
636 const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, name_style, E);
637 const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, tooltip_style, E);
638
639 section->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // Already translated manually.
640 section->set_text(0, item_name);
641 section->set_tooltip_text(0, tooltip);
642 section->set_selectable(0, false);
643 section->set_selectable(1, false);
644 section->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
645 section->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
646
647 if (collapsed.has(item_name)) {
648 section->set_collapsed(collapsed[item_name]);
649 }
650
651 sections[section_name] = section;
652 }
653
654 // Add shortcuts to sections.
655 for (const String &E : slist) {
656 Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
657 if (!sc->has_meta("original")) {
658 continue;
659 }
660
661 String section_name = E.get_slicec('/', 0);
662 TreeItem *section = sections[section_name];
663
664 if (!_should_display_shortcut(sc->get_name(), sc->get_events(), true)) {
665 continue;
666 }
667
668 Array original = sc->get_meta("original");
669 Array shortcuts_array = sc->get_events().duplicate(true);
670 bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);
671 bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);
672
673 TreeItem *shortcut_item = _create_shortcut_treeitem(section, E, sc->get_name(), shortcuts_array, !same_as_defaults, false, collapse);
674 if (!prev_selected_shortcut.is_empty() && sc->get_name() == prev_selected_shortcut) {
675 shortcut_item->select(0);
676 }
677 }
678
679 if (!prev_selected_shortcut.is_empty()) {
680 shortcuts->ensure_cursor_is_visible();
681 }
682
683 // remove sections with no shortcuts
684 for (KeyValue<String, TreeItem *> &E : sections) {
685 TreeItem *section = E.value;
686 if (section->get_first_child() == nullptr) {
687 root->remove_child(section);
688 memdelete(section);
689 }
690 }
691 }
692
693 void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button) {
694 if (p_button != MouseButton::LEFT) {
695 return;
696 }
697 TreeItem *ti = Object::cast_to<TreeItem>(p_item);
698 ERR_FAIL_NULL_MSG(ti, "Object passed is not a TreeItem.");
699
700 ShortcutButton button_idx = (ShortcutButton)p_idx;
701
702 is_editing_action = ti->get_meta("is_action");
703
704 String type = ti->get_meta("type");
705
706 if (type == "event") {
707 current_edited_identifier = ti->get_parent()->get_meta("shortcut_identifier");
708 current_events = ti->get_parent()->get_meta("events");
709 current_event_index = ti->get_meta("event_index");
710 } else { // Type is "shortcut"
711 current_edited_identifier = ti->get_meta("shortcut_identifier");
712 current_events = ti->get_meta("events");
713 current_event_index = -1;
714 }
715
716 switch (button_idx) {
717 case EditorSettingsDialog::SHORTCUT_ADD: {
718 // Only for "shortcut" types
719 shortcut_editor->popup_and_configure();
720 } break;
721 case EditorSettingsDialog::SHORTCUT_EDIT: {
722 // Only for "event" types
723 shortcut_editor->popup_and_configure(current_events[current_event_index]);
724 } break;
725 case EditorSettingsDialog::SHORTCUT_ERASE: {
726 if (type == "shortcut") {
727 if (is_editing_action) {
728 _update_builtin_action(current_edited_identifier, Array());
729 } else {
730 _update_shortcut_events(current_edited_identifier, Array());
731 }
732 } else if (type == "event") {
733 current_events.remove_at(current_event_index);
734
735 if (is_editing_action) {
736 _update_builtin_action(current_edited_identifier, current_events);
737 } else {
738 _update_shortcut_events(current_edited_identifier, current_events);
739 }
740 }
741 } break;
742 case EditorSettingsDialog::SHORTCUT_REVERT: {
743 // Only for "shortcut" types
744 if (is_editing_action) {
745 List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
746 Array events = _event_list_to_array_helper(defaults);
747
748 _update_builtin_action(current_edited_identifier, events);
749 } else {
750 Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(current_edited_identifier);
751 Array original = sc->get_meta("original");
752 _update_shortcut_events(current_edited_identifier, original);
753 }
754 } break;
755 default:
756 break;
757 }
758 }
759
760 void EditorSettingsDialog::_shortcut_cell_double_clicked() {
761 // When a shortcut cell is double clicked:
762 // If the cell has children and is in the bindings column, and if its first child is editable,
763 // then uncollapse the cell, and if the first child is the only child, then edit that child.
764 // If the cell is in the bindings column and can be edited, then edit it.
765 // If the cell is in the name column, then toggle collapse.
766 const ShortcutButton edit_btn_id = EditorSettingsDialog::SHORTCUT_EDIT;
767 const int edit_btn_col = 1;
768 TreeItem *ti = shortcuts->get_selected();
769 if (ti == nullptr) {
770 return;
771 }
772
773 String type = ti->get_meta("type");
774 int col = shortcuts->get_selected_column();
775 if (type == "shortcut" && col == 0) {
776 if (ti->get_first_child()) {
777 ti->set_collapsed(!ti->is_collapsed());
778 }
779 } else if (type == "shortcut" && col == 1) {
780 if (ti->get_first_child()) {
781 TreeItem *child_ti = ti->get_first_child();
782 if (child_ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
783 ti->set_collapsed(false);
784 if (ti->get_child_count() == 1) {
785 _shortcut_button_pressed(child_ti, edit_btn_col, edit_btn_id);
786 }
787 }
788 }
789 } else if (type == "event" && col == 1) {
790 if (ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
791 _shortcut_button_pressed(ti, edit_btn_col, edit_btn_id);
792 }
793 }
794 }
795
796 Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
797 TreeItem *selected = shortcuts->get_selected();
798
799 // Only allow drag for events
800 if (!selected || (String)selected->get_meta("type", "") != "event") {
801 return Variant();
802 }
803
804 String label_text = vformat(TTR("Event %d"), selected->get_meta("event_index"));
805 Label *label = memnew(Label(label_text));
806 label->set_modulate(Color(1, 1, 1, 1.0f));
807 shortcuts->set_drag_preview(label);
808
809 shortcuts->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
810
811 return Dictionary(); // No data required
812 }
813
814 bool EditorSettingsDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
815 TreeItem *selected = shortcuts->get_selected();
816 TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);
817 if (!selected || !item || item == selected || (String)item->get_meta("type", "") != "event") {
818 return false;
819 }
820
821 // Don't allow moving an events in-between shortcuts.
822 if (selected->get_parent()->get_meta("shortcut_identifier") != item->get_parent()->get_meta("shortcut_identifier")) {
823 return false;
824 }
825
826 return true;
827 }
828
829 void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
830 if (!can_drop_data_fw(p_point, p_data, p_from)) {
831 return;
832 }
833
834 TreeItem *selected = shortcuts->get_selected();
835 TreeItem *target = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);
836
837 if (!target) {
838 return;
839 }
840
841 int target_event_index = target->get_meta("event_index");
842 int index_moving_from = selected->get_meta("event_index");
843
844 Array events = selected->get_parent()->get_meta("events");
845
846 Variant event_moved = events[index_moving_from];
847 events.remove_at(index_moving_from);
848 events.insert(target_event_index, event_moved);
849
850 String ident = selected->get_parent()->get_meta("shortcut_identifier");
851 if (selected->get_meta("is_action")) {
852 _update_builtin_action(ident, events);
853 } else {
854 _update_shortcut_events(ident, events);
855 }
856 }
857
858 void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
859 _focus_current_search_box();
860
861 // When tab has switched, shortcuts may have changed.
862 _update_dynamic_property_hints();
863 inspector->get_inspector()->update_tree();
864 }
865
866 void EditorSettingsDialog::_update_dynamic_property_hints() {
867 // Calling add_property_hint overrides the existing hint.
868 EditorSettings *settings = EditorSettings::get_singleton();
869 settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/orbit_mouse_button", "spatial_editor/viewport_orbit_modifier_1", "spatial_editor/viewport_orbit_modifier_2"));
870 settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/pan_mouse_button", "spatial_editor/viewport_pan_modifier_1", "spatial_editor/viewport_pan_modifier_2"));
871 settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/zoom_mouse_button", "spatial_editor/viewport_zoom_modifier_1", "spatial_editor/viewport_zoom_modifier_2"));
872 }
873
874 PropertyInfo EditorSettingsDialog::_create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name) {
875 String hint_string;
876 hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
877 hint_string += "Left Mouse,";
878 hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
879 hint_string += "Middle Mouse,";
880 hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
881 hint_string += "Right Mouse,";
882 hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
883 hint_string += "Mouse Button 4,";
884 hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
885 hint_string += "Mouse Button 5";
886
887 return PropertyInfo(Variant::INT, p_property_name, PROPERTY_HINT_ENUM, hint_string);
888 }
889
890 String EditorSettingsDialog::_get_shortcut_button_string(const String &p_shortcut_name) {
891 String button_string;
892 Ref<Shortcut> shortcut_ref = EditorSettings::get_singleton()->get_shortcut(p_shortcut_name);
893 if (shortcut_ref.is_null()) {
894 return String();
895 }
896
897 Array events = shortcut_ref->get_events();
898 for (Ref<InputEvent> input_event : events) {
899 button_string += input_event->as_text() + " + ";
900 }
901 return button_string;
902 }
903
904 void EditorSettingsDialog::_focus_current_search_box() {
905 Control *tab = tabs->get_current_tab_control();
906 LineEdit *current_search_box = nullptr;
907 if (tab == tab_general) {
908 current_search_box = search_box;
909 } else if (tab == tab_shortcuts) {
910 current_search_box = shortcut_search_bar->get_name_search_box();
911 }
912
913 if (current_search_box) {
914 current_search_box->grab_focus();
915 current_search_box->select_all();
916 }
917 }
918
919 void EditorSettingsDialog::_advanced_toggled(bool p_button_pressed) {
920 EditorSettings::get_singleton()->set("_editor_settings_advanced_mode", p_button_pressed);
921 }
922
923 void EditorSettingsDialog::_editor_restart() {
924 emit_signal("restart_requested");
925 }
926
927 void EditorSettingsDialog::_editor_restart_request() {
928 restart_container->show();
929 }
930
931 void EditorSettingsDialog::_editor_restart_close() {
932 restart_container->hide();
933 }
934
935 void EditorSettingsDialog::_bind_methods() {
936 ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
937 ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
938
939 ADD_SIGNAL(MethodInfo("restart_requested"));
940 }
941
942 EditorSettingsDialog::EditorSettingsDialog() {
943 set_title(TTRC("Editor Settings"));
944 set_flag(FLAG_MAXIMIZE_DISABLED, false);
945 set_clamp_to_embedder(true);
946
947 tabs = memnew(TabContainer);
948 tabs->set_theme_type_variation("TabContainerOdd");
949 tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));
950 add_child(tabs);
951
952 // General Tab
953
954 tab_general = memnew(VBoxContainer);
955 tabs->add_child(tab_general);
956 tab_general->set_name(TTRC("General"));
957
958 HBoxContainer *hbc = memnew(HBoxContainer);
959 hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
960 tab_general->add_child(hbc);
961
962 search_box = memnew(LineEdit);
963 search_box->set_placeholder(TTRC("Filter Settings"));
964 search_box->set_accessibility_name(TTRC("Filter Settings"));
965 search_box->set_virtual_keyboard_show_on_focus(false);
966 search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
967 hbc->add_child(search_box);
968
969 advanced_switch = memnew(CheckButton(TTRC("Advanced Settings")));
970 hbc->add_child(advanced_switch);
971
972 bool use_advanced = EDITOR_DEF("_editor_settings_advanced_mode", false);
973 advanced_switch->set_pressed(use_advanced);
974 advanced_switch->connect(SceneStringName(toggled), callable_mp(this, &EditorSettingsDialog::_advanced_toggled));
975
976 inspector = memnew(SectionedInspector);
977 inspector->get_inspector()->set_use_filter(true);
978 inspector->get_inspector()->set_mark_unsaved(false);
979 inspector->register_search_box(search_box);
980 inspector->register_advanced_toggle(advanced_switch);
981 inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
982 tab_general->add_child(inspector);
983 inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));
984
985 if (EDITOR_GET("interface/touchscreen/enable_touch_optimizations")) {
986 inspector->set_touch_dragger_enabled(true);
987 }
988
989 restart_container = memnew(PanelContainer);
990 tab_general->add_child(restart_container);
991 HBoxContainer *restart_hb = memnew(HBoxContainer);
992 restart_container->add_child(restart_hb);
993 restart_icon = memnew(TextureRect);
994 restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
995 restart_hb->add_child(restart_icon);
996 restart_label = memnew(Label);
997 restart_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
998 if (_is_in_project_manager()) {
999 restart_label->set_text(TTRC("The Project Manager must be restarted for changes to take effect."));
1000 } else {
1001 restart_label->set_text(TTRC("The editor must be restarted for changes to take effect."));
1002 }
1003 restart_hb->add_child(restart_label);
1004 restart_hb->add_spacer();
1005 Button *restart_button = memnew(Button);
1006 restart_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart));
1007 restart_hb->add_child(restart_button);
1008 restart_button->set_text(TTRC("Save & Restart"));
1009 restart_close_button = memnew(Button);
1010 restart_close_button->set_accessibility_name(TTRC("Close"));
1011 restart_close_button->set_flat(true);
1012 restart_close_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart_close));
1013 restart_hb->add_child(restart_close_button);
1014 restart_container->hide();
1015
1016 // Needs to be done via the signal instead of the notification, otherwise it happens too late.
1017 EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));
1018
1019 // Shortcuts Tab
1020
1021 tab_shortcuts = memnew(VBoxContainer);
1022
1023 tabs->add_child(tab_shortcuts);
1024 tab_shortcuts->set_name(TTRC("Shortcuts"));
1025
1026 shortcut_search_bar = memnew(EditorEventSearchBar);
1027 shortcut_search_bar->connect(SceneStringName(value_changed), callable_mp(this, &EditorSettingsDialog::_update_shortcuts));
1028 tab_shortcuts->add_child(shortcut_search_bar);
1029
1030 MarginContainer *mc = memnew(MarginContainer);
1031 mc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
1032 mc->set_theme_type_variation("NoBorderHorizontalBottom");
1033 tab_shortcuts->add_child(mc);
1034
1035 shortcuts = memnew(Tree);
1036 shortcuts->set_accessibility_name(TTRC("Shortcuts"));
1037 shortcuts->set_theme_type_variation("TreeTable");
1038 shortcuts->set_columns(2);
1039 shortcuts->set_hide_root(true);
1040 shortcuts->set_column_titles_visible(true);
1041 shortcuts->set_column_title(0, TTRC("Name"));
1042 shortcuts->set_column_title(1, TTRC("Binding"));
1043 shortcuts->connect("button_clicked", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));
1044 shortcuts->connect("item_activated", callable_mp(this, &EditorSettingsDialog::_shortcut_cell_double_clicked));
1045 mc->add_child(shortcuts);
1046
1047 SET_DRAG_FORWARDING_GCD(shortcuts, EditorSettingsDialog);
1048
1049 // Adding event dialog
1050 shortcut_editor = memnew(InputEventConfigurationDialog);
1051 shortcut_editor->connect(SceneStringName(confirmed), callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));
1052 shortcut_editor->set_allowed_input_types(INPUT_KEY);
1053 add_child(shortcut_editor);
1054
1055 set_hide_on_ok(true);
1056
1057 timer = memnew(Timer);
1058 timer->set_wait_time(1.5);
1059 timer->connect("timeout", callable_mp(this, &EditorSettingsDialog::_settings_save));
1060 timer->set_one_shot(true);
1061 add_child(timer);
1062 EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_changed));
1063 set_ok_button_text(TTRC("Close"));
1064
1065 Ref<EditorSettingsInspectorPlugin> plugin;
1066 plugin.instantiate();
1067 plugin->inspector = inspector;
1068 EditorInspector::add_inspector_plugin(plugin);
1069 }
1070
1071 void EditorSettingsPropertyWrapper::_setup_override_info() {
1072 override_container = memnew(HBoxContainer);
1073
1074 override_icon = memnew(TextureRect);
1075 override_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
1076 override_container->add_child(override_icon);
1077
1078 Variant::Type type = ProjectSettings::get_singleton()->get_editor_setting_override(property).get_type();
1079 override_editor_property = get_parent_inspector()->instantiate_property_editor(ProjectSettings::get_singleton(), type, ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property, hint, hint_text, usage);
1080 override_editor_property->set_object_and_property(ProjectSettings::get_singleton(), ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property);
1081 override_editor_property->set_read_only(true);
1082 override_editor_property->set_label(TTR("Overridden in project"));
1083 override_editor_property->set_h_size_flags(SIZE_EXPAND_FILL);
1084 override_container->add_child(override_editor_property);
1085
1086 goto_button = memnew(Button);
1087 goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings."));
1088 override_container->add_child(goto_button);
1089 if (EditorNode::get_singleton()) {
1090 goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED);
1091 }
1092
1093 remove_button = memnew(Button);
1094 remove_button->set_tooltip_text(TTRC("Remove this override."));
1095 override_container->add_child(remove_button);
1096 remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override));
1097
1098 add_child(override_container);
1099
1100 if (is_ready()) {
1101 // Setup icons.
1102 _notification(NOTIFICATION_THEME_CHANGED);
1103 }
1104 }
1105
1106 void EditorSettingsPropertyWrapper::_update_override() {
1107 // Don't allow overriding theme properties, because it causes problems. Overriding Project Manager settings makes no sense.
1108 // TODO: Find a better way to define exception prefixes (if the list happens to grow).
1109 if (property.begins_with("interface/theme") || property.begins_with("project_manager") || Engine::get_singleton()->is_project_manager_hint()) {
1110 can_override = false;
1111 return;
1112 }
1113
1114 const bool has_override = ProjectSettings::get_singleton()->is_project_loaded() && ProjectSettings::get_singleton()->has_editor_setting_override(property);
1115 if (has_override) {
1116 if (!override_container) {
1117 _setup_override_info();
1118 }
1119 override_editor_property->update_property();
1120 set_bottom_editor(override_container);
1121 override_container->show();
1122 } else if (override_container) {
1123 override_container->hide();
1124 set_bottom_editor(nullptr);
1125 }
1126 can_override = !has_override;
1127 }
1128
1129 void EditorSettingsPropertyWrapper::_create_override() {
1130 ProjectSettings::get_singleton()->set_editor_setting_override(property, EDITOR_GET(property));
1131 ProjectSettings::get_singleton()->save();
1132 _update_override();
1133 }
1134
1135 void EditorSettingsPropertyWrapper::_remove_override() {
1136 ProjectSettings::get_singleton()->set_editor_setting_override(property, Variant());
1137 ProjectSettings::get_singleton()->save();
1138 EditorSettings::get_singleton()->mark_setting_changed(property);
1139 EditorNode::get_singleton()->notify_settings_overrides_changed();
1140 _update_override();
1141
1142 if (usage & PROPERTY_USAGE_RESTART_IF_CHANGED) {
1143 restart_request_callback.call();
1144 }
1145 }
1146
1147 void EditorSettingsPropertyWrapper::_notification(int p_what) {
1148 if (override_container && p_what == NOTIFICATION_THEME_CHANGED) {
1149 override_icon->set_texture(get_editor_theme_icon(SNAME("Hierarchy")));
1150 goto_button->set_button_icon(get_editor_theme_icon(SNAME("MethodOverride")));
1151 remove_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
1152 }
1153 }
1154
1155 void EditorSettingsPropertyWrapper::update_property() {
1156 editor_property->update_property();
1157 }
1158
1159 void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, PropertyHint p_hint, const String &p_hint_text, uint32_t p_usage) {
1160 hint = p_hint;
1161 hint_text = p_hint_text;
1162 usage = p_usage;
1163
1164 property = p_property;
1165 editor_property = p_editor_property;
1166 add_child(editor_property);
1167
1168 _update_override();
1169
1170 connect(SNAME("property_overridden"), callable_mp(this, &EditorSettingsPropertyWrapper::_create_override));
1171 editor_property->connect("property_changed", callable_mp((EditorProperty *)this, &EditorProperty::emit_changed));
1172 }
1173
1174 bool EditorSettingsInspectorPlugin::can_handle(Object *p_object) {
1175 return p_object && p_object->is_class("SectionedInspectorFilter") && p_object != current_object;
1176 }
1177
1178 bool EditorSettingsInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) {
1179 if (!p_object->is_class("SectionedInspectorFilter")) {
1180 return false;
1181 }
1182
1183 const String property = inspector->get_full_item_path(p_path);
1184 if (!EditorSettings::get_singleton()->has_setting(property)) {
1185 return false;
1186 }
1187 current_object = p_object;
1188
1189 EditorSettingsPropertyWrapper *editor = memnew(EditorSettingsPropertyWrapper);
1190 EditorProperty *real_property = inspector->get_inspector()->instantiate_property_editor(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);
1191 real_property->set_object_and_property(p_object, p_path);
1192 real_property->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1193 real_property->set_name_split_ratio(0.0);
1194 editor->setup(property, real_property, p_hint, p_hint_text, p_usage);
1195
1196 add_property_editor(p_path, editor);
1197 current_object = nullptr;
1198 return true;
1199 }