Merge pull request #30384 from Anutrix/a-filter-feature

Added filter to SceneTreeDialog
This commit is contained in:
Rémi Verschelde 2019-07-08 13:40:15 +02:00 committed by GitHub
commit c7734e2cbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -1164,6 +1164,8 @@ void SceneTreeDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
connect("confirmed", this, "_select");
filter->set_right_icon(get_icon("Search", "EditorIcons"));
filter->set_clear_button_enabled(true);
} break;
case NOTIFICATION_EXIT_TREE: {
disconnect("confirmed", this, "_select");
@ -1187,20 +1189,37 @@ void SceneTreeDialog::_select() {
}
}
void SceneTreeDialog::_filter_changed(const String &p_filter) {
tree->set_filter(p_filter);
}
void SceneTreeDialog::_bind_methods() {
ClassDB::bind_method("_select", &SceneTreeDialog::_select);
ClassDB::bind_method("_cancel", &SceneTreeDialog::_cancel);
ClassDB::bind_method(D_METHOD("_filter_changed"), &SceneTreeDialog::_filter_changed);
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::NODE_PATH, "path")));
}
SceneTreeDialog::SceneTreeDialog() {
set_title(TTR("Select a Node"));
VBoxContainer *vbc = memnew(VBoxContainer);
add_child(vbc);
filter = memnew(LineEdit);
filter->set_h_size_flags(SIZE_EXPAND_FILL);
filter->set_placeholder(TTR("Filter nodes"));
filter->add_constant_override("minimum_spaces", 0);
filter->connect("text_changed", this, "_filter_changed");
vbc->add_child(filter);
tree = memnew(SceneTreeEditor(false, false, true));
add_child(tree);
tree->set_v_size_flags(SIZE_EXPAND_FILL);
tree->get_scene_tree()->connect("item_activated", this, "_select");
vbc->add_child(tree);
}
SceneTreeDialog::~SceneTreeDialog() {

View File

@ -171,10 +171,12 @@ class SceneTreeDialog : public ConfirmationDialog {
SceneTreeEditor *tree;
//Button *select;
//Button *cancel;
LineEdit *filter;
void update_tree();
void _select();
void _cancel();
void _filter_changed(const String &p_filter);
protected:
void _notification(int p_what);