Skip to content

Commit

Permalink
CraterCrashGH-714 Support ui_cut action in GraphEdit controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Aug 18, 2024
1 parent 1953283 commit 1b17350
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,14 @@ void OrchestratorGraphEdit::_gui_input(const Ref<InputEvent>& p_event)
const Ref<InputEventKey> 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));
Expand Down Expand Up @@ -1794,7 +1802,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));
Expand Down Expand Up @@ -2026,6 +2034,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<GraphElement>(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<int> duplications;
Expand Down
4 changes: 4 additions & 0 deletions src/editor/graph/graph_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 1b17350

Please sign in to comment.