1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-15 13:51:40 +00:00

Merge pull request #99897 from aaronfranke/editor-top-nodes

Clarify API for top selected nodes in EditorSelection and make public
This commit is contained in:
Rémi Verschelde
2025-03-28 17:29:51 +01:00
12 changed files with 119 additions and 102 deletions

View File

@@ -560,7 +560,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (!profile_allow_editing) {
break;
}
if (editor_selection->get_selected_node_list().size() > 1) {
if (editor_selection->get_top_selected_node_list().size() > 1) {
if (!_validate_no_foreign()) {
break;
}
@@ -658,7 +658,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.size() == 0) {
break;
}
@@ -738,8 +738,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
Node *selected = scene_tree->get_selected();
if (!selected && !editor_selection->get_selected_node_list().is_empty()) {
selected = editor_selection->get_selected_node_list().front()->get();
const List<Node *> &top_node_list = editor_selection->get_top_selected_node_list();
if (!selected && !top_node_list.is_empty()) {
selected = top_node_list.front()->get();
}
if (selected) {
@@ -815,7 +816,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
bool MOVING_UP = !MOVING_DOWN;
Node *common_parent = scene_tree->get_selected()->get_parent();
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
selection.sort_custom<Node::Comparator>(); // sort by index
if (MOVING_DOWN) {
selection.reverse();
@@ -885,7 +886,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.size() == 0) {
break;
}
@@ -980,7 +981,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> nodes = editor_selection->get_selected_node_list();
List<Node *> nodes = editor_selection->get_top_selected_node_list();
HashSet<Node *> nodeset;
for (Node *E : nodes) {
nodeset.insert(E);
@@ -993,7 +994,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> nodes = editor_selection->get_selected_node_list();
List<Node *> nodes = editor_selection->get_top_selected_node_list();
ERR_FAIL_COND(nodes.size() != 1);
Node *node = nodes.front()->get();
@@ -1076,7 +1077,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> remove_list = editor_selection->get_selected_node_list();
List<Node *> remove_list = editor_selection->get_top_selected_node_list();
if (remove_list.is_empty()) {
return;
@@ -1146,7 +1147,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.size() != 1) {
accept->set_text(vformat(TTR("Saving the branch as a scene requires selecting only one node, but you have selected %d nodes."), selection.size()));
@@ -1202,7 +1203,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
new_scene_from_dialog->popup_file_dialog();
} break;
case TOOL_COPY_NODE_PATH: {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
Node *node = e->get();
@@ -1214,7 +1215,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SHOW_IN_FILE_SYSTEM: {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
const Node *node = e->get();
@@ -1224,7 +1225,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_OPEN_DOCUMENTATION: {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
for (const Node *node : selection) {
String class_name;
Ref<Script> script_base = node->get_script();
@@ -1253,7 +1254,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.size() != 1) {
break;
}
@@ -1288,7 +1289,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
Node *node = e->get();
@@ -1323,7 +1324,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
Node *node = e->get();
@@ -1348,7 +1349,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SCENE_OPEN: {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
Node *node = e->get();
@@ -1369,7 +1370,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
Node *node = e->get();
@@ -1381,7 +1382,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_SCENE_OPEN_INHERITED: {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
Node *node = e->get();
@@ -1392,14 +1393,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_TOGGLE_SCENE_UNIQUE_NAME: {
// Enabling/disabling based on the same node based on which the checkbox in the menu is checked/unchecked.
const List<Node *>::Element *first_selected = editor_selection->get_selected_node_list().front();
const List<Node *>::Element *first_selected = editor_selection->get_top_selected_node_list().front();
if (first_selected == nullptr) {
return;
}
if (first_selected->get() == EditorNode::get_singleton()->get_edited_scene()) {
// Exclude Root Node. It should never be unique name in its own scene!
editor_selection->remove_node(first_selected->get());
first_selected = editor_selection->get_selected_node_list().front();
first_selected = editor_selection->get_top_selected_node_list().front();
if (first_selected == nullptr) {
return;
}
@@ -2268,7 +2269,7 @@ void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) {
}
bool SceneTreeDock::_validate_no_foreign() {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
for (Node *E : selection) {
if (E != edited_scene && E->get_owner() != edited_scene) {
@@ -2297,7 +2298,7 @@ bool SceneTreeDock::_validate_no_foreign() {
}
bool SceneTreeDock::_validate_no_instance() {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
for (Node *E : selection) {
if (E != edited_scene && !E->get_scene_file_path().is_empty()) {
@@ -2314,7 +2315,7 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
Node *new_parent = scene_root->get_node(p_path);
ERR_FAIL_NULL(new_parent);
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.is_empty()) {
return; // Nothing to reparent.
@@ -2536,7 +2537,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
}
void SceneTreeDock::_script_created(Ref<Script> p_script) {
List<Node *> selected = editor_selection->get_selected_node_list();
List<Node *> selected = editor_selection->get_top_selected_node_list();
if (selected.is_empty()) {
return;
@@ -2597,7 +2598,7 @@ void SceneTreeDock::_shader_creation_closed() {
}
void SceneTreeDock::_toggle_editable_children_from_selection() {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -2606,7 +2607,7 @@ void SceneTreeDock::_toggle_editable_children_from_selection() {
}
void SceneTreeDock::_toggle_placeholder_from_selection() {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
@@ -2741,7 +2742,7 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) {
}
void SceneTreeDock::_delete_confirm(bool p_cut) {
List<Node *> remove_list = editor_selection->get_selected_node_list();
List<Node *> remove_list = editor_selection->get_top_selected_node_list();
if (remove_list.is_empty()) {
return;
@@ -2976,7 +2977,7 @@ void SceneTreeDock::_create() {
_do_create(parent);
} else if (current_option == TOOL_REPLACE) {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
ERR_FAIL_COND(selection.is_empty());
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
@@ -2995,7 +2996,7 @@ void SceneTreeDock::_create() {
ur->commit_action(false);
} else if (current_option == TOOL_REPARENT_TO_NEW_NODE) {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
ERR_FAIL_COND(selection.is_empty());
// Find top level node in selection
@@ -3344,7 +3345,7 @@ void SceneTreeDock::set_selected(Node *p_node, bool p_emit_selected) {
}
void SceneTreeDock::_new_scene_from(const String &p_file) {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.size() != 1) {
accept->set_text(TTR("This operation requires a single selected node."));
@@ -3522,7 +3523,7 @@ void SceneTreeDock::_normalize_drop(Node *&to_node, int &to_pos, int p_type) {
}
Array SceneTreeDock::_get_selection_array() {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
TypedArray<Node> array;
array.resize(selection.size());
@@ -3671,7 +3672,7 @@ void SceneTreeDock::_nodes_dragged(const Array &p_nodes, NodePath p_to, int p_ty
return;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.is_empty()) {
return; //nothing to reparent
@@ -3744,7 +3745,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
return;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
List<Node *> full_selection = editor_selection->get_full_selected_node_list(); // Above method only returns nodes with common parent.
if (selection.size() == 0) {
@@ -4084,7 +4085,7 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) {
return;
}
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.is_empty()) {
return;
}
@@ -4214,7 +4215,7 @@ List<Node *> SceneTreeDock::paste_nodes(bool p_paste_as_sibling) {
Node *paste_parent = edited_scene;
Node *paste_sibling = nullptr;
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> selection = editor_selection->get_top_selected_node_list();
if (selection.size() > 0) {
paste_parent = selection.back()->get();
}