editor_settings_dialog.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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. #include "editor_settings_dialog.h"
  31. #include "core/input/input_map.h"
  32. #include "core/os/keyboard.h"
  33. #include "editor/debugger/editor_debugger_node.h"
  34. #include "editor/editor_log.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_property_name_processor.h"
  37. #include "editor/editor_sectioned_inspector.h"
  38. #include "editor/editor_settings.h"
  39. #include "editor/editor_string_names.h"
  40. #include "editor/editor_undo_redo_manager.h"
  41. #include "editor/event_listener_line_edit.h"
  42. #include "editor/input_event_configuration_dialog.h"
  43. #include "editor/plugins/node_3d_editor_plugin.h"
  44. #include "editor/themes/editor_scale.h"
  45. #include "editor/themes/editor_theme_manager.h"
  46. #include "scene/gui/check_button.h"
  47. #include "scene/gui/panel_container.h"
  48. #include "scene/gui/tab_container.h"
  49. #include "scene/gui/texture_rect.h"
  50. void EditorSettingsDialog::ok_pressed() {
  51. if (!EditorSettings::get_singleton()) {
  52. return;
  53. }
  54. _settings_save();
  55. timer->stop();
  56. }
  57. void EditorSettingsDialog::_settings_changed() {
  58. timer->start();
  59. }
  60. void EditorSettingsDialog::_settings_property_edited(const String &p_name) {
  61. String full_name = inspector->get_full_item_path(p_name);
  62. // Set theme presets to Custom when controlled settings change.
  63. 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") {
  64. EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom");
  65. } else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {
  66. EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");
  67. } else if (full_name.begins_with("text_editor/theme/highlighting")) {
  68. EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
  69. } else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {
  70. EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");
  71. } 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") {
  72. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
  73. } else if (full_name == "editors/3d/navigation/navigation_scheme") {
  74. update_navigation_preset();
  75. }
  76. }
  77. void EditorSettingsDialog::update_navigation_preset() {
  78. Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();
  79. Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  80. Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  81. Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  82. Ref<InputEventKey> orbit_mod_key_1;
  83. Ref<InputEventKey> orbit_mod_key_2;
  84. Ref<InputEventKey> pan_mod_key_1;
  85. Ref<InputEventKey> pan_mod_key_2;
  86. Ref<InputEventKey> zoom_mod_key_1;
  87. Ref<InputEventKey> zoom_mod_key_2;
  88. bool set_preset = false;
  89. if (nav_scheme == Node3DEditorViewport::NAVIGATION_GODOT) {
  90. set_preset = true;
  91. set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  92. set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  93. set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  94. orbit_mod_key_1 = InputEventKey::create_reference(Key::NONE);
  95. orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  96. pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
  97. pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  98. zoom_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
  99. zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);
  100. } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA) {
  101. set_preset = true;
  102. set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  103. set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  104. set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_RIGHT_MOUSE;
  105. orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  106. orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  107. pan_mod_key_1 = InputEventKey::create_reference(Key::NONE);
  108. pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  109. zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  110. zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  111. } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) {
  112. set_preset = true;
  113. set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  114. set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  115. set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  116. orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  117. orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  118. pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
  119. pan_mod_key_2 = InputEventKey::create_reference(Key::ALT);
  120. zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  121. zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);
  122. }
  123. // Set settings to the desired preset values.
  124. if (set_preset) {
  125. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/orbit_mouse_button", (int)set_orbit_mouse_button);
  126. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/pan_mouse_button", (int)set_pan_mouse_button);
  127. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/zoom_mouse_button", (int)set_zoom_mouse_button);
  128. _set_shortcut_input("spatial_editor/viewport_orbit_modifier_1", orbit_mod_key_1);
  129. _set_shortcut_input("spatial_editor/viewport_orbit_modifier_2", orbit_mod_key_2);
  130. _set_shortcut_input("spatial_editor/viewport_pan_modifier_1", pan_mod_key_1);
  131. _set_shortcut_input("spatial_editor/viewport_pan_modifier_2", pan_mod_key_2);
  132. _set_shortcut_input("spatial_editor/viewport_zoom_modifier_1", zoom_mod_key_1);
  133. _set_shortcut_input("spatial_editor/viewport_zoom_modifier_2", zoom_mod_key_2);
  134. }
  135. }
  136. void EditorSettingsDialog::_set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event) {
  137. Array sc_events;
  138. if (p_event->get_keycode() != Key::NONE) {
  139. sc_events.push_back((Variant)p_event);
  140. }
  141. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_name);
  142. sc->set_events(sc_events);
  143. }
  144. void EditorSettingsDialog::_settings_save() {
  145. EditorSettings::get_singleton()->notify_changes();
  146. EditorSettings::get_singleton()->save();
  147. }
  148. void EditorSettingsDialog::cancel_pressed() {
  149. if (!EditorSettings::get_singleton()) {
  150. return;
  151. }
  152. EditorSettings::get_singleton()->notify_changes();
  153. }
  154. void EditorSettingsDialog::popup_edit_settings() {
  155. if (!EditorSettings::get_singleton()) {
  156. return;
  157. }
  158. EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes
  159. _update_dynamic_property_hints();
  160. inspector->edit(EditorSettings::get_singleton());
  161. inspector->get_inspector()->update_tree();
  162. _update_shortcuts();
  163. set_process_shortcut_input(true);
  164. // Restore valid window bounds or pop up at default size.
  165. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
  166. if (saved_size != Rect2()) {
  167. popup(saved_size);
  168. } else {
  169. popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
  170. }
  171. _focus_current_search_box();
  172. }
  173. void EditorSettingsDialog::_filter_shortcuts(const String &) {
  174. _update_shortcuts();
  175. }
  176. void EditorSettingsDialog::_filter_shortcuts_by_event(const Ref<InputEvent> &p_event) {
  177. if (p_event.is_null() || (p_event->is_pressed() && !p_event->is_echo())) {
  178. _update_shortcuts();
  179. }
  180. }
  181. void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {
  182. EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
  183. }
  184. void EditorSettingsDialog::_notification(int p_what) {
  185. switch (p_what) {
  186. case NOTIFICATION_VISIBILITY_CHANGED: {
  187. if (!is_visible()) {
  188. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));
  189. set_process_shortcut_input(false);
  190. }
  191. } break;
  192. case NOTIFICATION_READY: {
  193. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  194. undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_method_notify_callback(EditorDebuggerNode::_methods_changed, nullptr);
  195. undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_property_notify_callback(EditorDebuggerNode::_properties_changed, nullptr);
  196. undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
  197. } break;
  198. case NOTIFICATION_ENTER_TREE: {
  199. _update_icons();
  200. } break;
  201. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  202. if (EditorThemeManager::is_generated_theme_outdated()) {
  203. _update_icons();
  204. }
  205. bool update_shortcuts_tab =
  206. EditorSettings::get_singleton()->check_changed_settings_in_group("shortcuts") ||
  207. EditorSettings::get_singleton()->check_changed_settings_in_group("builtin_action_overrides");
  208. if (update_shortcuts_tab) {
  209. _update_shortcuts();
  210. }
  211. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d/navigation")) {
  212. // Shortcuts may have changed, so dynamic hint values must update.
  213. _update_dynamic_property_hints();
  214. inspector->get_inspector()->update_tree();
  215. }
  216. if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {
  217. inspector->update_category_list();
  218. }
  219. } break;
  220. }
  221. }
  222. void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
  223. const Ref<InputEventKey> k = p_event;
  224. if (k.is_valid() && k->is_pressed()) {
  225. bool handled = false;
  226. if (ED_IS_SHORTCUT("ui_undo", p_event)) {
  227. EditorNode::get_singleton()->undo();
  228. handled = true;
  229. }
  230. if (ED_IS_SHORTCUT("ui_redo", p_event)) {
  231. EditorNode::get_singleton()->redo();
  232. handled = true;
  233. }
  234. if (k->is_match(InputEventKey::create_reference(KeyModifierMask::CMD_OR_CTRL | Key::F))) {
  235. _focus_current_search_box();
  236. handled = true;
  237. }
  238. if (handled) {
  239. set_input_as_handled();
  240. }
  241. }
  242. }
  243. void EditorSettingsDialog::_update_icons() {
  244. search_box->set_right_icon(shortcuts->get_editor_theme_icon(SNAME("Search")));
  245. search_box->set_clear_button_enabled(true);
  246. shortcut_search_box->set_right_icon(shortcuts->get_editor_theme_icon(SNAME("Search")));
  247. shortcut_search_box->set_clear_button_enabled(true);
  248. restart_close_button->set_icon(shortcuts->get_editor_theme_icon(SNAME("Close")));
  249. restart_container->add_theme_style_override(SceneStringName(panel), shortcuts->get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
  250. restart_icon->set_texture(shortcuts->get_editor_theme_icon(SNAME("StatusWarning")));
  251. restart_label->add_theme_color_override(SceneStringName(font_color), shortcuts->get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  252. }
  253. void EditorSettingsDialog::_event_config_confirmed() {
  254. Ref<InputEventKey> k = shortcut_editor->get_event();
  255. if (k.is_null()) {
  256. return;
  257. }
  258. if (current_event_index == -1) {
  259. // Add new event
  260. current_events.push_back(k);
  261. } else {
  262. // Edit existing event
  263. current_events[current_event_index] = k;
  264. }
  265. if (is_editing_action) {
  266. _update_builtin_action(current_edited_identifier, current_events);
  267. } else {
  268. _update_shortcut_events(current_edited_identifier, current_events);
  269. }
  270. }
  271. void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
  272. Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);
  273. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  274. undo_redo->create_action(vformat(TTR("Edit Built-in Action: %s"), p_name));
  275. undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
  276. undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
  277. undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);
  278. undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);
  279. undo_redo->add_do_method(this, "_settings_changed");
  280. undo_redo->add_undo_method(this, "_settings_changed");
  281. undo_redo->commit_action();
  282. _update_shortcuts();
  283. }
  284. void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {
  285. Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  286. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  287. undo_redo->create_action(vformat(TTR("Edit Shortcut: %s"), p_path));
  288. undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);
  289. undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());
  290. undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
  291. undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
  292. undo_redo->add_do_method(this, "_update_shortcuts");
  293. undo_redo->add_undo_method(this, "_update_shortcuts");
  294. undo_redo->add_do_method(this, "_settings_changed");
  295. undo_redo->add_undo_method(this, "_settings_changed");
  296. undo_redo->commit_action();
  297. bool path_is_orbit_mod = p_path == "spatial_editor/viewport_orbit_modifier_1" || p_path == "spatial_editor/viewport_orbit_modifier_2";
  298. bool path_is_pan_mod = p_path == "spatial_editor/viewport_pan_modifier_1" || p_path == "spatial_editor/viewport_pan_modifier_2";
  299. bool path_is_zoom_mod = p_path == "spatial_editor/viewport_zoom_modifier_1" || p_path == "spatial_editor/viewport_zoom_modifier_2";
  300. if (path_is_orbit_mod || path_is_pan_mod || path_is_zoom_mod) {
  301. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
  302. }
  303. }
  304. Array EditorSettingsDialog::_event_list_to_array_helper(const List<Ref<InputEvent>> &p_events) {
  305. Array events;
  306. // Convert the list to an array, and only keep key events as this is for the editor.
  307. for (const List<Ref<InputEvent>>::Element *E = p_events.front(); E; E = E->next()) {
  308. Ref<InputEventKey> k = E->get();
  309. if (k.is_valid()) {
  310. events.append(E->get());
  311. }
  312. }
  313. return events;
  314. }
  315. void 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) {
  316. TreeItem *shortcut_item = shortcuts->create_item(p_parent);
  317. shortcut_item->set_collapsed(p_is_collapsed);
  318. shortcut_item->set_text(0, p_display);
  319. Ref<InputEvent> primary = p_events.size() > 0 ? Ref<InputEvent>(p_events[0]) : Ref<InputEvent>();
  320. Ref<InputEvent> secondary = p_events.size() > 1 ? Ref<InputEvent>(p_events[1]) : Ref<InputEvent>();
  321. String sc_text = "None";
  322. if (primary.is_valid()) {
  323. sc_text = primary->as_text();
  324. if (secondary.is_valid()) {
  325. sc_text += ", " + secondary->as_text();
  326. if (p_events.size() > 2) {
  327. sc_text += " (+" + itos(p_events.size() - 2) + ")";
  328. }
  329. }
  330. }
  331. shortcut_item->set_text(1, sc_text);
  332. if (sc_text == "None") {
  333. // Fade out unassigned shortcut labels for easier visual grepping.
  334. shortcut_item->set_custom_color(1, shortcuts->get_theme_color(SceneStringName(font_color), SNAME("Label")) * Color(1, 1, 1, 0.5));
  335. }
  336. if (p_allow_revert) {
  337. shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Reload")), SHORTCUT_REVERT);
  338. }
  339. shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Add")), SHORTCUT_ADD);
  340. shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
  341. shortcut_item->set_meta("is_action", p_is_action);
  342. shortcut_item->set_meta("type", "shortcut");
  343. shortcut_item->set_meta("shortcut_identifier", p_shortcut_identifier);
  344. shortcut_item->set_meta("events", p_events);
  345. // Shortcut Input Events
  346. for (int i = 0; i < p_events.size(); i++) {
  347. Ref<InputEvent> ie = p_events[i];
  348. if (ie.is_null()) {
  349. continue;
  350. }
  351. TreeItem *event_item = shortcuts->create_item(shortcut_item);
  352. event_item->set_text(0, shortcut_item->get_child_count() == 1 ? "Primary" : "");
  353. event_item->set_text(1, ie->as_text());
  354. event_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Edit")), SHORTCUT_EDIT);
  355. event_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
  356. event_item->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
  357. event_item->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
  358. event_item->set_meta("is_action", p_is_action);
  359. event_item->set_meta("type", "event");
  360. event_item->set_meta("event_index", i);
  361. }
  362. }
  363. bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const Array &p_events) const {
  364. const Ref<InputEvent> search_ev = shortcut_search_by_event->get_event();
  365. bool event_match = true;
  366. if (search_ev.is_valid()) {
  367. event_match = false;
  368. for (int i = 0; i < p_events.size(); ++i) {
  369. const Ref<InputEvent> ev = p_events[i];
  370. if (ev.is_valid() && ev->is_match(search_ev, true)) {
  371. event_match = true;
  372. }
  373. }
  374. }
  375. return event_match && shortcut_search_box->get_text().is_subsequence_ofn(p_name);
  376. }
  377. void EditorSettingsDialog::_update_shortcuts() {
  378. // Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.
  379. HashMap<String, bool> collapsed;
  380. if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {
  381. TreeItem *ti = shortcuts->get_root()->get_first_child();
  382. while (ti) {
  383. // 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.
  384. if (ti->get_first_child() && ti->has_meta("shortcut_identifier")) {
  385. collapsed[ti->get_meta("shortcut_identifier")] = ti->is_collapsed();
  386. } else {
  387. collapsed[ti->get_text(0)] = ti->is_collapsed();
  388. }
  389. // Try go down tree
  390. TreeItem *ti_next = ti->get_first_child();
  391. // Try go to the next node via in-order traversal
  392. if (!ti_next) {
  393. ti_next = ti;
  394. while (ti_next && !ti_next->get_next()) {
  395. ti_next = ti_next->get_parent();
  396. }
  397. if (ti_next) {
  398. ti_next = ti_next->get_next();
  399. }
  400. }
  401. ti = ti_next;
  402. }
  403. }
  404. shortcuts->clear();
  405. TreeItem *root = shortcuts->create_item();
  406. HashMap<String, TreeItem *> sections;
  407. // Set up section for Common/Built-in actions
  408. TreeItem *common_section = shortcuts->create_item(root);
  409. sections["Common"] = common_section;
  410. common_section->set_text(0, TTR("Common"));
  411. common_section->set_selectable(0, false);
  412. common_section->set_selectable(1, false);
  413. if (collapsed.has("Common")) {
  414. common_section->set_collapsed(collapsed["Common"]);
  415. }
  416. common_section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  417. common_section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  418. // Get the action map for the editor, and add each item to the "Common" section.
  419. for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {
  420. const String &action_name = E.key;
  421. const InputMap::Action &action = E.value;
  422. // Skip non-builtin actions.
  423. if (!InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().has(action_name)) {
  424. continue;
  425. }
  426. const List<Ref<InputEvent>> &all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name)->value;
  427. Array action_events = _event_list_to_array_helper(action.inputs);
  428. if (!_should_display_shortcut(action_name, action_events)) {
  429. continue;
  430. }
  431. Array default_events = _event_list_to_array_helper(all_default_events);
  432. bool same_as_defaults = Shortcut::is_event_array_equal(default_events, action_events);
  433. bool collapse = !collapsed.has(action_name) || (collapsed.has(action_name) && collapsed[action_name]);
  434. _create_shortcut_treeitem(common_section, action_name, action_name, action_events, !same_as_defaults, true, collapse);
  435. }
  436. // Editor Shortcuts
  437. List<String> slist;
  438. EditorSettings::get_singleton()->get_shortcut_list(&slist);
  439. slist.sort(); // Sort alphabetically.
  440. const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
  441. const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
  442. // Create all sections first.
  443. for (const String &E : slist) {
  444. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
  445. String section_name = E.get_slice("/", 0);
  446. if (sections.has(section_name)) {
  447. continue;
  448. }
  449. TreeItem *section = shortcuts->create_item(root);
  450. const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, name_style, E);
  451. const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, tooltip_style, E);
  452. section->set_text(0, item_name);
  453. section->set_tooltip_text(0, tooltip);
  454. section->set_selectable(0, false);
  455. section->set_selectable(1, false);
  456. section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  457. section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  458. if (collapsed.has(item_name)) {
  459. section->set_collapsed(collapsed[item_name]);
  460. }
  461. sections[section_name] = section;
  462. }
  463. // Add shortcuts to sections.
  464. for (const String &E : slist) {
  465. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
  466. if (!sc->has_meta("original")) {
  467. continue;
  468. }
  469. String section_name = E.get_slice("/", 0);
  470. TreeItem *section = sections[section_name];
  471. if (!_should_display_shortcut(sc->get_name(), sc->get_events())) {
  472. continue;
  473. }
  474. Array original = sc->get_meta("original");
  475. Array shortcuts_array = sc->get_events().duplicate(true);
  476. bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);
  477. bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);
  478. _create_shortcut_treeitem(section, E, sc->get_name(), shortcuts_array, !same_as_defaults, false, collapse);
  479. }
  480. // remove sections with no shortcuts
  481. for (KeyValue<String, TreeItem *> &E : sections) {
  482. TreeItem *section = E.value;
  483. if (section->get_first_child() == nullptr) {
  484. root->remove_child(section);
  485. memdelete(section);
  486. }
  487. }
  488. // Update UI.
  489. clear_all_search->set_disabled(shortcut_search_box->get_text().is_empty() && shortcut_search_by_event->get_event().is_null());
  490. }
  491. void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button) {
  492. if (p_button != MouseButton::LEFT) {
  493. return;
  494. }
  495. TreeItem *ti = Object::cast_to<TreeItem>(p_item);
  496. ERR_FAIL_NULL_MSG(ti, "Object passed is not a TreeItem.");
  497. ShortcutButton button_idx = (ShortcutButton)p_idx;
  498. is_editing_action = ti->get_meta("is_action");
  499. String type = ti->get_meta("type");
  500. if (type == "event") {
  501. current_edited_identifier = ti->get_parent()->get_meta("shortcut_identifier");
  502. current_events = ti->get_parent()->get_meta("events");
  503. current_event_index = ti->get_meta("event_index");
  504. } else { // Type is "shortcut"
  505. current_edited_identifier = ti->get_meta("shortcut_identifier");
  506. current_events = ti->get_meta("events");
  507. current_event_index = -1;
  508. }
  509. switch (button_idx) {
  510. case EditorSettingsDialog::SHORTCUT_ADD: {
  511. // Only for "shortcut" types
  512. shortcut_editor->popup_and_configure();
  513. } break;
  514. case EditorSettingsDialog::SHORTCUT_EDIT: {
  515. // Only for "event" types
  516. shortcut_editor->popup_and_configure(current_events[current_event_index]);
  517. } break;
  518. case EditorSettingsDialog::SHORTCUT_ERASE: {
  519. if (type == "shortcut") {
  520. if (is_editing_action) {
  521. _update_builtin_action(current_edited_identifier, Array());
  522. } else {
  523. _update_shortcut_events(current_edited_identifier, Array());
  524. }
  525. } else if (type == "event") {
  526. current_events.remove_at(current_event_index);
  527. if (is_editing_action) {
  528. _update_builtin_action(current_edited_identifier, current_events);
  529. } else {
  530. _update_shortcut_events(current_edited_identifier, current_events);
  531. }
  532. }
  533. } break;
  534. case EditorSettingsDialog::SHORTCUT_REVERT: {
  535. // Only for "shortcut" types
  536. if (is_editing_action) {
  537. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
  538. Array events = _event_list_to_array_helper(defaults);
  539. _update_builtin_action(current_edited_identifier, events);
  540. } else {
  541. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(current_edited_identifier);
  542. Array original = sc->get_meta("original");
  543. _update_shortcut_events(current_edited_identifier, original);
  544. }
  545. } break;
  546. default:
  547. break;
  548. }
  549. }
  550. void EditorSettingsDialog::_shortcut_cell_double_clicked() {
  551. // When a shortcut cell is double clicked:
  552. // If the cell has children and is in the bindings column, and if its first child is editable,
  553. // then uncollapse the cell, and if the first child is the only child, then edit that child.
  554. // If the cell is in the bindings column and can be edited, then edit it.
  555. // If the cell is in the name column, then toggle collapse.
  556. const ShortcutButton edit_btn_id = EditorSettingsDialog::SHORTCUT_EDIT;
  557. const int edit_btn_col = 1;
  558. TreeItem *ti = shortcuts->get_selected();
  559. if (ti == nullptr) {
  560. return;
  561. }
  562. String type = ti->get_meta("type");
  563. int col = shortcuts->get_selected_column();
  564. if (type == "shortcut" && col == 0) {
  565. if (ti->get_first_child()) {
  566. ti->set_collapsed(!ti->is_collapsed());
  567. }
  568. } else if (type == "shortcut" && col == 1) {
  569. if (ti->get_first_child()) {
  570. TreeItem *child_ti = ti->get_first_child();
  571. if (child_ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
  572. ti->set_collapsed(false);
  573. if (ti->get_child_count() == 1) {
  574. _shortcut_button_pressed(child_ti, edit_btn_col, edit_btn_id);
  575. }
  576. }
  577. }
  578. } else if (type == "event" && col == 1) {
  579. if (ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
  580. _shortcut_button_pressed(ti, edit_btn_col, edit_btn_id);
  581. }
  582. }
  583. }
  584. Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  585. TreeItem *selected = shortcuts->get_selected();
  586. // Only allow drag for events
  587. if (!selected || (String)selected->get_meta("type", "") != "event") {
  588. return Variant();
  589. }
  590. String label_text = vformat(TTRC("Event %d"), selected->get_meta("event_index"));
  591. Label *label = memnew(Label(label_text));
  592. label->set_modulate(Color(1, 1, 1, 1.0f));
  593. shortcuts->set_drag_preview(label);
  594. shortcuts->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  595. return Dictionary(); // No data required
  596. }
  597. bool EditorSettingsDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  598. TreeItem *selected = shortcuts->get_selected();
  599. TreeItem *item = shortcuts->get_item_at_position(p_point);
  600. if (!selected || !item || item == selected || (String)item->get_meta("type", "") != "event") {
  601. return false;
  602. }
  603. // Don't allow moving an events in-between shortcuts.
  604. if (selected->get_parent()->get_meta("shortcut_identifier") != item->get_parent()->get_meta("shortcut_identifier")) {
  605. return false;
  606. }
  607. return true;
  608. }
  609. void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  610. if (!can_drop_data_fw(p_point, p_data, p_from)) {
  611. return;
  612. }
  613. TreeItem *selected = shortcuts->get_selected();
  614. TreeItem *target = shortcuts->get_item_at_position(p_point);
  615. if (!target) {
  616. return;
  617. }
  618. int target_event_index = target->get_meta("event_index");
  619. int index_moving_from = selected->get_meta("event_index");
  620. Array events = selected->get_parent()->get_meta("events");
  621. Variant event_moved = events[index_moving_from];
  622. events.remove_at(index_moving_from);
  623. events.insert(target_event_index, event_moved);
  624. String ident = selected->get_parent()->get_meta("shortcut_identifier");
  625. if (selected->get_meta("is_action")) {
  626. _update_builtin_action(ident, events);
  627. } else {
  628. _update_shortcut_events(ident, events);
  629. }
  630. }
  631. void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
  632. _focus_current_search_box();
  633. // When tab has switched, shortcuts may have changed.
  634. _update_dynamic_property_hints();
  635. inspector->get_inspector()->update_tree();
  636. }
  637. void EditorSettingsDialog::_update_dynamic_property_hints() {
  638. // Calling add_property_hint overrides the existing hint.
  639. EditorSettings *settings = EditorSettings::get_singleton();
  640. 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"));
  641. 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"));
  642. 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"));
  643. }
  644. PropertyInfo EditorSettingsDialog::_create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name) {
  645. String hint_string;
  646. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  647. hint_string += "Left Mouse,";
  648. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  649. hint_string += "Middle Mouse,";
  650. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  651. hint_string += "Right Mouse";
  652. return PropertyInfo(Variant::INT, p_property_name, PROPERTY_HINT_ENUM, hint_string);
  653. }
  654. String EditorSettingsDialog::_get_shortcut_button_string(const String &p_shortcut_name) {
  655. String button_string;
  656. Ref<Shortcut> shortcut_ref = EditorSettings::get_singleton()->get_shortcut(p_shortcut_name);
  657. Array events = shortcut_ref->get_events();
  658. for (Ref<InputEvent> input_event : events) {
  659. button_string += input_event->as_text() + " + ";
  660. }
  661. return button_string;
  662. }
  663. void EditorSettingsDialog::_focus_current_search_box() {
  664. Control *tab = tabs->get_current_tab_control();
  665. LineEdit *current_search_box = nullptr;
  666. if (tab == tab_general) {
  667. current_search_box = search_box;
  668. } else if (tab == tab_shortcuts) {
  669. current_search_box = shortcut_search_box;
  670. }
  671. if (current_search_box) {
  672. current_search_box->grab_focus();
  673. current_search_box->select_all();
  674. }
  675. }
  676. void EditorSettingsDialog::_advanced_toggled(bool p_button_pressed) {
  677. EditorSettings::get_singleton()->set("_editor_settings_advanced_mode", p_button_pressed);
  678. inspector->set_restrict_to_basic_settings(!p_button_pressed);
  679. }
  680. void EditorSettingsDialog::_editor_restart() {
  681. EditorNode::get_singleton()->save_all_scenes();
  682. EditorNode::get_singleton()->restart_editor();
  683. }
  684. void EditorSettingsDialog::_editor_restart_request() {
  685. restart_container->show();
  686. }
  687. void EditorSettingsDialog::_editor_restart_close() {
  688. restart_container->hide();
  689. }
  690. void EditorSettingsDialog::_bind_methods() {
  691. ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
  692. ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
  693. }
  694. EditorSettingsDialog::EditorSettingsDialog() {
  695. set_title(TTR("Editor Settings"));
  696. set_clamp_to_embedder(true);
  697. tabs = memnew(TabContainer);
  698. tabs->set_theme_type_variation("TabContainerOdd");
  699. tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));
  700. add_child(tabs);
  701. // General Tab
  702. tab_general = memnew(VBoxContainer);
  703. tabs->add_child(tab_general);
  704. tab_general->set_name(TTR("General"));
  705. HBoxContainer *hbc = memnew(HBoxContainer);
  706. hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  707. tab_general->add_child(hbc);
  708. search_box = memnew(LineEdit);
  709. search_box->set_placeholder(TTR("Filter Settings"));
  710. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  711. hbc->add_child(search_box);
  712. advanced_switch = memnew(CheckButton(TTR("Advanced Settings")));
  713. hbc->add_child(advanced_switch);
  714. bool use_advanced = EDITOR_DEF("_editor_settings_advanced_mode", false);
  715. advanced_switch->set_pressed(use_advanced);
  716. advanced_switch->connect(SceneStringName(toggled), callable_mp(this, &EditorSettingsDialog::_advanced_toggled));
  717. inspector = memnew(SectionedInspector);
  718. inspector->get_inspector()->set_use_filter(true);
  719. inspector->set_restrict_to_basic_settings(!use_advanced);
  720. inspector->register_search_box(search_box);
  721. inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  722. tab_general->add_child(inspector);
  723. inspector->get_inspector()->connect("property_edited", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));
  724. inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));
  725. restart_container = memnew(PanelContainer);
  726. tab_general->add_child(restart_container);
  727. HBoxContainer *restart_hb = memnew(HBoxContainer);
  728. restart_container->add_child(restart_hb);
  729. restart_icon = memnew(TextureRect);
  730. restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  731. restart_hb->add_child(restart_icon);
  732. restart_label = memnew(Label);
  733. restart_label->set_text(TTR("The editor must be restarted for changes to take effect."));
  734. restart_hb->add_child(restart_label);
  735. restart_hb->add_spacer();
  736. Button *restart_button = memnew(Button);
  737. restart_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart));
  738. restart_hb->add_child(restart_button);
  739. restart_button->set_text(TTR("Save & Restart"));
  740. restart_close_button = memnew(Button);
  741. restart_close_button->set_flat(true);
  742. restart_close_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart_close));
  743. restart_hb->add_child(restart_close_button);
  744. restart_container->hide();
  745. // Shortcuts Tab
  746. tab_shortcuts = memnew(VBoxContainer);
  747. tabs->add_child(tab_shortcuts);
  748. tab_shortcuts->set_name(TTR("Shortcuts"));
  749. HBoxContainer *top_hbox = memnew(HBoxContainer);
  750. top_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  751. tab_shortcuts->add_child(top_hbox);
  752. shortcut_search_box = memnew(LineEdit);
  753. shortcut_search_box->set_placeholder(TTR("Filter by Name"));
  754. shortcut_search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  755. top_hbox->add_child(shortcut_search_box);
  756. shortcut_search_box->connect(SceneStringName(text_changed), callable_mp(this, &EditorSettingsDialog::_filter_shortcuts));
  757. shortcut_search_by_event = memnew(EventListenerLineEdit);
  758. shortcut_search_by_event->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  759. shortcut_search_by_event->set_stretch_ratio(0.75);
  760. shortcut_search_by_event->set_allowed_input_types(INPUT_KEY);
  761. shortcut_search_by_event->connect("event_changed", callable_mp(this, &EditorSettingsDialog::_filter_shortcuts_by_event));
  762. shortcut_search_by_event->connect(SceneStringName(focus_entered), callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(false));
  763. shortcut_search_by_event->connect(SceneStringName(focus_exited), callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(true));
  764. top_hbox->add_child(shortcut_search_by_event);
  765. clear_all_search = memnew(Button);
  766. clear_all_search->set_text(TTR("Clear All"));
  767. clear_all_search->set_tooltip_text(TTR("Clear all search filters."));
  768. clear_all_search->connect(SceneStringName(pressed), callable_mp(shortcut_search_box, &LineEdit::clear));
  769. clear_all_search->connect(SceneStringName(pressed), callable_mp(shortcut_search_by_event, &EventListenerLineEdit::clear_event));
  770. top_hbox->add_child(clear_all_search);
  771. shortcuts = memnew(Tree);
  772. shortcuts->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  773. shortcuts->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  774. shortcuts->set_columns(2);
  775. shortcuts->set_hide_root(true);
  776. shortcuts->set_column_titles_visible(true);
  777. shortcuts->set_column_title(0, TTR("Name"));
  778. shortcuts->set_column_title(1, TTR("Binding"));
  779. shortcuts->connect("button_clicked", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));
  780. shortcuts->connect("item_activated", callable_mp(this, &EditorSettingsDialog::_shortcut_cell_double_clicked));
  781. tab_shortcuts->add_child(shortcuts);
  782. SET_DRAG_FORWARDING_GCD(shortcuts, EditorSettingsDialog);
  783. // Adding event dialog
  784. shortcut_editor = memnew(InputEventConfigurationDialog);
  785. shortcut_editor->connect(SceneStringName(confirmed), callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));
  786. shortcut_editor->set_allowed_input_types(INPUT_KEY);
  787. add_child(shortcut_editor);
  788. set_hide_on_ok(true);
  789. timer = memnew(Timer);
  790. timer->set_wait_time(1.5);
  791. timer->connect("timeout", callable_mp(this, &EditorSettingsDialog::_settings_save));
  792. timer->set_one_shot(true);
  793. add_child(timer);
  794. EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_changed));
  795. set_ok_button_text(TTR("Close"));
  796. }
  797. EditorSettingsDialog::~EditorSettingsDialog() {
  798. }