@@ -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
@@ -984,7 +990,8 @@ void ConnectionsDock::_filter_changed(const String &p_text) {
984990 */
985991void ConnectionsDock::_make_or_edit_connection () {
986992 NodePath dst_path = connect_dialog->get_dst_path ();
987- Node *target = selected_node->get_node (dst_path);
993+ Node *target = Object::cast_to<Node>(selected_object)->get_node (dst_path);
994+
988995 ERR_FAIL_NULL (target);
989996
990997 ConnectDialog::ConnectionData cd;
@@ -1077,7 +1084,7 @@ void ConnectionsDock::_make_or_edit_connection() {
10771084 script_function_args.push_back (" extra_arg_" + itos (i) + " : " + Variant::get_type_name (cd.binds [i].get_type ()));
10781085 }
10791086
1080- EditorNode::get_singleton ()->emit_signal (SNAME (" script_add_function_request" ), target, cd.method , script_function_args);
1087+ EditorNode::get_singleton ()->emit_signal (SNAME (" script_add_function_request" ), cd. target , cd.method , script_function_args);
10811088 }
10821089
10831090 if (connect_dialog->is_editing ()) {
@@ -1094,7 +1101,7 @@ void ConnectionsDock::_make_or_edit_connection() {
10941101 * Creates single connection w/ undo-redo functionality.
10951102 */
10961103void ConnectionsDock::_connect (const ConnectDialog::ConnectionData &p_cd) {
1097- Node *source = Object::cast_to<Node>( p_cd.source ) ;
1104+ Object *source = p_cd.source ;
10981105 Node *target = Object::cast_to<Node>(p_cd.target );
10991106
11001107 if (!source || !target) {
@@ -1118,14 +1125,14 @@ void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
11181125 * Break single connection w/ undo-redo functionality.
11191126 */
11201127void ConnectionsDock::_disconnect (const ConnectDialog::ConnectionData &p_cd) {
1121- ERR_FAIL_COND (p_cd.source != selected_node ); // Shouldn't happen but... Bugcheck.
1128+ ERR_FAIL_COND (p_cd.source != selected_object ); // Shouldn't happen but... Bugcheck.
11221129
11231130 EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
11241131 undo_redo->create_action (vformat (TTR (" Disconnect '%s' from '%s'" ), p_cd.signal , p_cd.method ));
11251132
11261133 Callable callable = p_cd.get_callable ();
1127- undo_redo->add_do_method (selected_node , " disconnect" , p_cd.signal , callable);
1128- undo_redo->add_undo_method (selected_node , " connect" , p_cd.signal , callable, p_cd.flags );
1134+ undo_redo->add_do_method (selected_object , " disconnect" , p_cd.signal , callable);
1135+ undo_redo->add_undo_method (selected_object , " connect" , p_cd.signal , callable, p_cd.flags );
11291136 undo_redo->add_do_method (this , " update_tree" );
11301137 undo_redo->add_undo_method (this , " update_tree" );
11311138 undo_redo->add_do_method (SceneTreeDock::get_singleton ()->get_tree_editor (), " update_tree" ); // To force redraw of scene tree.
@@ -1153,8 +1160,8 @@ void ConnectionsDock::_disconnect_all() {
11531160 Connection connection = child->get_metadata (0 );
11541161 if (!_is_connection_inherited (connection)) {
11551162 ConnectDialog::ConnectionData cd = connection;
1156- undo_redo->add_do_method (selected_node , " disconnect" , cd.signal , cd.get_callable ());
1157- undo_redo->add_undo_method (selected_node , " connect" , cd.signal , cd.get_callable (), cd.flags );
1163+ undo_redo->add_do_method (selected_object , " disconnect" , cd.signal , cd.get_callable ());
1164+ undo_redo->add_undo_method (selected_object , " connect" , cd.signal , cd.get_callable (), cd.flags );
11581165 }
11591166 child = child->get_next ();
11601167 }
@@ -1172,7 +1179,7 @@ void ConnectionsDock::_tree_item_selected() {
11721179 if (item && _get_item_type (*item) == TREE_ITEM_TYPE_SIGNAL) {
11731180 connect_button->set_text (TTR (" Connect..." ));
11741181 connect_button->set_button_icon (get_editor_theme_icon (SNAME (" Instance" )));
1175- connect_button->set_disabled (false );
1182+ connect_button->set_disabled (is_editing_resource );
11761183 } else if (item && _get_item_type (*item) == TREE_ITEM_TYPE_CONNECTION) {
11771184 connect_button->set_text (TTR (" Disconnect" ));
11781185 connect_button->set_button_icon (get_editor_theme_icon (SNAME (" Unlinked" )));
@@ -1219,19 +1226,24 @@ bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) {
12191226 * Open connection dialog with TreeItem data to CREATE a brand-new connection.
12201227 */
12211228void ConnectionsDock::_open_connection_dialog (TreeItem &p_item) {
1229+ if (is_editing_resource) {
1230+ return ;
1231+ }
1232+
12221233 const Dictionary sinfo = p_item.get_metadata (0 );
12231234 const StringName signal_name = sinfo[" name" ];
12241235 const PackedStringArray signal_args = sinfo[" args" ];
12251236
1237+ ConnectDialog::ConnectionData cd;
1238+
1239+ Node *selected_node = Object::cast_to<Node>(selected_object);
12261240 Node *dst_node = selected_node->get_owner () ? selected_node->get_owner () : selected_node;
12271241 if (!dst_node || dst_node->get_script ().is_null ()) {
12281242 dst_node = _find_first_script (get_tree ()->get_edited_scene_root (), get_tree ()->get_edited_scene_root ());
12291243 }
1230-
1231- ConnectDialog::ConnectionData cd;
1232- cd.source = selected_node;
1233- cd.signal = signal_name;
1244+ cd.source = selected_object;
12341245 cd.target = dst_node;
1246+ cd.signal = signal_name;
12351247 cd.method = ConnectDialog::generate_method_callback_name (cd.source , signal_name, cd.target );
12361248 connect_dialog->init (cd, signal_args);
12371249 connect_dialog->set_title (TTR (" Connect a Signal to a Method" ));
@@ -1248,8 +1260,8 @@ void ConnectionsDock::_open_edit_connection_dialog(TreeItem &p_item) {
12481260 Connection connection = p_item.get_metadata (0 );
12491261 ConnectDialog::ConnectionData cd = connection;
12501262
1251- Node *src = Object::cast_to<Node>( cd.source ) ;
1252- Node *dst = Object::cast_to<Node>( cd.target ) ;
1263+ Object *src = cd.source ;
1264+ Object *dst = cd.target ;
12531265
12541266 if (src && dst) {
12551267 const StringName &signal_name = cd.signal ;
@@ -1271,7 +1283,7 @@ void ConnectionsDock::_go_to_method(TreeItem &p_item) {
12711283
12721284 Connection connection = p_item.get_metadata (0 );
12731285 ConnectDialog::ConnectionData cd = connection;
1274- ERR_FAIL_COND (cd.source != selected_node ); // Shouldn't happen but... bugcheck.
1286+ ERR_FAIL_COND (cd.source != selected_object ); // Shouldn't happen but... bugcheck.
12751287
12761288 if (!cd.target ) {
12771289 return ;
@@ -1342,6 +1354,7 @@ void ConnectionsDock::_signal_menu_about_to_popup() {
13421354 }
13431355 }
13441356
1357+ signal_menu->set_item_disabled (signal_menu->get_item_index (SIGNAL_MENU_CONNECT), is_editing_resource);
13451358 signal_menu->set_item_disabled (signal_menu->get_item_index (SIGNAL_MENU_DISCONNECT_ALL), disable_disconnect_all);
13461359 signal_menu->set_item_disabled (signal_menu->get_item_index (SIGNAL_MENU_OPEN_DOCS), String (meta[" class" ]).is_empty ());
13471360}
@@ -1509,8 +1522,9 @@ void ConnectionsDock::_bind_methods() {
15091522 ClassDB::bind_method (" update_tree" , &ConnectionsDock::update_tree);
15101523}
15111524
1512- void ConnectionsDock::set_node (Node *p_node) {
1513- selected_node = p_node;
1525+ void ConnectionsDock::set_object (Object *p_obj) {
1526+ selected_object = p_obj;
1527+ is_editing_resource = (Object::cast_to<Resource>(selected_object) != nullptr );
15141528 update_tree ();
15151529}
15161530
@@ -1521,15 +1535,15 @@ void ConnectionsDock::update_tree() {
15211535 }
15221536 tree->clear ();
15231537
1524- if (!selected_node ) {
1538+ if (!selected_object ) {
15251539 return ;
15261540 }
15271541
15281542 TreeItem *root = tree->create_item ();
15291543 DocTools *doc_data = EditorHelp::get_doc_data ();
15301544 EditorData &editor_data = EditorNode::get_editor_data ();
1531- StringName native_base = selected_node ->get_class ();
1532- Ref<Script> script_base = selected_node ->get_script ();
1545+ StringName native_base = selected_object ->get_class ();
1546+ Ref<Script> script_base = selected_object ->get_script ();
15331547
15341548 while (native_base != StringName ()) {
15351549 String class_name;
@@ -1643,7 +1657,7 @@ void ConnectionsDock::update_tree() {
16431657
16441658 // List existing connections.
16451659 List<Object::Connection> existing_connections;
1646- selected_node ->get_signal_connection_list (signal_name, &existing_connections);
1660+ selected_object ->get_signal_connection_list (signal_name, &existing_connections);
16471661
16481662 for (const Object::Connection &F : existing_connections) {
16491663 Connection connection = F;
@@ -1657,7 +1671,7 @@ void ConnectionsDock::update_tree() {
16571671 continue ;
16581672 }
16591673
1660- String path = String (selected_node ->get_path_to (target)) + " :: " + cd.method + " ()" ;
1674+ String path = String (Object::cast_to<Node>(selected_object) ->get_path_to (target)) + " :: " + cd.method + " ()" ;
16611675 if (cd.flags & CONNECT_DEFERRED) {
16621676 path += " (deferred)" ;
16631677 }
@@ -1694,7 +1708,7 @@ void ConnectionsDock::update_tree() {
16941708 }
16951709 }
16961710
1697- connect_button->set_text (TTR (" Connect..." ));
1711+ connect_button->set_text (TTRC (" Connect..." ));
16981712 connect_button->set_button_icon (get_editor_theme_icon (SNAME (" Instance" )));
16991713 connect_button->set_disabled (true );
17001714}
0 commit comments