diff --git a/doc/classes/GraphEdit.xml b/doc/classes/GraphEdit.xml index 93ab17d7f79..a79b79b5fd5 100644 --- a/doc/classes/GraphEdit.xml +++ b/doc/classes/GraphEdit.xml @@ -212,8 +212,9 @@ + - Emitted when a GraphNode is attempted to be removed from the GraphEdit. + Emitted when a GraphNode is attempted to be removed from the GraphEdit. Provides a list of node names to be removed (all selected nodes, excluding nodes without closing button). diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index a0ed93588cb..60021466da7 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -1950,17 +1950,23 @@ void VisualShaderEditor::_paste_nodes() { _dup_update_excluded(type, copy_nodes_excluded_buffer); // to prevent selection of previous copies at new paste } -void VisualShaderEditor::_on_nodes_delete() { +void VisualShaderEditor::_on_nodes_delete(const Array &p_nodes) { VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); List to_erase; - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - if (gn->is_selected() && gn->is_close_button_visible()) { - to_erase.push_back(gn->get_name().operator String().to_int()); + if (p_nodes.empty()) { + for (int i = 0; i < graph->get_child_count(); i++) { + GraphNode *gn = Object::cast_to(graph->get_child(i)); + if (gn) { + if (gn->is_selected() && gn->is_close_button_visible()) { + to_erase.push_back(gn->get_name().operator String().to_int()); + } } } + } else { + for (int i = 0; i < p_nodes.size(); i++) { + to_erase.push_back(p_nodes[i].operator String().to_int()); + } } if (to_erase.empty()) { diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 18a908d9d69..e4dfba98e02 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -183,7 +183,7 @@ class VisualShaderEditor : public VBoxContainer { void _node_selected(Object *p_node); void _delete_request(int); - void _on_nodes_delete(); + void _on_nodes_delete(const Array &p_nodes); void _node_changed(int p_id); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 578a220b043..02d59ea82ae 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1831,18 +1831,24 @@ void VisualScriptEditor::_on_nodes_paste() { } } -void VisualScriptEditor::_on_nodes_delete() { +void VisualScriptEditor::_on_nodes_delete(const Array &p_nodes) { // delete all the selected nodes List to_erase; - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - if (gn->is_selected() && gn->is_close_button_visible()) { - to_erase.push_back(gn->get_name().operator String().to_int()); + if (p_nodes.empty()) { + for (int i = 0; i < graph->get_child_count(); i++) { + GraphNode *gn = Object::cast_to(graph->get_child(i)); + if (gn) { + if (gn->is_selected() && gn->is_close_button_visible()) { + to_erase.push_back(gn->get_name().operator String().to_int()); + } } } + } else { + for (int i = 0; i < graph->get_child_count(); i++) { + to_erase.push_back(p_nodes[i].operator String().to_int()); + } } if (to_erase.empty()) { @@ -4253,7 +4259,7 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_ void VisualScriptEditor::_menu_option(int p_what) { switch (p_what) { case EDIT_DELETE_NODES: { - _on_nodes_delete(); + _on_nodes_delete(Array()); } break; case EDIT_TOGGLE_BREAKPOINT: { List reselect; @@ -4288,7 +4294,7 @@ void VisualScriptEditor::_menu_option(int p_what) { } break; case EDIT_CUT_NODES: { _on_nodes_copy(); - _on_nodes_delete(); + _on_nodes_delete(Array()); } break; case EDIT_PASTE_NODES: { _on_nodes_paste(); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 618aed8d38e..5ed88163c8f 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -257,7 +257,7 @@ class VisualScriptEditor : public ScriptEditorBase { void _on_nodes_copy(); void _on_nodes_paste(); - void _on_nodes_delete(); + void _on_nodes_delete(const Array &p_nodes); void _on_nodes_duplicate(); Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index ab2fe66adfc..9a5b62412cf 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1370,7 +1370,18 @@ void GraphEdit::_gui_input(const Ref &p_ev) { } if (k->get_scancode() == KEY_DELETE && k->is_pressed()) { - emit_signal("delete_nodes_request"); + Array nodes; + + for (int i = 0; i < get_child_count(); i++) { + GraphNode *gn = Object::cast_to(get_child(i)); + if (gn) { + if (gn->is_selected() && gn->is_close_button_visible()) { + nodes.push_back(gn->get_name()); + } + } + } + + emit_signal("delete_nodes_request", nodes); accept_event(); } } @@ -1746,7 +1757,7 @@ void GraphEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("node_unselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); - ADD_SIGNAL(MethodInfo("delete_nodes_request")); + ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes"))); ADD_SIGNAL(MethodInfo("_begin_node_move")); ADD_SIGNAL(MethodInfo("_end_node_move")); ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "ofs")));