From 8c8c552befac38d88af54adf1042395e95f5aa76 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Fri, 16 Aug 2024 02:23:56 -0400 Subject: [PATCH] GH-714 Support `ui_cut` action in `GraphEdit` controls --- src/editor/graph/graph_edit.cpp | 29 ++++++++++++++++++++++++++++- src/editor/graph/graph_edit.h | 4 ++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/editor/graph/graph_edit.cpp b/src/editor/graph/graph_edit.cpp index a4140e95..09d852c7 100644 --- a/src/editor/graph/graph_edit.cpp +++ b/src/editor/graph/graph_edit.cpp @@ -684,6 +684,14 @@ void OrchestratorGraphEdit::_gui_input(const Ref& p_event) const Ref key = p_event; if (key.is_valid() && key->is_pressed()) { + // todo: Submitted https://github.com/godotengine/godot/pull/95614 + // Can eventually rely on the "cut_nodes_request" signal rather than this approach + if (key->is_action("ui_cut", true)) + { + _on_cut_nodes_request(); + accept_event(); + } + if (key->is_action("ui_left", true)) { _move_selected(Vector2(is_snapping_enabled() ? -get_snapping_distance() : -1, 0)); @@ -1798,7 +1806,7 @@ void OrchestratorGraphEdit::_on_delete_nodes_requested(const PackedStringArray& return; OrchestratorSettings* settings = OrchestratorSettings::get_singleton(); - if (settings->get_setting("ui/graph/confirm_on_delete", true)) + if (!_disable_delete_confirmation && settings->get_setting("ui/graph/confirm_on_delete", true)) { const String message = vformat("Do you wish to delete %d node(s)?", p_node_names.size()); _confirm_yes_no(message, "Confirm deletion", callable_mp(this, &OrchestratorGraphEdit::_delete_nodes).bind(p_node_names)); @@ -2030,6 +2038,25 @@ void OrchestratorGraphEdit::_on_copy_nodes_request() _clipboard->connections.insert(E); } +void OrchestratorGraphEdit::_on_cut_nodes_request() +{ + _clipboard->reset(); + + _on_copy_nodes_request(); + + PackedStringArray selected_names; + for (int index = 0; index < get_child_count(); index++) + { + GraphElement* element = Object::cast_to(get_child(index)); + if (element && element->is_selected()) + selected_names.push_back(element->get_name()); + } + + _disable_delete_confirmation = true; + _on_delete_nodes_requested(selected_names); + _disable_delete_confirmation = false; +} + void OrchestratorGraphEdit::_on_duplicate_nodes_request() { Vector duplications; diff --git a/src/editor/graph/graph_edit.h b/src/editor/graph/graph_edit.h index 71ff34a6..9a323892 100644 --- a/src/editor/graph/graph_edit.h +++ b/src/editor/graph/graph_edit.h @@ -135,6 +135,7 @@ class OrchestratorGraphEdit : public GraphEdit GDExtensionGodotVersion _version; //! Godot version bool _is_43p{ false }; //! Is Godot 4.3+ bool _box_selection{ false }; //! Is graph doing box selection? + bool _disable_delete_confirmation{ false }; //! Allows temporarily disabling delete confirmation Vector2 _box_selection_from; //! Mouse position box selection started from OrchestratorScriptAutowireSelections* _autowire{ nullptr }; @@ -487,6 +488,9 @@ class OrchestratorGraphEdit : public GraphEdit /// Dispatched when the user presses {@code Ctrl+C} to copy selected nodes to the clipboard. void _on_copy_nodes_request(); + /// Dispatched when the user pressed {@code Ctrl+X} to cut selected nodes to the clipboard. + void _on_cut_nodes_request(); + /// Dispatched when the user wants to duplicate a graph node. void _on_duplicate_nodes_request();