settings_config_dialog.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*************************************************************************/
  2. /* settings_config_dialog.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "settings_config_dialog.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/input/input_map.h"
  33. #include "core/os/keyboard.h"
  34. #include "editor/debugger/editor_debugger_node.h"
  35. #include "editor_file_system.h"
  36. #include "editor_log.h"
  37. #include "editor_node.h"
  38. #include "editor_scale.h"
  39. #include "editor_settings.h"
  40. #include "scene/gui/margin_container.h"
  41. void EditorSettingsDialog::ok_pressed() {
  42. if (!EditorSettings::get_singleton()) {
  43. return;
  44. }
  45. _settings_save();
  46. timer->stop();
  47. }
  48. void EditorSettingsDialog::_settings_changed() {
  49. timer->start();
  50. }
  51. void EditorSettingsDialog::_settings_property_edited(const String &p_name) {
  52. String full_name = inspector->get_full_item_path(p_name);
  53. if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast") {
  54. EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom"); // set preset to Custom
  55. } else if (full_name.begins_with("text_editor/highlighting")) {
  56. EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
  57. }
  58. }
  59. void EditorSettingsDialog::_settings_save() {
  60. EditorSettings::get_singleton()->notify_changes();
  61. EditorSettings::get_singleton()->save();
  62. }
  63. void EditorSettingsDialog::cancel_pressed() {
  64. if (!EditorSettings::get_singleton()) {
  65. return;
  66. }
  67. EditorSettings::get_singleton()->notify_changes();
  68. }
  69. void EditorSettingsDialog::popup_edit_settings() {
  70. if (!EditorSettings::get_singleton()) {
  71. return;
  72. }
  73. EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes
  74. inspector->edit(EditorSettings::get_singleton());
  75. inspector->get_inspector()->update_tree();
  76. search_box->select_all();
  77. search_box->grab_focus();
  78. _update_shortcuts();
  79. set_process_unhandled_input(true);
  80. // Restore valid window bounds or pop up at default size.
  81. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
  82. if (saved_size != Rect2()) {
  83. popup(saved_size);
  84. } else {
  85. popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
  86. }
  87. _focus_current_search_box();
  88. }
  89. void EditorSettingsDialog::_filter_shortcuts(const String &p_filter) {
  90. shortcut_filter = p_filter;
  91. _update_shortcuts();
  92. }
  93. void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {
  94. EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
  95. }
  96. void EditorSettingsDialog::_notification(int p_what) {
  97. switch (p_what) {
  98. case NOTIFICATION_VISIBILITY_CHANGED: {
  99. if (!is_visible()) {
  100. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));
  101. set_process_unhandled_input(false);
  102. }
  103. } break;
  104. case NOTIFICATION_READY: {
  105. undo_redo->set_method_notify_callback(EditorDebuggerNode::_method_changeds, nullptr);
  106. undo_redo->set_property_notify_callback(EditorDebuggerNode::_property_changeds, nullptr);
  107. undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
  108. } break;
  109. case NOTIFICATION_ENTER_TREE: {
  110. _update_icons();
  111. } break;
  112. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  113. _update_icons();
  114. // Update theme colors.
  115. inspector->update_category_list();
  116. _update_shortcuts();
  117. } break;
  118. }
  119. }
  120. void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
  121. ERR_FAIL_COND(p_event.is_null());
  122. const Ref<InputEventKey> k = p_event;
  123. if (k.is_valid() && k->is_pressed()) {
  124. bool handled = false;
  125. if (ED_IS_SHORTCUT("ui_undo", p_event)) {
  126. String action = undo_redo->get_current_action_name();
  127. if (action != "") {
  128. EditorNode::get_log()->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR);
  129. }
  130. undo_redo->undo();
  131. handled = true;
  132. }
  133. if (ED_IS_SHORTCUT("ui_redo", p_event)) {
  134. undo_redo->redo();
  135. String action = undo_redo->get_current_action_name();
  136. if (action != "") {
  137. EditorNode::get_log()->add_message("Redo: " + action, EditorLog::MSG_TYPE_EDITOR);
  138. }
  139. handled = true;
  140. }
  141. if (k->get_keycode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) {
  142. _focus_current_search_box();
  143. handled = true;
  144. }
  145. if (handled) {
  146. set_input_as_handled();
  147. }
  148. }
  149. }
  150. void EditorSettingsDialog::_update_icons() {
  151. search_box->set_right_icon(shortcuts->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
  152. search_box->set_clear_button_enabled(true);
  153. shortcut_search_box->set_right_icon(shortcuts->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
  154. shortcut_search_box->set_clear_button_enabled(true);
  155. restart_close_button->set_icon(shortcuts->get_theme_icon(SNAME("Close"), SNAME("EditorIcons")));
  156. restart_container->add_theme_style_override("panel", shortcuts->get_theme_stylebox(SNAME("bg"), SNAME("Tree")));
  157. restart_icon->set_texture(shortcuts->get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
  158. restart_label->add_theme_color_override("font_color", shortcuts->get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  159. }
  160. void EditorSettingsDialog::_event_config_confirmed() {
  161. Ref<InputEventKey> k = shortcut_editor->get_event();
  162. if (k.is_null()) {
  163. return;
  164. }
  165. if (editing_action) {
  166. if (current_action_event_index == -1) {
  167. // Add new event
  168. current_action_events.push_back(k);
  169. } else {
  170. // Edit existing event
  171. current_action_events[current_action_event_index] = k;
  172. }
  173. _update_builtin_action(current_action, current_action_events);
  174. } else {
  175. k = k->duplicate();
  176. Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(shortcut_being_edited);
  177. undo_redo->create_action(TTR("Change Shortcut") + " '" + shortcut_being_edited + "'");
  178. undo_redo->add_do_method(current_sc.ptr(), "set_shortcut", k);
  179. undo_redo->add_undo_method(current_sc.ptr(), "set_shortcut", current_sc->get_shortcut());
  180. undo_redo->add_do_method(this, "_update_shortcuts");
  181. undo_redo->add_undo_method(this, "_update_shortcuts");
  182. undo_redo->add_do_method(this, "_settings_changed");
  183. undo_redo->add_undo_method(this, "_settings_changed");
  184. undo_redo->commit_action();
  185. }
  186. }
  187. void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
  188. Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(current_action);
  189. undo_redo->create_action(TTR("Edit Built-in Action"));
  190. undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);
  191. undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);
  192. undo_redo->add_do_method(this, "_settings_changed");
  193. undo_redo->add_undo_method(this, "_settings_changed");
  194. undo_redo->commit_action();
  195. _update_shortcuts();
  196. }
  197. void EditorSettingsDialog::_update_shortcuts() {
  198. // Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.
  199. Map<String, bool> collapsed;
  200. if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {
  201. for (TreeItem *item = shortcuts->get_root()->get_first_child(); item; item = item->get_next()) {
  202. collapsed[item->get_text(0)] = item->is_collapsed();
  203. }
  204. }
  205. shortcuts->clear();
  206. TreeItem *root = shortcuts->create_item();
  207. Map<String, TreeItem *> sections;
  208. // Set up section for Common/Built-in actions
  209. TreeItem *common_section = shortcuts->create_item(root);
  210. sections["Common"] = common_section;
  211. common_section->set_text(0, TTR("Common"));
  212. if (collapsed.has("Common")) {
  213. common_section->set_collapsed(collapsed["Common"]);
  214. }
  215. common_section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
  216. common_section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
  217. // Get the action map for the editor, and add each item to the "Common" section.
  218. OrderedHashMap<StringName, InputMap::Action> action_map = InputMap::get_singleton()->get_action_map();
  219. for (OrderedHashMap<StringName, InputMap::Action>::Element E = action_map.front(); E; E = E.next()) {
  220. String action_name = E.key();
  221. InputMap::Action action = E.get();
  222. Array events; // Need to get the list of events into an array so it can be set as metadata on the item.
  223. Vector<String> event_strings;
  224. List<Ref<InputEvent>> all_default_events = InputMap::get_singleton()->get_builtins().find(action_name).value();
  225. List<Ref<InputEventKey>> key_default_events;
  226. // Remove all non-key events from the defaults. Only check keys, since we are in the editor.
  227. for (List<Ref<InputEvent>>::Element *I = all_default_events.front(); I; I = I->next()) {
  228. Ref<InputEventKey> k = I->get();
  229. if (k.is_valid()) {
  230. key_default_events.push_back(k);
  231. }
  232. }
  233. bool same_as_defaults = key_default_events.size() == action.inputs.size(); // Initially this is set to just whether the arrays are equal. Later we check the events if needed.
  234. int count = 0;
  235. for (List<Ref<InputEvent>>::Element *I = action.inputs.front(); I; I = I->next()) {
  236. // Add event and event text to respective arrays.
  237. events.push_back(I->get());
  238. event_strings.push_back(I->get()->as_text());
  239. // Only check if the events have been the same so far - once one fails, we don't need to check any more.
  240. if (same_as_defaults && !key_default_events[count]->is_match(I->get())) {
  241. same_as_defaults = false;
  242. }
  243. count++;
  244. }
  245. // Join the text of the events with a delimiter so they can all be displayed in one cell.
  246. String events_display_string = event_strings.is_empty() ? "None" : String("; ").join(event_strings);
  247. if (!shortcut_filter.is_subsequence_ofi(action_name) && (events_display_string == "None" || !shortcut_filter.is_subsequence_ofi(events_display_string))) {
  248. continue;
  249. }
  250. TreeItem *item = shortcuts->create_item(common_section);
  251. item->set_text(0, action_name);
  252. item->set_text(1, events_display_string);
  253. if (!same_as_defaults) {
  254. item->add_button(1, shortcuts->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")), 2);
  255. }
  256. if (events_display_string == "None") {
  257. // Fade out unassigned shortcut labels for easier visual grepping.
  258. item->set_custom_color(1, shortcuts->get_theme_color(SNAME("font_color"), SNAME("Label")) * Color(1, 1, 1, 0.5));
  259. }
  260. item->add_button(1, shortcuts->get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0);
  261. item->add_button(1, shortcuts->get_theme_icon(SNAME("Close"), SNAME("EditorIcons")), 1);
  262. item->set_tooltip(0, action_name);
  263. item->set_tooltip(1, events_display_string);
  264. item->set_metadata(0, "Common");
  265. item->set_metadata(1, events);
  266. }
  267. // Editor Shortcuts
  268. List<String> slist;
  269. EditorSettings::get_singleton()->get_shortcut_list(&slist);
  270. for (const String &E : slist) {
  271. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
  272. if (!sc->has_meta("original")) {
  273. continue;
  274. }
  275. Ref<InputEvent> original = sc->get_meta("original");
  276. String section_name = E.get_slice("/", 0);
  277. TreeItem *section;
  278. if (sections.has(section_name)) {
  279. section = sections[section_name];
  280. } else {
  281. section = shortcuts->create_item(root);
  282. String item_name = section_name.capitalize();
  283. section->set_text(0, item_name);
  284. if (collapsed.has(item_name)) {
  285. section->set_collapsed(collapsed[item_name]);
  286. }
  287. sections[section_name] = section;
  288. section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
  289. section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
  290. }
  291. // Don't match unassigned shortcuts when searching for assigned keys in search results.
  292. // This prevents all unassigned shortcuts from appearing when searching a string like "no".
  293. if (shortcut_filter.is_subsequence_ofi(sc->get_name()) || (sc->get_as_text() != "None" && shortcut_filter.is_subsequence_ofi(sc->get_as_text()))) {
  294. TreeItem *item = shortcuts->create_item(section);
  295. item->set_text(0, sc->get_name());
  296. item->set_text(1, sc->get_as_text());
  297. if (!sc->is_shortcut(original) && !(sc->get_shortcut().is_null() && original.is_null())) {
  298. item->add_button(1, shortcuts->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")), 2);
  299. }
  300. if (sc->get_as_text() == "None") {
  301. // Fade out unassigned shortcut labels for easier visual grepping.
  302. item->set_custom_color(1, shortcuts->get_theme_color(SNAME("font_color"), SNAME("Label")) * Color(1, 1, 1, 0.5));
  303. }
  304. item->add_button(1, shortcuts->get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0);
  305. item->add_button(1, shortcuts->get_theme_icon(SNAME("Close"), SNAME("EditorIcons")), 1);
  306. item->set_tooltip(0, E);
  307. item->set_metadata(0, E);
  308. }
  309. }
  310. // remove sections with no shortcuts
  311. for (Map<String, TreeItem *>::Element *E = sections.front(); E; E = E->next()) {
  312. TreeItem *section = E->get();
  313. if (section->get_first_child() == nullptr) {
  314. root->remove_child(section);
  315. }
  316. }
  317. }
  318. void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx) {
  319. TreeItem *ti = Object::cast_to<TreeItem>(p_item);
  320. ERR_FAIL_COND(!ti);
  321. button_idx = p_idx;
  322. if (ti->get_metadata(0) == "Common") {
  323. // Editing a Built-in action, which can have multiple bindings.
  324. editing_action = true;
  325. current_action = ti->get_text(0);
  326. switch (button_idx) {
  327. case SHORTCUT_REVERT: {
  328. Array events;
  329. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[current_action];
  330. // Convert the list to an array, and only keep key events as this is for the editor.
  331. for (Ref<InputEvent> k : defaults) {
  332. if (k.is_valid()) {
  333. events.append(k);
  334. }
  335. }
  336. _update_builtin_action(current_action, events);
  337. } break;
  338. case SHORTCUT_EDIT:
  339. case SHORTCUT_ERASE: {
  340. // For Edit end Delete, we will show a popup which displays each event so the user can select which one to edit/delete.
  341. current_action_events = ti->get_metadata(1);
  342. action_popup->clear();
  343. for (int i = 0; i < current_action_events.size(); i++) {
  344. Ref<InputEvent> ie = current_action_events[i];
  345. action_popup->add_item(ie->as_text());
  346. action_popup->set_item_metadata(i, ie);
  347. }
  348. if (button_idx == SHORTCUT_EDIT) {
  349. // If editing, add a button which can be used to add an additional event.
  350. action_popup->add_icon_item(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), TTR("Add"));
  351. }
  352. action_popup->set_position(get_position() + get_mouse_position());
  353. action_popup->take_mouse_focus();
  354. action_popup->popup();
  355. action_popup->set_as_minsize();
  356. } break;
  357. default:
  358. break;
  359. }
  360. } else {
  361. // Editing an Editor Shortcut, which can only have 1 binding.
  362. String item = ti->get_metadata(0);
  363. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(item);
  364. editing_action = false;
  365. switch (button_idx) {
  366. case EditorSettingsDialog::SHORTCUT_EDIT:
  367. shortcut_editor->popup_and_configure(sc->get_shortcut());
  368. shortcut_being_edited = item;
  369. break;
  370. case EditorSettingsDialog::SHORTCUT_ERASE: {
  371. if (!sc.is_valid()) {
  372. return; //pointless, there is nothing
  373. }
  374. undo_redo->create_action(TTR("Erase Shortcut"));
  375. undo_redo->add_do_method(sc.ptr(), "set_shortcut", Ref<InputEvent>());
  376. undo_redo->add_undo_method(sc.ptr(), "set_shortcut", sc->get_shortcut());
  377. undo_redo->add_do_method(this, "_update_shortcuts");
  378. undo_redo->add_undo_method(this, "_update_shortcuts");
  379. undo_redo->add_do_method(this, "_settings_changed");
  380. undo_redo->add_undo_method(this, "_settings_changed");
  381. undo_redo->commit_action();
  382. } break;
  383. case EditorSettingsDialog::SHORTCUT_REVERT: {
  384. if (!sc.is_valid()) {
  385. return; //pointless, there is nothing
  386. }
  387. Ref<InputEvent> original = sc->get_meta("original");
  388. undo_redo->create_action(TTR("Restore Shortcut"));
  389. undo_redo->add_do_method(sc.ptr(), "set_shortcut", original);
  390. undo_redo->add_undo_method(sc.ptr(), "set_shortcut", sc->get_shortcut());
  391. undo_redo->add_do_method(this, "_update_shortcuts");
  392. undo_redo->add_undo_method(this, "_update_shortcuts");
  393. undo_redo->add_do_method(this, "_settings_changed");
  394. undo_redo->add_undo_method(this, "_settings_changed");
  395. undo_redo->commit_action();
  396. } break;
  397. default:
  398. break;
  399. }
  400. }
  401. }
  402. void EditorSettingsDialog::_builtin_action_popup_index_pressed(int p_index) {
  403. switch (button_idx) {
  404. case SHORTCUT_EDIT: {
  405. if (p_index == action_popup->get_item_count() - 1) {
  406. // Selected last item in list (Add button), therefore add new
  407. current_action_event_index = -1;
  408. shortcut_editor->popup_and_configure();
  409. } else {
  410. // Configure existing
  411. current_action_event_index = p_index;
  412. shortcut_editor->popup_and_configure(action_popup->get_item_metadata(p_index));
  413. }
  414. } break;
  415. case SHORTCUT_ERASE: {
  416. current_action_events.remove(p_index);
  417. _update_builtin_action(current_action, current_action_events);
  418. } break;
  419. default:
  420. break;
  421. }
  422. }
  423. void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
  424. _focus_current_search_box();
  425. }
  426. void EditorSettingsDialog::_focus_current_search_box() {
  427. Control *tab = tabs->get_current_tab_control();
  428. LineEdit *current_search_box = nullptr;
  429. if (tab == tab_general) {
  430. current_search_box = search_box;
  431. } else if (tab == tab_shortcuts) {
  432. current_search_box = shortcut_search_box;
  433. }
  434. if (current_search_box) {
  435. current_search_box->grab_focus();
  436. current_search_box->select_all();
  437. }
  438. }
  439. void EditorSettingsDialog::_editor_restart() {
  440. EditorNode::get_singleton()->save_all_scenes();
  441. EditorNode::get_singleton()->restart_editor();
  442. }
  443. void EditorSettingsDialog::_editor_restart_request() {
  444. restart_container->show();
  445. }
  446. void EditorSettingsDialog::_editor_restart_close() {
  447. restart_container->hide();
  448. }
  449. void EditorSettingsDialog::_bind_methods() {
  450. ClassDB::bind_method(D_METHOD("_unhandled_input"), &EditorSettingsDialog::_unhandled_input);
  451. ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
  452. ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
  453. }
  454. EditorSettingsDialog::EditorSettingsDialog() {
  455. action_popup = memnew(PopupMenu);
  456. action_popup->connect("index_pressed", callable_mp(this, &EditorSettingsDialog::_builtin_action_popup_index_pressed));
  457. add_child(action_popup);
  458. set_title(TTR("Editor Settings"));
  459. undo_redo = memnew(UndoRedo);
  460. tabs = memnew(TabContainer);
  461. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  462. tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));
  463. add_child(tabs);
  464. // General Tab
  465. tab_general = memnew(VBoxContainer);
  466. tabs->add_child(tab_general);
  467. tab_general->set_name(TTR("General"));
  468. HBoxContainer *hbc = memnew(HBoxContainer);
  469. hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  470. tab_general->add_child(hbc);
  471. search_box = memnew(LineEdit);
  472. search_box->set_placeholder(TTR("Search"));
  473. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  474. hbc->add_child(search_box);
  475. inspector = memnew(SectionedInspector);
  476. inspector->get_inspector()->set_use_filter(true);
  477. inspector->register_search_box(search_box);
  478. inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  479. inspector->get_inspector()->set_undo_redo(undo_redo);
  480. tab_general->add_child(inspector);
  481. inspector->get_inspector()->connect("property_edited", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));
  482. inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));
  483. restart_container = memnew(PanelContainer);
  484. tab_general->add_child(restart_container);
  485. HBoxContainer *restart_hb = memnew(HBoxContainer);
  486. restart_container->add_child(restart_hb);
  487. restart_icon = memnew(TextureRect);
  488. restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  489. restart_hb->add_child(restart_icon);
  490. restart_label = memnew(Label);
  491. restart_label->set_text(TTR("The editor must be restarted for changes to take effect."));
  492. restart_hb->add_child(restart_label);
  493. restart_hb->add_spacer();
  494. Button *restart_button = memnew(Button);
  495. restart_button->connect("pressed", callable_mp(this, &EditorSettingsDialog::_editor_restart));
  496. restart_hb->add_child(restart_button);
  497. restart_button->set_text(TTR("Save & Restart"));
  498. restart_close_button = memnew(Button);
  499. restart_close_button->set_flat(true);
  500. restart_close_button->connect("pressed", callable_mp(this, &EditorSettingsDialog::_editor_restart_close));
  501. restart_hb->add_child(restart_close_button);
  502. restart_container->hide();
  503. // Shortcuts Tab
  504. tab_shortcuts = memnew(VBoxContainer);
  505. tabs->add_child(tab_shortcuts);
  506. tab_shortcuts->set_name(TTR("Shortcuts"));
  507. shortcut_search_box = memnew(LineEdit);
  508. shortcut_search_box->set_placeholder(TTR("Search"));
  509. shortcut_search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  510. tab_shortcuts->add_child(shortcut_search_box);
  511. shortcut_search_box->connect("text_changed", callable_mp(this, &EditorSettingsDialog::_filter_shortcuts));
  512. shortcuts = memnew(Tree);
  513. shortcuts->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  514. shortcuts->set_columns(2);
  515. shortcuts->set_hide_root(true);
  516. shortcuts->set_column_titles_visible(true);
  517. shortcuts->set_column_title(0, TTR("Name"));
  518. shortcuts->set_column_title(1, TTR("Binding"));
  519. shortcuts->connect("button_pressed", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));
  520. tab_shortcuts->add_child(shortcuts);
  521. // Adding event dialog
  522. shortcut_editor = memnew(InputEventConfigurationDialog);
  523. shortcut_editor->connect("confirmed", callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));
  524. shortcut_editor->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_KEY);
  525. add_child(shortcut_editor);
  526. set_hide_on_ok(true);
  527. timer = memnew(Timer);
  528. timer->set_wait_time(1.5);
  529. timer->connect("timeout", callable_mp(this, &EditorSettingsDialog::_settings_save));
  530. timer->set_one_shot(true);
  531. add_child(timer);
  532. EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_changed));
  533. get_ok_button()->set_text(TTR("Close"));
  534. updating = false;
  535. }
  536. EditorSettingsDialog::~EditorSettingsDialog() {
  537. memdelete(undo_redo);
  538. }