@@ -1561,10 +1561,42 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin
15611561}
15621562
15631563void FileSystemDock::_update_resource_paths_after_move (const HashMap<String, String> &p_renames, const HashMap<String, ResourceUID::ID> &p_uids) const {
1564- // Update the paths in ResourceUID, so that UIDs remain valid.
1565- for (const KeyValue<String, ResourceUID::ID> &pair : p_uids) {
1566- if (p_renames.has (pair.key )) {
1567- ResourceUID::get_singleton ()->set_id (pair.value , p_renames[pair.key ]);
1564+ for (const KeyValue<String, String> &pair : p_renames) {
1565+ // Update UID path.
1566+ const String &old_path = pair.key ;
1567+ const String &new_path = pair.value ;
1568+
1569+ const HashMap<String, ResourceUID::ID>::ConstIterator I = p_uids.find (old_path);
1570+ if (I) {
1571+ ResourceUID::get_singleton ()->set_id (I->value , new_path);
1572+ }
1573+
1574+ ScriptServer::remove_global_class_by_path (old_path);
1575+
1576+ int index = -1 ;
1577+ EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton ()->find_file (old_path, &index);
1578+
1579+ if (!efd || index < 0 ) {
1580+ // The file was removed.
1581+ continue ;
1582+ }
1583+
1584+ // Update paths for global classes.
1585+ if (!efd->get_file_script_class_name (index).is_empty ()) {
1586+ String lang;
1587+ for (int i = 0 ; i < ScriptServer::get_language_count (); i++) {
1588+ if (ScriptServer::get_language (i)->handles_global_class_type (efd->get_file_type (index))) {
1589+ lang = ScriptServer::get_language (i)->get_name ();
1590+ break ;
1591+ }
1592+ }
1593+ if (lang.is_empty ()) {
1594+ continue ; // No language found that can handle this global class.
1595+ }
1596+
1597+ ScriptServer::add_global_class (efd->get_file_script_class_name (index), efd->get_file_script_class_extends (index), lang, new_path);
1598+ EditorNode::get_editor_data ().script_class_set_icon_path (efd->get_file_script_class_name (index), efd->get_file_script_class_icon_path (index));
1599+ EditorNode::get_editor_data ().script_class_set_name (new_path, efd->get_file_script_class_name (index));
15681600 }
15691601 }
15701602
@@ -1583,10 +1615,13 @@ void FileSystemDock::_update_resource_paths_after_move(const HashMap<String, Str
15831615
15841616 if (p_renames.has (base_path)) {
15851617 base_path = p_renames[base_path];
1618+ r->set_path (base_path + extra_path);
15861619 }
1587-
1588- r->set_path (base_path + extra_path);
15891620 }
1621+
1622+ ScriptServer::save_global_classes ();
1623+ EditorNode::get_editor_data ().script_class_save_icon_paths ();
1624+ EditorFileSystem::get_singleton ()->emit_signal (SNAME (" script_classes_updated" ));
15901625}
15911626
15921627void FileSystemDock::_update_dependencies_after_move (const HashMap<String, String> &p_renames, const HashSet<String> &p_file_owners) const {
@@ -1710,6 +1745,13 @@ void FileSystemDock::_make_scene_confirm() {
17101745}
17111746
17121747void FileSystemDock::_resource_removed (const Ref<Resource> &p_resource) {
1748+ const Ref<Script> &scr = p_resource;
1749+ if (scr.is_valid ()) {
1750+ ScriptServer::remove_global_class_by_path (scr->get_path ());
1751+ ScriptServer::save_global_classes ();
1752+ EditorNode::get_editor_data ().script_class_save_icon_paths ();
1753+ EditorFileSystem::get_singleton ()->emit_signal (SNAME (" script_classes_updated" ));
1754+ }
17131755 emit_signal (SNAME (" resource_removed" ), p_resource);
17141756}
17151757
0 commit comments