Merge pull request #82821 from Madalaski/connections_delete_key

Allow to remove signal connections using `Delete`
This commit is contained in:
Yuri Sizov 2024-01-17 18:52:22 +01:00
commit a0fec566ef
2 changed files with 19 additions and 4 deletions

View file

@ -1202,7 +1202,22 @@ void ConnectionsDock::_slot_menu_about_to_popup() {
slot_menu->set_item_disabled(slot_menu->get_item_index(SLOT_MENU_DISCONNECT), connection_is_inherited);
}
void ConnectionsDock::_rmb_pressed(const Ref<InputEvent> &p_event) {
void ConnectionsDock::_tree_gui_input(const Ref<InputEvent> &p_event) {
// Handle Delete press.
if (ED_IS_SHORTCUT("connections_editor/disconnect", p_event)) {
TreeItem *item = tree->get_selected();
if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
Connection connection = item->get_metadata(0);
_disconnect(connection);
update_tree();
// Stop the Delete input from propagating elsewhere.
accept_event();
return;
}
}
// Handle RMB press.
const Ref<InputEventMouseButton> &mb_event = p_event;
if (mb_event.is_null() || !mb_event->is_pressed() || mb_event->get_button_index() != MouseButton::RIGHT) {
return;
@ -1536,13 +1551,13 @@ ConnectionsDock::ConnectionsDock() {
slot_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_slot_menu_about_to_popup));
slot_menu->add_item(TTR("Edit..."), SLOT_MENU_EDIT);
slot_menu->add_item(TTR("Go to Method"), SLOT_MENU_GO_TO_METHOD);
slot_menu->add_item(TTR("Disconnect"), SLOT_MENU_DISCONNECT);
slot_menu->add_shortcut(ED_SHORTCUT("connections_editor/disconnect", TTR("Disconnect"), Key::KEY_DELETE), SLOT_MENU_DISCONNECT);
add_child(slot_menu);
connect_dialog->connect("connected", callable_mp(this, &ConnectionsDock::_make_or_edit_connection));
tree->connect("item_selected", callable_mp(this, &ConnectionsDock::_tree_item_selected));
tree->connect("item_activated", callable_mp(this, &ConnectionsDock::_tree_item_activated));
tree->connect("gui_input", callable_mp(this, &ConnectionsDock::_rmb_pressed));
tree->connect("gui_input", callable_mp(this, &ConnectionsDock::_tree_gui_input));
add_theme_constant_override("separation", 3 * EDSCALE);
}

View file

@ -252,7 +252,7 @@ class ConnectionsDock : public VBoxContainer {
void _signal_menu_about_to_popup();
void _handle_slot_menu_option(int p_option);
void _slot_menu_about_to_popup();
void _rmb_pressed(const Ref<InputEvent> &p_event);
void _tree_gui_input(const Ref<InputEvent> &p_event);
void _close();
protected: