diff options
Diffstat (limited to 'editor/connections_dialog.cpp')
-rw-r--r-- | editor/connections_dialog.cpp | 87 |
1 files changed, 53 insertions, 34 deletions
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index facd57418d..0c1fb6fe4d 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,7 +30,8 @@ #include "connections_dialog.h" -#include "core/print_string.h" +#include "core/string/print_string.h" +#include "editor/doc_tools.h" #include "editor_node.h" #include "editor_scale.h" #include "editor_settings.h" @@ -97,7 +98,7 @@ public: } void notify_changed() { - _change_notify(); + notify_property_list_changed(); } ConnectDialogBinds() { @@ -251,16 +252,16 @@ void ConnectDialog::_update_ok_enabled() { Node *target = tree->get_selected(); if (target == nullptr) { - get_ok()->set_disabled(true); + get_ok_button()->set_disabled(true); return; } if (!advanced->is_pressed() && target->get_script().is_null()) { - get_ok()->set_disabled(true); + get_ok_button()->set_disabled(true); return; } - get_ok()->set_disabled(false); + get_ok_button()->set_disabled(false); } void ConnectDialog::_notification(int p_what) { @@ -410,6 +411,7 @@ ConnectDialog::ConnectDialog() { tree = memnew(SceneTreeEditor(false)); tree->set_connecting_signal(true); + tree->set_show_enabled_subscene(true); tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ConnectDialog::_item_activated)); tree->connect("node_selected", callable_mp(this, &ConnectDialog::_tree_node_selected)); tree->set_connect_to_script_mode(true); @@ -477,11 +479,6 @@ ConnectDialog::ConnectDialog() { advanced->set_text(TTR("Advanced")); advanced->connect("pressed", callable_mp(this, &ConnectDialog::_advanced_pressed)); - // Add spacing so the tree and inspector are the same size. - Control *spacing = memnew(Control); - spacing->set_custom_minimum_size(Size2(0, 4) * EDSCALE); - vbc_right->add_child(spacing); - deferred = memnew(CheckBox); deferred->set_h_size_flags(0); deferred->set_text(TTR("Deferred")); @@ -499,8 +496,8 @@ ConnectDialog::ConnectDialog() { error = memnew(AcceptDialog); add_child(error); error->set_title(TTR("Cannot connect signal")); - error->get_ok()->set_text(TTR("Close")); - get_ok()->set_text(TTR("Connect")); + error->get_ok_button()->set_text(TTR("Close")); + get_ok_button()->set_text(TTR("Connect")); } ConnectDialog::~ConnectDialog() { @@ -528,6 +525,10 @@ struct _ConnectionsDockMethodInfoSort { } }; +void ConnectionsDock::_filter_changed(const String &p_text) { + update_tree(); +} + /* * Post-ConnectDialog callback for creating/editing connections. * Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed. @@ -715,7 +716,7 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) { const String &signalname = signal; String midname = selectedNode->get_name(); for (int i = 0; i < midname.length(); i++) { //TODO: Regex filter may be cleaner. - CharType c = midname[i]; + char32_t c = midname[i]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) { if (c == ' ') { // Replace spaces with underlines. @@ -755,8 +756,9 @@ void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData cToE Node *dst = static_cast<Node *>(cToEdit.target); if (src && dst) { + const String &signalname = cToEdit.signal; connect_dialog->set_title(TTR("Edit Connection:") + cToEdit.signal); - connect_dialog->popup_centered(); + connect_dialog->popup_dialog(signalname); connect_dialog->init(cToEdit, true); } } @@ -903,6 +905,7 @@ void ConnectionsDock::update_tree() { String name; if (!did_script) { + // Get script signals (including signals from any base scripts). Ref<Script> scr = selectedNode->get_script(); if (scr.is_valid()) { scr->get_script_signal_list(&node_signals2); @@ -928,15 +931,16 @@ void ConnectionsDock::update_tree() { icon = get_theme_icon("Object", "EditorIcons"); } - TreeItem *pitem = nullptr; + TreeItem *section_item = nullptr; + // Create subsections. if (node_signals2.size()) { - pitem = tree->create_item(root); - pitem->set_text(0, name); - pitem->set_icon(0, icon); - pitem->set_selectable(0, false); - pitem->set_editable(0, false); - pitem->set_custom_bg_color(0, get_theme_color("prop_subsection", "Editor")); + section_item = tree->create_item(root); + section_item->set_text(0, name); + section_item->set_icon(0, icon); + section_item->set_selectable(0, false); + section_item->set_editable(0, false); + section_item->set_custom_bg_color(0, get_theme_color("prop_subsection", "Editor")); node_signals2.sort(); } @@ -946,6 +950,12 @@ void ConnectionsDock::update_tree() { StringName signal_name = mi.name; String signaldesc = "("; PackedStringArray argnames; + + String filter_text = search_box->get_text(); + if (!filter_text.is_subsequence_ofi(signal_name)) { + continue; + } + if (mi.arguments.size()) { for (int i = 0; i < mi.arguments.size(); i++) { PropertyInfo &pi = mi.arguments[i]; @@ -965,13 +975,14 @@ void ConnectionsDock::update_tree() { } signaldesc += ")"; - TreeItem *item = tree->create_item(pitem); - item->set_text(0, String(signal_name) + signaldesc); + // Create the children of the subsection - the actual list of signals. + TreeItem *signal_item = tree->create_item(section_item); + signal_item->set_text(0, String(signal_name) + signaldesc); Dictionary sinfo; sinfo["name"] = signal_name; sinfo["args"] = argnames; - item->set_metadata(0, sinfo); - item->set_icon(0, get_theme_icon("Signal", "EditorIcons")); + signal_item->set_metadata(0, sinfo); + signal_item->set_icon(0, get_theme_icon("Signal", "EditorIcons")); // Set tooltip with the signal's documentation. { @@ -988,7 +999,7 @@ void ConnectionsDock::update_tree() { } if (!found) { - DocData *dd = EditorHelp::get_doc_data(); + DocTools *dd = EditorHelp::get_doc_data(); Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(base); while (F && descr == String()) { for (int i = 0; i < F->get().signals.size(); i++) { @@ -997,7 +1008,7 @@ void ConnectionsDock::update_tree() { break; } } - if (!F->get().inherits.empty()) { + if (!F->get().inherits.is_empty()) { F = dd->class_list.find(F->get().inherits); } else { break; @@ -1007,7 +1018,7 @@ void ConnectionsDock::update_tree() { } // "::" separators used in make_custom_tooltip for formatting. - item->set_tooltip(0, String(signal_name) + "::" + signaldesc + "::" + descr); + signal_item->set_tooltip(0, String(signal_name) + "::" + signaldesc + "::" + descr); } // List existing connections @@ -1044,11 +1055,11 @@ void ConnectionsDock::update_tree() { path += ")"; } - TreeItem *item2 = tree->create_item(item); - item2->set_text(0, path); + TreeItem *connection_item = tree->create_item(signal_item); + connection_item->set_text(0, path); Connection cd = c; - item2->set_metadata(0, cd); - item2->set_icon(0, get_theme_icon("Slot", "EditorIcons")); + connection_item->set_metadata(0, cd); + connection_item->set_icon(0, get_theme_icon("Slot", "EditorIcons")); } } @@ -1069,6 +1080,14 @@ ConnectionsDock::ConnectionsDock(EditorNode *p_editor) { VBoxContainer *vbc = this; + search_box = memnew(LineEdit); + search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); + search_box->set_placeholder(TTR("Filter signals")); + search_box->set_right_icon(get_theme_icon("Search", "EditorIcons")); + search_box->set_clear_button_enabled(true); + search_box->connect("text_changed", callable_mp(this, &ConnectionsDock::_filter_changed)); + vbc->add_child(search_box); + tree = memnew(ConnectionsDockTree); tree->set_columns(1); tree->set_select_mode(Tree::SELECT_ROW); |