Merge pull request #39982 from hinlopen/create-dialog-preferred

Add Control to preferred types in Create Dialog
This commit is contained in:
Rémi Verschelde 2020-06-30 12:50:36 +02:00 committed by GitHub
commit dffb8824db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 7 deletions

View File

@ -350,17 +350,22 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (!profile_allow_editing) {
break;
}
String preferred = "";
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
// Prefer nodes that inherit from the current scene root.
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
if (current_edited_scene_root) {
if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D")) {
preferred = "Node2D";
} else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D")) {
preferred = "Node3D";
static const String preferred_types[] = { "Node2D", "Node3D", "Control" };
StringName root_class = current_edited_scene_root->get_class_name();
for (int i = 0; i < preferred_types->size(); i++) {
if (ClassDB::is_parent_class(root_class, preferred_types[i])) {
create_dialog->set_preferred_search_result_type(preferred_types[i]);
break;
}
}
}
create_dialog->set_preferred_search_result_type(preferred);
create_dialog->popup_create(true);
} break;
case TOOL_INSTANCE: {