Skip to content

Commit

Permalink
Add right click popup to connections in conections to method dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 27, 2024
1 parent 0f95e9f commit abb0746
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 49 deletions.
16 changes: 12 additions & 4 deletions editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ void ConnectionsDock::_make_or_edit_connection() {
/*
* Creates single connection w/ undo-redo functionality.
*/
void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd, const bool &commit_action) {
Node *source = Object::cast_to<Node>(p_cd.source);
Node *target = Object::cast_to<Node>(p_cd.target);

Expand All @@ -1018,13 +1018,15 @@ void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");

undo_redo->commit_action();
if (commit_action) {
undo_redo->commit_action();
}
}

/*
* Break single connection w/ undo-redo functionality.
*/
void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd) {
void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd, const bool &commit_action) {
ERR_FAIL_COND(p_cd.source != selected_node); // Shouldn't happen but... Bugcheck.

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
Expand All @@ -1038,7 +1040,9 @@ void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd) {
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");

undo_redo->commit_action();
if (commit_action) {
undo_redo->commit_action();
}
}

/*
Expand Down Expand Up @@ -1589,6 +1593,8 @@ void ConnectionsDock::update_tree() {
connect_button->set_disabled(true);
}

ConnectionsDock *ConnectionsDock::singleton = nullptr;

ConnectionsDock::ConnectionsDock() {
set_name(TTR("Signals"));

Expand Down Expand Up @@ -1657,6 +1663,8 @@ ConnectionsDock::ConnectionsDock() {
tree->connect(SceneStringName(gui_input), callable_mp(this, &ConnectionsDock::_tree_gui_input));

add_theme_constant_override("separation", 3 * EDSCALE);

singleton = this;
}

ConnectionsDock::~ConnectionsDock() {
Expand Down
13 changes: 11 additions & 2 deletions editor/connections_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class ConnectionsDockTree : public Tree {
class ConnectionsDock : public VBoxContainer {
GDCLASS(ConnectionsDock, VBoxContainer);

static ConnectionsDock *singleton;

enum TreeItemType {
TREE_ITEM_TYPE_ROOT,
TREE_ITEM_TYPE_CLASS,
Expand Down Expand Up @@ -237,8 +239,8 @@ class ConnectionsDock : public VBoxContainer {
void _filter_changed(const String &p_text);

void _make_or_edit_connection();
void _connect(const ConnectDialog::ConnectionData &p_cd);
void _disconnect(const ConnectDialog::ConnectionData &p_cd);
void _connect(const ConnectDialog::ConnectionData &p_cd, const bool &commit_action = true);
void _disconnect(const ConnectDialog::ConnectionData &p_cd, const bool &commit_action = true);
void _disconnect_all();

void _tree_item_selected();
Expand All @@ -265,6 +267,13 @@ class ConnectionsDock : public VBoxContainer {
static void _bind_methods();

public:
static ConnectionsDock *get_singleton() { return singleton; }
void connect_connection(const ConnectDialog::ConnectionData &p_cd, const bool &commit_action = true) {
_connect(p_cd, commit_action);
}
void disconnect_connection(const ConnectDialog::ConnectionData &p_cd, const bool &commit_action = true) {
_disconnect(p_cd, commit_action);
}
void set_node(Node *p_node);
void update_tree();

Expand Down
Loading

0 comments on commit abb0746

Please sign in to comment.