2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* settings_config_dialog.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2022-01-13 08:45:09 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "settings_config_dialog.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/keyboard.h"
|
|
|
|
#include "core/project_settings.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "editor_file_system.h"
|
2019-12-24 07:17:23 +00:00
|
|
|
#include "editor_log.h"
|
2016-06-05 00:31:29 +00:00
|
|
|
#include "editor_node.h"
|
2019-12-24 07:17:23 +00:00
|
|
|
#include "editor_scale.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor_settings.h"
|
|
|
|
#include "scene/gui/margin_container.h"
|
2017-10-15 11:36:36 +00:00
|
|
|
#include "script_editor_debugger.h"
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void EditorSettingsDialog::ok_pressed() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!EditorSettings::get_singleton()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_settings_save();
|
|
|
|
timer->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_settings_changed() {
|
|
|
|
timer->start();
|
2016-07-18 21:46:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorSettingsDialog::_settings_property_edited(const String &p_name) {
|
2018-07-19 21:58:15 +00:00
|
|
|
String full_name = inspector->get_full_item_path(p_name);
|
2016-07-18 21:46:16 +00:00
|
|
|
|
2018-09-15 18:22:09 +00:00
|
|
|
if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast") {
|
2018-06-23 09:05:12 +00:00
|
|
|
EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom"); // set preset to Custom
|
2017-12-26 19:41:08 +00:00
|
|
|
} else if (full_name.begins_with("text_editor/highlighting")) {
|
|
|
|
EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
|
2016-07-18 21:46:16 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_settings_save() {
|
|
|
|
EditorSettings::get_singleton()->notify_changes();
|
|
|
|
EditorSettings::get_singleton()->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::cancel_pressed() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!EditorSettings::get_singleton()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorSettings::get_singleton()->notify_changes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::popup_edit_settings() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!EditorSettings::get_singleton()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-04-12 14:45:31 +00:00
|
|
|
EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes
|
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
inspector->edit(EditorSettings::get_singleton());
|
|
|
|
inspector->get_inspector()->update_tree();
|
2015-11-21 16:42:15 +00:00
|
|
|
|
2016-01-23 19:05:27 +00:00
|
|
|
search_box->select_all();
|
|
|
|
search_box->grab_focus();
|
|
|
|
|
2016-06-05 00:31:29 +00:00
|
|
|
_update_shortcuts();
|
2017-10-15 11:36:36 +00:00
|
|
|
set_process_unhandled_input(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-02 21:43:56 +00:00
|
|
|
// Restore valid window bounds or pop up at default size.
|
2018-12-04 15:52:56 +00:00
|
|
|
Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
|
|
|
|
if (saved_size != Rect2()) {
|
|
|
|
popup(saved_size);
|
2017-03-02 21:43:56 +00:00
|
|
|
} else {
|
2019-04-26 19:36:44 +00:00
|
|
|
popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
|
2017-03-02 21:43:56 +00:00
|
|
|
}
|
2017-12-17 17:22:26 +00:00
|
|
|
|
|
|
|
_focus_current_search_box();
|
2017-03-02 21:43:56 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorSettingsDialog::_filter_shortcuts(const String &p_filter) {
|
2016-07-03 13:07:16 +00:00
|
|
|
shortcut_filter = p_filter;
|
|
|
|
_update_shortcuts();
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:36:36 +00:00
|
|
|
void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {
|
2019-09-19 23:56:09 +00:00
|
|
|
EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
|
2017-10-15 11:36:36 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void EditorSettingsDialog::_notification(int p_what) {
|
2017-03-02 21:43:56 +00:00
|
|
|
switch (p_what) {
|
2017-10-15 11:36:36 +00:00
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
undo_redo->set_method_notify_callback(sed->_method_changeds, sed);
|
|
|
|
undo_redo->set_property_notify_callback(sed->_property_changeds, sed);
|
|
|
|
undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
|
|
|
|
} break;
|
2017-03-02 21:43:56 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2017-12-17 17:22:26 +00:00
|
|
|
_update_icons();
|
2017-03-02 21:43:56 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_POPUP_HIDE: {
|
2018-12-04 15:52:56 +00:00
|
|
|
EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", get_rect());
|
2017-10-15 11:36:36 +00:00
|
|
|
set_process_unhandled_input(false);
|
2017-03-02 21:43:56 +00:00
|
|
|
} break;
|
2017-12-17 17:22:26 +00:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
|
|
|
_update_icons();
|
|
|
|
// Update theme colors.
|
2018-07-19 21:58:15 +00:00
|
|
|
inspector->update_category_list();
|
2017-12-17 17:22:26 +00:00
|
|
|
_update_shortcuts();
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:36:36 +00:00
|
|
|
void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
|
2019-10-06 15:13:56 +00:00
|
|
|
const Ref<InputEventKey> k = p_event;
|
2017-10-15 11:36:36 +00:00
|
|
|
|
2019-10-06 15:13:56 +00:00
|
|
|
if (k.is_valid() && is_window_modal_on_top() && k->is_pressed()) {
|
|
|
|
bool handled = false;
|
2017-10-15 11:36:36 +00:00
|
|
|
|
2019-10-06 15:13:56 +00:00
|
|
|
if (ED_IS_SHORTCUT("editor/undo", p_event)) {
|
|
|
|
String action = undo_redo->get_current_action_name();
|
2021-05-05 10:44:11 +00:00
|
|
|
if (action != "") {
|
2019-10-06 15:13:56 +00:00
|
|
|
EditorNode::get_log()->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2019-10-06 15:13:56 +00:00
|
|
|
undo_redo->undo();
|
|
|
|
handled = true;
|
|
|
|
}
|
2017-10-15 11:36:36 +00:00
|
|
|
|
2019-10-06 15:13:56 +00:00
|
|
|
if (ED_IS_SHORTCUT("editor/redo", p_event)) {
|
|
|
|
undo_redo->redo();
|
|
|
|
String action = undo_redo->get_current_action_name();
|
2021-05-05 10:44:11 +00:00
|
|
|
if (action != "") {
|
2019-10-06 15:13:56 +00:00
|
|
|
EditorNode::get_log()->add_message("Redo: " + action, EditorLog::MSG_TYPE_EDITOR);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2019-10-06 15:13:56 +00:00
|
|
|
handled = true;
|
|
|
|
}
|
2017-10-15 11:36:36 +00:00
|
|
|
|
2019-10-06 15:13:56 +00:00
|
|
|
if (k->get_scancode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) {
|
|
|
|
_focus_current_search_box();
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
accept_event();
|
2017-10-15 11:36:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 17:22:26 +00:00
|
|
|
void EditorSettingsDialog::_update_icons() {
|
2018-08-11 10:04:19 +00:00
|
|
|
search_box->set_right_icon(get_icon("Search", "EditorIcons"));
|
2018-07-26 11:45:38 +00:00
|
|
|
search_box->set_clear_button_enabled(true);
|
2018-08-11 10:04:19 +00:00
|
|
|
shortcut_search_box->set_right_icon(get_icon("Search", "EditorIcons"));
|
2018-07-26 11:45:38 +00:00
|
|
|
shortcut_search_box->set_clear_button_enabled(true);
|
2018-07-19 21:58:15 +00:00
|
|
|
|
|
|
|
restart_close_button->set_icon(get_icon("Close", "EditorIcons"));
|
|
|
|
restart_container->add_style_override("panel", get_stylebox("bg", "Tree"));
|
|
|
|
restart_icon->set_texture(get_icon("StatusWarning", "EditorIcons"));
|
2019-03-25 13:04:31 +00:00
|
|
|
restart_label->add_color_override("font_color", get_color("warning_color", "Editor"));
|
2017-12-17 17:22:26 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 00:31:29 +00:00
|
|
|
void EditorSettingsDialog::_update_shortcuts() {
|
2018-03-23 22:02:38 +00:00
|
|
|
Map<String, bool> collapsed;
|
|
|
|
|
|
|
|
if (shortcuts->get_root() && shortcuts->get_root()->get_children()) {
|
|
|
|
for (TreeItem *item = shortcuts->get_root()->get_children(); item; item = item->get_next()) {
|
|
|
|
collapsed[item->get_text(0)] = item->is_collapsed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 00:31:29 +00:00
|
|
|
shortcuts->clear();
|
|
|
|
|
|
|
|
List<String> slist;
|
|
|
|
EditorSettings::get_singleton()->get_shortcut_list(&slist);
|
|
|
|
TreeItem *root = shortcuts->create_item();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<String, TreeItem *> sections;
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<String>::Element *E = slist.front(); E; E = E->next()) {
|
2016-06-05 00:31:29 +00:00
|
|
|
Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(E->get());
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!sc->has_meta("original")) {
|
2016-06-05 00:31:29 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEvent> original = sc->get_meta("original");
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String section_name = E->get().get_slice("/", 0);
|
2016-06-05 00:31:29 +00:00
|
|
|
|
|
|
|
TreeItem *section;
|
|
|
|
|
|
|
|
if (sections.has(section_name)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
section = sections[section_name];
|
2016-06-05 00:31:29 +00:00
|
|
|
} else {
|
|
|
|
section = shortcuts->create_item(root);
|
2018-03-23 22:02:38 +00:00
|
|
|
|
|
|
|
String item_name = section_name.capitalize();
|
|
|
|
section->set_text(0, item_name);
|
|
|
|
|
|
|
|
if (collapsed.has(item_name)) {
|
|
|
|
section->set_collapsed(collapsed[item_name]);
|
|
|
|
}
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
sections[section_name] = section;
|
|
|
|
section->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
|
|
|
|
section->set_custom_bg_color(1, get_color("prop_subsection", "Editor"));
|
2016-06-05 00:31:29 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 13:52:49 +00:00
|
|
|
// Don't match unassigned shortcuts when searching for assigned keys in search results.
|
|
|
|
// This prevents all unassigned shortcuts from appearing when searching a string like "no".
|
|
|
|
if (shortcut_filter.is_subsequence_ofi(sc->get_name()) || (sc->get_as_text() != "None" && shortcut_filter.is_subsequence_ofi(sc->get_as_text()))) {
|
2016-07-03 13:07:16 +00:00
|
|
|
TreeItem *item = shortcuts->create_item(section);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
item->set_text(0, sc->get_name());
|
|
|
|
item->set_text(1, sc->get_as_text());
|
2019-12-12 13:52:49 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!sc->is_shortcut(original) && !(sc->get_shortcut().is_null() && original.is_null())) {
|
2017-03-05 15:44:50 +00:00
|
|
|
item->add_button(1, get_icon("Reload", "EditorIcons"), 2);
|
2016-07-03 13:07:16 +00:00
|
|
|
}
|
2019-12-12 13:52:49 +00:00
|
|
|
|
|
|
|
if (sc->get_as_text() == "None") {
|
|
|
|
// Fade out unassigned shortcut labels for easier visual grepping.
|
|
|
|
item->set_custom_color(1, get_color("font_color", "Label") * Color(1, 1, 1, 0.5));
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
item->add_button(1, get_icon("Edit", "EditorIcons"), 0);
|
|
|
|
item->add_button(1, get_icon("Close", "EditorIcons"), 1);
|
|
|
|
item->set_tooltip(0, E->get());
|
|
|
|
item->set_metadata(0, E->get());
|
2016-06-05 00:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 13:07:16 +00:00
|
|
|
// remove sections with no shortcuts
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<String, TreeItem *>::Element *E = sections.front(); E; E = E->next()) {
|
2016-07-03 13:07:16 +00:00
|
|
|
TreeItem *section = E->get();
|
2021-05-04 14:00:45 +00:00
|
|
|
if (section->get_children() == nullptr) {
|
2016-07-03 13:07:16 +00:00
|
|
|
root->remove_child(section);
|
|
|
|
}
|
|
|
|
}
|
2016-06-05 00:31:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx) {
|
2017-08-24 20:58:51 +00:00
|
|
|
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
|
2016-06-05 00:31:29 +00:00
|
|
|
ERR_FAIL_COND(!ti);
|
|
|
|
|
|
|
|
String item = ti->get_metadata(0);
|
|
|
|
Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_idx == 0) {
|
2018-04-22 17:36:01 +00:00
|
|
|
press_a_key_label->set_text(TTR("Press a Key..."));
|
2017-05-20 15:38:03 +00:00
|
|
|
last_wait_for_key = Ref<InputEventKey>();
|
2017-03-05 15:44:50 +00:00
|
|
|
press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
|
2016-06-05 00:31:29 +00:00
|
|
|
press_a_key->grab_focus();
|
|
|
|
press_a_key->get_ok()->set_focus_mode(FOCUS_NONE);
|
|
|
|
press_a_key->get_cancel()->set_focus_mode(FOCUS_NONE);
|
2017-03-05 15:44:50 +00:00
|
|
|
shortcut_configured = item;
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_idx == 1) { //erase
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!sc.is_valid()) {
|
2016-06-05 00:31:29 +00:00
|
|
|
return; //pointless, there is nothing
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2019-02-21 19:41:01 +00:00
|
|
|
undo_redo->create_action(TTR("Erase Shortcut"));
|
2017-10-15 11:36:36 +00:00
|
|
|
undo_redo->add_do_method(sc.ptr(), "set_shortcut", Ref<InputEvent>());
|
|
|
|
undo_redo->add_undo_method(sc.ptr(), "set_shortcut", sc->get_shortcut());
|
|
|
|
undo_redo->add_do_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_undo_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_idx == 2) { //revert to original
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!sc.is_valid()) {
|
2016-06-05 00:31:29 +00:00
|
|
|
return; //pointless, there is nothing
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEvent> original = sc->get_meta("original");
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2019-02-21 19:41:01 +00:00
|
|
|
undo_redo->create_action(TTR("Restore Shortcut"));
|
2017-10-15 11:36:36 +00:00
|
|
|
undo_redo->add_do_method(sc.ptr(), "set_shortcut", original);
|
|
|
|
undo_redo->add_undo_method(sc.ptr(), "set_shortcut", sc->get_shortcut());
|
|
|
|
undo_redo->add_do_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_undo_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
2016-06-05 00:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void EditorSettingsDialog::_wait_for_key(const Ref<InputEvent> &p_event) {
|
|
|
|
Ref<InputEventKey> k = p_event;
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (k.is_valid() && k->is_pressed() && k->get_scancode() != 0) {
|
|
|
|
last_wait_for_key = k;
|
2019-11-04 14:22:30 +00:00
|
|
|
const String str = keycode_get_string(k->get_scancode_with_modifiers());
|
2016-06-05 00:31:29 +00:00
|
|
|
|
|
|
|
press_a_key_label->set_text(str);
|
|
|
|
press_a_key->accept_event();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_press_a_key_confirm() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (last_wait_for_key.is_null()) {
|
2016-06-05 00:31:29 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> ie;
|
|
|
|
ie.instance();
|
|
|
|
ie->set_scancode(last_wait_for_key->get_scancode());
|
|
|
|
ie->set_shift(last_wait_for_key->get_shift());
|
|
|
|
ie->set_control(last_wait_for_key->get_control());
|
|
|
|
ie->set_alt(last_wait_for_key->get_alt());
|
|
|
|
ie->set_metakey(last_wait_for_key->get_metakey());
|
2016-06-05 00:31:29 +00:00
|
|
|
|
|
|
|
Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(shortcut_configured);
|
|
|
|
|
2019-02-21 19:41:01 +00:00
|
|
|
undo_redo->create_action(TTR("Change Shortcut") + " '" + shortcut_configured + "'");
|
2017-10-15 11:36:36 +00:00
|
|
|
undo_redo->add_do_method(sc.ptr(), "set_shortcut", ie);
|
|
|
|
undo_redo->add_undo_method(sc.ptr(), "set_shortcut", sc->get_shortcut());
|
|
|
|
undo_redo->add_do_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_undo_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
2016-06-05 00:31:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 17:22:26 +00:00
|
|
|
void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
|
|
|
|
_focus_current_search_box();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_focus_current_search_box() {
|
|
|
|
Control *tab = tabs->get_current_tab_control();
|
2021-05-04 14:00:45 +00:00
|
|
|
LineEdit *current_search_box = nullptr;
|
2021-05-05 10:44:11 +00:00
|
|
|
if (tab == tab_general) {
|
2017-12-17 17:22:26 +00:00
|
|
|
current_search_box = search_box;
|
2021-05-05 10:44:11 +00:00
|
|
|
} else if (tab == tab_shortcuts) {
|
2017-12-17 17:22:26 +00:00
|
|
|
current_search_box = shortcut_search_box;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-12-17 17:22:26 +00:00
|
|
|
|
|
|
|
if (current_search_box) {
|
|
|
|
current_search_box->grab_focus();
|
|
|
|
current_search_box->select_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
void EditorSettingsDialog::_editor_restart() {
|
2019-01-25 20:23:56 +00:00
|
|
|
EditorNode::get_singleton()->save_all_scenes();
|
|
|
|
EditorNode::get_singleton()->restart_editor();
|
2018-07-19 21:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_editor_restart_request() {
|
|
|
|
restart_container->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_editor_restart_close() {
|
|
|
|
restart_container->hide();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void EditorSettingsDialog::_bind_methods() {
|
2017-10-15 11:36:36 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_unhandled_input"), &EditorSettingsDialog::_unhandled_input);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_settings_save"), &EditorSettingsDialog::_settings_save);
|
|
|
|
ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_settings_property_edited"), &EditorSettingsDialog::_settings_property_edited);
|
|
|
|
ClassDB::bind_method(D_METHOD("_shortcut_button_pressed"), &EditorSettingsDialog::_shortcut_button_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_filter_shortcuts"), &EditorSettingsDialog::_filter_shortcuts);
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
|
|
|
|
ClassDB::bind_method(D_METHOD("_press_a_key_confirm"), &EditorSettingsDialog::_press_a_key_confirm);
|
|
|
|
ClassDB::bind_method(D_METHOD("_wait_for_key"), &EditorSettingsDialog::_wait_for_key);
|
2017-12-17 17:22:26 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_tabs_tab_changed"), &EditorSettingsDialog::_tabs_tab_changed);
|
2018-07-19 21:58:15 +00:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_editor_restart_request"), &EditorSettingsDialog::_editor_restart_request);
|
|
|
|
ClassDB::bind_method(D_METHOD("_editor_restart"), &EditorSettingsDialog::_editor_restart);
|
|
|
|
ClassDB::bind_method(D_METHOD("_editor_restart_close"), &EditorSettingsDialog::_editor_restart_close);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorSettingsDialog::EditorSettingsDialog() {
|
2016-05-04 01:25:37 +00:00
|
|
|
set_title(TTR("Editor Settings"));
|
2017-03-02 21:43:56 +00:00
|
|
|
set_resizable(true);
|
2017-10-15 11:36:36 +00:00
|
|
|
undo_redo = memnew(UndoRedo);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tabs = memnew(TabContainer);
|
2017-05-02 20:13:12 +00:00
|
|
|
tabs->set_tab_align(TabContainer::ALIGN_LEFT);
|
2017-12-17 17:22:26 +00:00
|
|
|
tabs->connect("tab_changed", this, "_tabs_tab_changed");
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(tabs);
|
|
|
|
|
2017-12-17 17:22:26 +00:00
|
|
|
// General Tab
|
|
|
|
|
|
|
|
tab_general = memnew(VBoxContainer);
|
|
|
|
tabs->add_child(tab_general);
|
|
|
|
tab_general->set_name(TTR("General"));
|
2016-01-23 19:05:27 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2016-01-23 19:05:27 +00:00
|
|
|
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-12-17 17:22:26 +00:00
|
|
|
tab_general->add_child(hbc);
|
2016-01-23 19:05:27 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
search_box = memnew(LineEdit);
|
2020-08-28 21:39:19 +00:00
|
|
|
search_box->set_placeholder(TTR("Search"));
|
2016-01-23 19:05:27 +00:00
|
|
|
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
hbc->add_child(search_box);
|
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
inspector = memnew(SectionedInspector);
|
|
|
|
inspector->get_inspector()->set_use_filter(true);
|
|
|
|
inspector->register_search_box(search_box);
|
|
|
|
inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
inspector->get_inspector()->set_undo_redo(undo_redo);
|
|
|
|
tab_general->add_child(inspector);
|
|
|
|
inspector->get_inspector()->connect("property_edited", this, "_settings_property_edited");
|
|
|
|
inspector->get_inspector()->connect("restart_requested", this, "_editor_restart_request");
|
|
|
|
|
|
|
|
restart_container = memnew(PanelContainer);
|
|
|
|
tab_general->add_child(restart_container);
|
|
|
|
HBoxContainer *restart_hb = memnew(HBoxContainer);
|
|
|
|
restart_container->add_child(restart_hb);
|
|
|
|
restart_icon = memnew(TextureRect);
|
|
|
|
restart_icon->set_v_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
restart_hb->add_child(restart_icon);
|
|
|
|
restart_label = memnew(Label);
|
2019-03-25 00:54:29 +00:00
|
|
|
restart_label->set_text(TTR("The editor must be restarted for changes to take effect."));
|
2018-07-19 21:58:15 +00:00
|
|
|
restart_hb->add_child(restart_label);
|
|
|
|
restart_hb->add_spacer();
|
|
|
|
Button *restart_button = memnew(Button);
|
|
|
|
restart_button->connect("pressed", this, "_editor_restart");
|
|
|
|
restart_hb->add_child(restart_button);
|
|
|
|
restart_button->set_text(TTR("Save & Restart"));
|
|
|
|
restart_close_button = memnew(ToolButton);
|
|
|
|
restart_close_button->connect("pressed", this, "_editor_restart_close");
|
|
|
|
restart_hb->add_child(restart_close_button);
|
|
|
|
restart_container->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-17 17:22:26 +00:00
|
|
|
// Shortcuts Tab
|
|
|
|
|
|
|
|
tab_shortcuts = memnew(VBoxContainer);
|
|
|
|
tabs->add_child(tab_shortcuts);
|
|
|
|
tab_shortcuts->set_name(TTR("Shortcuts"));
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hbc = memnew(HBoxContainer);
|
2016-07-03 13:07:16 +00:00
|
|
|
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-12-17 17:22:26 +00:00
|
|
|
tab_shortcuts->add_child(hbc);
|
2016-07-03 13:07:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shortcut_search_box = memnew(LineEdit);
|
2020-08-28 21:39:19 +00:00
|
|
|
shortcut_search_box->set_placeholder(TTR("Search"));
|
2016-07-03 13:07:16 +00:00
|
|
|
shortcut_search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
hbc->add_child(shortcut_search_box);
|
|
|
|
shortcut_search_box->connect("text_changed", this, "_filter_shortcuts");
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shortcuts = memnew(Tree);
|
2017-12-17 17:22:26 +00:00
|
|
|
tab_shortcuts->add_child(shortcuts, true);
|
|
|
|
shortcuts->set_v_size_flags(SIZE_EXPAND_FILL);
|
2016-06-05 00:31:29 +00:00
|
|
|
shortcuts->set_columns(2);
|
|
|
|
shortcuts->set_hide_root(true);
|
|
|
|
shortcuts->set_column_titles_visible(true);
|
2017-12-02 09:58:58 +00:00
|
|
|
shortcuts->set_column_title(0, TTR("Name"));
|
|
|
|
shortcuts->set_column_title(1, TTR("Binding"));
|
2017-03-05 15:44:50 +00:00
|
|
|
shortcuts->connect("button_pressed", this, "_shortcut_button_pressed");
|
2016-06-05 00:31:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
press_a_key = memnew(ConfirmationDialog);
|
2016-06-05 00:31:29 +00:00
|
|
|
press_a_key->set_focus_mode(FOCUS_ALL);
|
|
|
|
add_child(press_a_key);
|
|
|
|
|
2017-12-17 17:22:26 +00:00
|
|
|
Label *l = memnew(Label);
|
2018-04-22 17:36:01 +00:00
|
|
|
l->set_text(TTR("Press a Key..."));
|
2017-09-21 22:12:33 +00:00
|
|
|
l->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
2016-06-05 00:31:29 +00:00
|
|
|
l->set_align(Label::ALIGN_CENTER);
|
2017-03-05 15:44:50 +00:00
|
|
|
l->set_margin(MARGIN_TOP, 20);
|
|
|
|
l->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_BEGIN, 30);
|
|
|
|
press_a_key_label = l;
|
2016-06-05 00:31:29 +00:00
|
|
|
press_a_key->add_child(l);
|
2017-03-05 15:44:50 +00:00
|
|
|
press_a_key->connect("gui_input", this, "_wait_for_key");
|
|
|
|
press_a_key->connect("confirmed", this, "_press_a_key_confirm");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
set_hide_on_ok(true);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
timer = memnew(Timer);
|
2018-07-03 17:33:06 +00:00
|
|
|
timer->set_wait_time(1.5);
|
2017-03-05 15:44:50 +00:00
|
|
|
timer->connect("timeout", this, "_settings_save");
|
2014-02-10 01:10:30 +00:00
|
|
|
timer->set_one_shot(true);
|
|
|
|
add_child(timer);
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorSettings::get_singleton()->connect("settings_changed", this, "_settings_changed");
|
2016-05-04 01:25:37 +00:00
|
|
|
get_ok()->set_text(TTR("Close"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-10-15 11:36:36 +00:00
|
|
|
|
|
|
|
EditorSettingsDialog::~EditorSettingsDialog() {
|
|
|
|
memdelete(undo_redo);
|
|
|
|
}
|