settings_config_dialog.cpp 24 KB

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