Added search box to signals dock.

Also made localised code changes for better documentation and readability.

(cherry picked from commit 8c4c2bceab)
This commit is contained in:
Eric M 2020-08-08 14:15:46 +10:00 committed by Rémi Verschelde
parent b79bcb1f33
commit 8bdfba790b
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 42 additions and 17 deletions

View file

@ -515,6 +515,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.
@ -871,6 +875,7 @@ void ConnectionsDock::_bind_methods() {
ClassDB::bind_method("_rmb_pressed", &ConnectionsDock::_rmb_pressed);
ClassDB::bind_method("_close", &ConnectionsDock::_close);
ClassDB::bind_method("_connect_pressed", &ConnectionsDock::_connect_pressed);
ClassDB::bind_method("_filter_changed", &ConnectionsDock::_filter_changed);
ClassDB::bind_method("update_tree", &ConnectionsDock::update_tree);
}
@ -903,7 +908,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);
@ -929,15 +934,16 @@ void ConnectionsDock::update_tree() {
icon = get_icon("Object", "EditorIcons");
}
TreeItem *pitem = NULL;
TreeItem *section_item = NULL;
// 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_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_color("prop_subsection", "Editor"));
node_signals2.sort();
}
@ -948,6 +954,12 @@ void ConnectionsDock::update_tree() {
StringName signal_name = mi.name;
String signaldesc = "(";
PoolStringArray 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++) {
@ -967,13 +979,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_icon("Signal", "EditorIcons"));
signal_item->set_metadata(0, sinfo);
signal_item->set_icon(0, get_icon("Signal", "EditorIcons"));
// Set tooltip with the signal's documentation.
{
@ -1009,7 +1022,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
@ -1043,10 +1056,11 @@ void ConnectionsDock::update_tree() {
path += ")";
}
TreeItem *item2 = tree->create_item(item);
item2->set_text(0, path);
item2->set_metadata(0, c);
item2->set_icon(0, get_icon("Slot", "EditorIcons"));
TreeItem *connection_item = tree->create_item(signal_item);
connection_item->set_text(0, path);
Connection cd = c;
connection_item->set_metadata(0, cd);
connection_item->set_icon(0, get_icon("Slot", "EditorIcons"));
}
}
@ -1068,6 +1082,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_icon("Search", "EditorIcons"));
search_box->set_clear_button_enabled(true);
search_box->connect("text_changed", this, "_filter_changed");
vbc->add_child(search_box);
tree = memnew(ConnectionsDockTree);
tree->set_columns(1);
tree->set_select_mode(Tree::SELECT_ROW);

View file

@ -140,9 +140,12 @@ class ConnectionsDock : public VBoxContainer {
PopupMenu *signal_menu;
PopupMenu *slot_menu;
UndoRedo *undo_redo;
LineEdit *search_box;
Map<StringName, Map<StringName, String> > descr_cache;
void _filter_changed(const String &p_text);
void _make_or_edit_connection();
void _connect(Connection cToMake);
void _disconnect(TreeItem &item);