@@ -199,7 +199,11 @@ void ConnectDialog::_tree_node_selected() {
199199 return ;
200200 }
201201
202- dst_path = source->get_path_to (current);
202+ Node *source_node = Object::cast_to<Node>(source);
203+ if (source_node) {
204+ dst_path = source_node->get_path_to (current);
205+ }
206+
203207 if (!edit_mode) {
204208 set_dst_method (generate_method_callback_name (source, signal, current));
205209 }
@@ -212,7 +216,7 @@ void ConnectDialog::_tree_node_selected() {
212216}
213217
214218void ConnectDialog::_focus_currently_connected () {
215- tree->set_selected (source);
219+ tree->set_selected (Object::cast_to<Node>( source) );
216220}
217221
218222void ConnectDialog::_unbind_count_changed (double p_count) {
@@ -267,8 +271,9 @@ void ConnectDialog::_remove_bind() {
267271/*
268272 * Automatically generates a name for the callback method.
269273 */
270- StringName ConnectDialog::generate_method_callback_name (Node *p_source, const String &p_signal_name, Node *p_target) {
271- String node_name = p_source->get_name ();
274+ StringName ConnectDialog::generate_method_callback_name (Object *p_source, const String &p_signal_name, Object *p_target) {
275+ String node_name = p_source->call (" get_name" );
276+
272277 for (int i = 0 ; i < node_name.length (); i++) { // TODO: Regex filter may be cleaner.
273278 char32_t c = node_name[i];
274279 if ((i == 0 && !is_unicode_identifier_start (c)) || (i > 0 && !is_unicode_identifier_continue (c))) {
@@ -492,7 +497,8 @@ void ConnectDialog::_update_ok_enabled() {
492497}
493498
494499void ConnectDialog::_update_warning_label () {
495- Node *dst = source->get_node (dst_path);
500+ Node *dst = Object::cast_to<Node>(source)->get_node (dst_path);
501+
496502 if (dst == nullptr ) {
497503 warning_label->set_visible (false );
498504 return ;
@@ -537,7 +543,7 @@ void ConnectDialog::_bind_methods() {
537543 ADD_SIGNAL (MethodInfo (" connected" ));
538544}
539545
540- Node *ConnectDialog::get_source () const {
546+ Object *ConnectDialog::get_source () const {
541547 return source;
542548}
543549
@@ -693,15 +699,15 @@ void ConnectDialog::shortcut_input(const Ref<InputEvent> &p_event) {
693699void ConnectDialog::init (const ConnectionData &p_cd, const PackedStringArray &p_signal_args, bool p_edit) {
694700 set_hide_on_ok (false );
695701
696- source = static_cast <Node *>( p_cd.source ) ;
702+ source = p_cd.source ;
697703 signal = p_cd.signal ;
698704 signal_args = p_signal_args;
699705
700706 tree->set_selected (nullptr );
701- tree->set_marked (source);
707+ tree->set_marked (Object::cast_to<Node>( source) );
702708
703709 if (p_cd.target ) {
704- set_dst_node (static_cast <Node * >(p_cd.target ));
710+ set_dst_node (Object::cast_to <Node>(p_cd.target ));
705711 set_dst_method (p_cd.method );
706712 }
707713
@@ -985,7 +991,8 @@ void ConnectionsDock::_filter_changed(const String &p_text) {
985991 */
986992void ConnectionsDock::_make_or_edit_connection () {
987993 NodePath dst_path = connect_dialog->get_dst_path ();
988- Node *target = selected_node->get_node (dst_path);
994+ Node *target = Object::cast_to<Node>(selected_object)->get_node (dst_path);
995+
989996 ERR_FAIL_NULL (target);
990997
991998 ConnectDialog::ConnectionData cd;
@@ -1078,7 +1085,7 @@ void ConnectionsDock::_make_or_edit_connection() {
10781085 script_function_args.push_back (" extra_arg_" + itos (i) + " : " + Variant::get_type_name (cd.binds [i].get_type ()));
10791086 }
10801087
1081- EditorNode::get_singleton ()->emit_signal (SNAME (" script_add_function_request" ), target, cd.method , script_function_args);
1088+ EditorNode::get_singleton ()->emit_signal (SNAME (" script_add_function_request" ), cd. target , cd.method , script_function_args);
10821089 }
10831090
10841091 if (connect_dialog->is_editing ()) {
@@ -1095,7 +1102,7 @@ void ConnectionsDock::_make_or_edit_connection() {
10951102 * Creates single connection w/ undo-redo functionality.
10961103 */
10971104void ConnectionsDock::_connect (const ConnectDialog::ConnectionData &p_cd) {
1098- Node *source = Object::cast_to<Node>( p_cd.source ) ;
1105+ Object *source = p_cd.source ;
10991106 Node *target = Object::cast_to<Node>(p_cd.target );
11001107
11011108 if (!source || !target) {
@@ -1119,14 +1126,14 @@ void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
11191126 * Break single connection w/ undo-redo functionality.
11201127 */
11211128void ConnectionsDock::_disconnect (const ConnectDialog::ConnectionData &p_cd) {
1122- ERR_FAIL_COND (p_cd.source != selected_node ); // Shouldn't happen but... Bugcheck.
1129+ ERR_FAIL_COND (p_cd.source != selected_object ); // Shouldn't happen but... Bugcheck.
11231130
11241131 EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
11251132 undo_redo->create_action (vformat (TTR (" Disconnect '%s' from '%s'" ), p_cd.signal , p_cd.method ));
11261133
11271134 Callable callable = p_cd.get_callable ();
1128- undo_redo->add_do_method (selected_node , " disconnect" , p_cd.signal , callable);
1129- undo_redo->add_undo_method (selected_node , " connect" , p_cd.signal , callable, p_cd.flags );
1135+ undo_redo->add_do_method (selected_object , " disconnect" , p_cd.signal , callable);
1136+ undo_redo->add_undo_method (selected_object , " connect" , p_cd.signal , callable, p_cd.flags );
11301137 undo_redo->add_do_method (this , " update_tree" );
11311138 undo_redo->add_undo_method (this , " update_tree" );
11321139 undo_redo->add_do_method (SceneTreeDock::get_singleton ()->get_tree_editor (), " update_tree" ); // To force redraw of scene tree.
@@ -1154,8 +1161,8 @@ void ConnectionsDock::_disconnect_all() {
11541161 Connection connection = child->get_metadata (0 );
11551162 if (!_is_connection_inherited (connection)) {
11561163 ConnectDialog::ConnectionData cd = connection;
1157- undo_redo->add_do_method (selected_node , " disconnect" , cd.signal , cd.get_callable ());
1158- undo_redo->add_undo_method (selected_node , " connect" , cd.signal , cd.get_callable (), cd.flags );
1164+ undo_redo->add_do_method (selected_object , " disconnect" , cd.signal , cd.get_callable ());
1165+ undo_redo->add_undo_method (selected_object , " connect" , cd.signal , cd.get_callable (), cd.flags );
11591166 }
11601167 child = child->get_next ();
11611168 }
@@ -1173,7 +1180,7 @@ void ConnectionsDock::_tree_item_selected() {
11731180 if (item && _get_item_type (*item) == TREE_ITEM_TYPE_SIGNAL) {
11741181 connect_button->set_text (TTR (" Connect..." ));
11751182 connect_button->set_button_icon (get_editor_theme_icon (SNAME (" Instance" )));
1176- connect_button->set_disabled (false );
1183+ connect_button->set_disabled (is_editing_resource );
11771184 } else if (item && _get_item_type (*item) == TREE_ITEM_TYPE_CONNECTION) {
11781185 connect_button->set_text (TTR (" Disconnect" ));
11791186 connect_button->set_button_icon (get_editor_theme_icon (SNAME (" Unlinked" )));
@@ -1220,19 +1227,24 @@ bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) {
12201227 * Open connection dialog with TreeItem data to CREATE a brand-new connection.
12211228 */
12221229void ConnectionsDock::_open_connection_dialog (TreeItem &p_item) {
1230+ if (is_editing_resource) {
1231+ return ;
1232+ }
1233+
12231234 const Dictionary sinfo = p_item.get_metadata (0 );
12241235 const StringName signal_name = sinfo[" name" ];
12251236 const PackedStringArray signal_args = sinfo[" args" ];
12261237
1238+ ConnectDialog::ConnectionData cd;
1239+
1240+ Node *selected_node = Object::cast_to<Node>(selected_object);
12271241 Node *dst_node = selected_node->get_owner () ? selected_node->get_owner () : selected_node;
12281242 if (!dst_node || dst_node->get_script ().is_null ()) {
12291243 dst_node = _find_first_script (get_tree ()->get_edited_scene_root (), get_tree ()->get_edited_scene_root ());
12301244 }
1231-
1232- ConnectDialog::ConnectionData cd;
1233- cd.source = selected_node;
1234- cd.signal = signal_name;
1245+ cd.source = selected_object;
12351246 cd.target = dst_node;
1247+ cd.signal = signal_name;
12361248 cd.method = ConnectDialog::generate_method_callback_name (cd.source , signal_name, cd.target );
12371249 connect_dialog->init (cd, signal_args);
12381250 connect_dialog->set_title (TTR (" Connect a Signal to a Method" ));
@@ -1249,8 +1261,8 @@ void ConnectionsDock::_open_edit_connection_dialog(TreeItem &p_item) {
12491261 Connection connection = p_item.get_metadata (0 );
12501262 ConnectDialog::ConnectionData cd = connection;
12511263
1252- Node *src = Object::cast_to<Node>( cd.source ) ;
1253- Node *dst = Object::cast_to<Node>( cd.target ) ;
1264+ Object *src = cd.source ;
1265+ Object *dst = cd.target ;
12541266
12551267 if (src && dst) {
12561268 const StringName &signal_name = cd.signal ;
@@ -1272,7 +1284,7 @@ void ConnectionsDock::_go_to_method(TreeItem &p_item) {
12721284
12731285 Connection connection = p_item.get_metadata (0 );
12741286 ConnectDialog::ConnectionData cd = connection;
1275- ERR_FAIL_COND (cd.source != selected_node ); // Shouldn't happen but... bugcheck.
1287+ ERR_FAIL_COND (cd.source != selected_object ); // Shouldn't happen but... bugcheck.
12761288
12771289 if (!cd.target ) {
12781290 return ;
@@ -1343,6 +1355,7 @@ void ConnectionsDock::_signal_menu_about_to_popup() {
13431355 }
13441356 }
13451357
1358+ signal_menu->set_item_disabled (signal_menu->get_item_index (SIGNAL_MENU_CONNECT), is_editing_resource);
13461359 signal_menu->set_item_disabled (signal_menu->get_item_index (SIGNAL_MENU_DISCONNECT_ALL), disable_disconnect_all);
13471360 signal_menu->set_item_disabled (signal_menu->get_item_index (SIGNAL_MENU_OPEN_DOCS), String (meta[" class" ]).is_empty ());
13481361}
@@ -1510,8 +1523,9 @@ void ConnectionsDock::_bind_methods() {
15101523 ClassDB::bind_method (" update_tree" , &ConnectionsDock::update_tree);
15111524}
15121525
1513- void ConnectionsDock::set_node (Node *p_node) {
1514- selected_node = p_node;
1526+ void ConnectionsDock::set_object (Object *p_obj) {
1527+ selected_object = p_obj;
1528+ is_editing_resource = (Object::cast_to<Resource>(selected_object) != nullptr );
15151529 update_tree ();
15161530}
15171531
@@ -1522,15 +1536,15 @@ void ConnectionsDock::update_tree() {
15221536 }
15231537 tree->clear ();
15241538
1525- if (!selected_node ) {
1539+ if (!selected_object ) {
15261540 return ;
15271541 }
15281542
15291543 TreeItem *root = tree->create_item ();
15301544 DocTools *doc_data = EditorHelp::get_doc_data ();
15311545 EditorData &editor_data = EditorNode::get_editor_data ();
1532- StringName native_base = selected_node ->get_class ();
1533- Ref<Script> script_base = selected_node ->get_script ();
1546+ StringName native_base = selected_object ->get_class ();
1547+ Ref<Script> script_base = selected_object ->get_script ();
15341548
15351549 while (native_base != StringName ()) {
15361550 String class_name;
@@ -1644,7 +1658,7 @@ void ConnectionsDock::update_tree() {
16441658
16451659 // List existing connections.
16461660 List<Object::Connection> existing_connections;
1647- selected_node ->get_signal_connection_list (signal_name, &existing_connections);
1661+ selected_object ->get_signal_connection_list (signal_name, &existing_connections);
16481662
16491663 for (const Object::Connection &F : existing_connections) {
16501664 Connection connection = F;
@@ -1658,7 +1672,7 @@ void ConnectionsDock::update_tree() {
16581672 continue ;
16591673 }
16601674
1661- String path = String (selected_node ->get_path_to (target)) + " :: " + cd.method + " ()" ;
1675+ String path = String (Object::cast_to<Node>(selected_object) ->get_path_to (target)) + " :: " + cd.method + " ()" ;
16621676 if (cd.flags & CONNECT_DEFERRED) {
16631677 path += " (deferred)" ;
16641678 }
@@ -1695,7 +1709,7 @@ void ConnectionsDock::update_tree() {
16951709 }
16961710 }
16971711
1698- connect_button->set_text (TTR (" Connect..." ));
1712+ connect_button->set_text (TTRC (" Connect..." ));
16991713 connect_button->set_button_icon (get_editor_theme_icon (SNAME (" Instance" )));
17001714 connect_button->set_disabled (true );
17011715}
0 commit comments