@@ -161,6 +161,10 @@ String EditorFileSystemDirectory::get_file_script_class_icon_path(int p_idx) con
161161 return files[p_idx]->script_class_icon_path ;
162162}
163163
164+ String EditorFileSystemDirectory::get_file_icon_path (int p_idx) const {
165+ return files[p_idx]->icon_path ;
166+ }
167+
164168StringName EditorFileSystemDirectory::get_file_type (int p_idx) const {
165169 ERR_FAIL_INDEX_V (p_idx, files.size (), " " );
166170 return files[p_idx]->type ;
@@ -740,6 +744,8 @@ void EditorFileSystem::scan() {
740744 scanning = false ;
741745 _update_pending_script_classes ();
742746 _update_pending_scene_groups ();
747+ // Update all icons so they are loaded for the FileSystemDock.
748+ _update_files_icon_path ();
743749 emit_signal (SNAME (" filesystem_changed" ));
744750 emit_signal (SNAME (" sources_changed" ), sources_changed.size () > 0 );
745751 first_scan = false ;
@@ -1298,6 +1304,8 @@ void EditorFileSystem::_notification(int p_what) {
12981304 _update_scan_actions ();
12991305 _update_pending_script_classes ();
13001306 _update_pending_scene_groups ();
1307+ // Update all icons so they are loaded for the FileSystemDock.
1308+ _update_files_icon_path ();
13011309 emit_signal (SNAME (" filesystem_changed" ));
13021310 emit_signal (SNAME (" sources_changed" ), sources_changed.size () > 0 );
13031311 first_scan = false ;
@@ -1578,6 +1586,43 @@ String EditorFileSystem::_get_global_script_class(const String &p_type, const St
15781586 return String ();
15791587}
15801588
1589+ void EditorFileSystem::_update_file_icon_path (EditorFileSystemDirectory::FileInfo *file_info) {
1590+ String icon_path;
1591+ if (file_info->script_class_icon_path .is_empty () && !file_info->deps .is_empty ()) {
1592+ const String &script_path = file_info->deps [0 ]; // Assuming the first dependency is a script.
1593+ if (!script_path.is_empty ()) {
1594+ String *cached = file_icon_cache.getptr (script_path);
1595+ if (cached) {
1596+ icon_path = *cached;
1597+ } else {
1598+ if (ClassDB::is_parent_class (ResourceLoader::get_resource_type (script_path), SNAME (" Script" ))) {
1599+ int script_file;
1600+ EditorFileSystemDirectory *efsd = find_file (script_path, &script_file);
1601+ if (efsd) {
1602+ icon_path = efsd->files [script_file]->script_class_icon_path ;
1603+ }
1604+ }
1605+ file_icon_cache.insert (script_path, icon_path);
1606+ }
1607+ }
1608+ }
1609+
1610+ file_info->icon_path = icon_path;
1611+ }
1612+
1613+ void EditorFileSystem::_update_files_icon_path (EditorFileSystemDirectory *edp) {
1614+ if (!edp) {
1615+ edp = filesystem;
1616+ file_icon_cache.clear ();
1617+ }
1618+ for (EditorFileSystemDirectory *sub_dir : edp->subdirs ) {
1619+ _update_files_icon_path (sub_dir);
1620+ }
1621+ for (EditorFileSystemDirectory::FileInfo *fi : edp->files ) {
1622+ _update_file_icon_path (fi);
1623+ }
1624+ }
1625+
15811626void EditorFileSystem::_update_script_classes () {
15821627 update_script_mutex.lock ();
15831628
@@ -1719,6 +1764,8 @@ void EditorFileSystem::update_file(const String &p_file) {
17191764
17201765void EditorFileSystem::update_files (const Vector<String> &p_script_paths) {
17211766 bool updated = false ;
1767+ bool update_files_icon_cache = false ;
1768+ Vector<EditorFileSystemDirectory::FileInfo *> files_to_update_icon_path;
17221769 for (const String &file : p_script_paths) {
17231770 ERR_CONTINUE (file.is_empty ());
17241771 EditorFileSystemDirectory *fs = nullptr ;
@@ -1741,6 +1788,9 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
17411788 }
17421789 if (ClassDB::is_parent_class (fs->files [cpos]->type , SNAME (" Script" ))) {
17431790 _queue_update_script_class (file);
1791+ if (!fs->files [cpos]->script_class_icon_path .is_empty ()) {
1792+ update_files_icon_cache = true ;
1793+ }
17441794 }
17451795 if (fs->files [cpos]->type == SNAME (" PackedScene" )) {
17461796 _queue_update_scene_groups (file);
@@ -1789,6 +1839,7 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
17891839 _save_late_updated_files (); // files need to be updated in the re-scan
17901840 }
17911841
1842+ const String old_script_class_icon_path = fs->files [cpos]->script_class_icon_path ;
17921843 fs->files [cpos]->type = type;
17931844 fs->files [cpos]->resource_script_class = script_class;
17941845 fs->files [cpos]->uid = uid;
@@ -1816,13 +1867,25 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
18161867 if (fs->files [cpos]->type == SNAME (" PackedScene" )) {
18171868 _queue_update_scene_groups (file);
18181869 }
1870+ if (fs->files [cpos]->type == SNAME (" Resource" )) {
1871+ files_to_update_icon_path.push_back (fs->files [cpos]);
1872+ } else if (old_script_class_icon_path != fs->files [cpos]->script_class_icon_path ) {
1873+ update_files_icon_cache = true ;
1874+ }
18191875 updated = true ;
18201876 }
18211877 }
18221878
18231879 if (updated) {
18241880 _update_pending_script_classes ();
18251881 _update_pending_scene_groups ();
1882+ if (update_files_icon_cache) {
1883+ _update_files_icon_path ();
1884+ } else {
1885+ for (EditorFileSystemDirectory::FileInfo *fi : files_to_update_icon_path) {
1886+ _update_file_icon_path (fi);
1887+ }
1888+ }
18261889 call_deferred (SNAME (" emit_signal" ), " filesystem_changed" ); // update later
18271890 }
18281891}
0 commit comments