editor_settings_dialog.cpp 41 KB

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