summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Hinlopen <f.a.hinlopen@gmail.com>2020-06-29 18:23:49 +0200
committerStijn Hinlopen <f.a.hinlopen@gmail.com>2020-06-30 12:00:55 +0200
commitec86d3268429eebbf512779bd03df9cd754cea99 (patch)
treeed058b75c6190e0b38d3d3a35617361bb7447f49
parent4599381fad10a20ffd2d4eadf7e9de99ef15ac80 (diff)
Add Control to preferred types
-rw-r--r--editor/scene_tree_dock.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index dd42ed9760..04ac809d03 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -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: {