@@ -173,14 +173,48 @@ FileSystemList::FileSystemList() {
173173
174174FileSystemDock *FileSystemDock::singleton = nullptr ;
175175
176- Ref<Texture2D> FileSystemDock::_get_tree_item_icon (bool p_is_valid, const String &p_file_type) {
177- Ref<Texture2D> file_icon;
176+ Ref<Texture2D> FileSystemDock::_get_tree_item_icon (bool p_is_valid, const String &p_file_type, const String &p_icon_path) {
177+ if (!p_icon_path.is_empty ()) {
178+ Ref<Texture2D> icon = ResourceLoader::load (p_icon_path);
179+ if (icon.is_valid ()) {
180+ return icon;
181+ }
182+ }
183+
178184 if (!p_is_valid) {
179- file_icon = get_editor_theme_icon (SNAME (" ImportFail" ));
185+ return get_editor_theme_icon (SNAME (" ImportFail" ));
186+ } else if (has_theme_icon (p_file_type, EditorStringName (EditorIcons))) {
187+ return get_editor_theme_icon (p_file_type);
180188 } else {
181- file_icon = ( has_theme_icon (p_file_type, EditorStringName (EditorIcons))) ? get_editor_theme_icon (p_file_type) : get_editor_theme_icon (SNAME (" File" ));
189+ return get_editor_theme_icon (SNAME (" File" ));
182190 }
183- return file_icon;
191+ }
192+
193+ String FileSystemDock::_get_entry_script_icon (const EditorFileSystemDirectory *p_dir, int p_file) {
194+ const PackedStringArray &deps = p_dir->get_file_deps (p_file);
195+ if (deps.is_empty ()) {
196+ return String ();
197+ }
198+
199+ const String &script_path = deps[0 ]; // Assuming the first dependency is a script.
200+ if (script_path.is_empty () || !ClassDB::is_parent_class (ResourceLoader::get_resource_type (script_path), SNAME (" Script" ))) {
201+ return String ();
202+ }
203+
204+ String *cached = icon_cache.getptr (script_path);
205+ if (cached) {
206+ return *cached;
207+ }
208+
209+ HashMap<String, String>::Iterator I;
210+ int script_file;
211+ EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton ()->find_file (script_path, &script_file);
212+ if (efsd) {
213+ I = icon_cache.insert (script_path, efsd->get_file_script_class_icon_path (script_file));
214+ } else {
215+ I = icon_cache.insert (script_path, String ());
216+ }
217+ return I->value ;
184218}
185219
186220bool FileSystemDock::_create_tree (TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites, bool p_unfold_path) {
@@ -272,6 +306,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
272306 FileInfo fi;
273307 fi.name = p_dir->get_file (i);
274308 fi.type = p_dir->get_file_type (i);
309+ fi.icon_path = _get_entry_script_icon (p_dir, i);
275310 fi.import_broken = !p_dir->get_file_import_is_valid (i);
276311 fi.modified_time = p_dir->get_file_modified_time (i);
277312
@@ -282,18 +317,21 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
282317 _sort_file_info_list (file_list);
283318
284319 // Build the tree.
320+ const int icon_size = get_theme_constant (SNAME (" class_icon_size" ), SNAME (" Editor" ));
321+
285322 for (const FileInfo &fi : file_list) {
286323 TreeItem *file_item = tree->create_item (subdirectory_item);
324+ const String file_metadata = lpath.path_join (fi.name );
287325 file_item->set_text (0 , fi.name );
288326 file_item->set_structured_text_bidi_override (0 , TextServer::STRUCTURED_TEXT_FILE );
289- file_item->set_icon (0 , _get_tree_item_icon (!fi.import_broken , fi.type ));
327+ file_item->set_icon (0 , _get_tree_item_icon (!fi.import_broken , fi.type , fi.icon_path ));
328+ file_item->set_icon_max_width (0 , icon_size);
290329 Color parent_bg_color = subdirectory_item->get_custom_bg_color (0 );
291330 if (has_custom_color) {
292331 file_item->set_custom_bg_color (0 , parent_bg_color.darkened (0.3 ));
293332 } else if (parent_bg_color != Color ()) {
294333 file_item->set_custom_bg_color (0 , parent_bg_color);
295334 }
296- String file_metadata = lpath.path_join (fi.name );
297335 file_item->set_metadata (0 , file_metadata);
298336 if (!p_select_in_favorites && current_path == file_metadata) {
299337 file_item->select (0 );
@@ -366,6 +404,8 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
366404 updating_tree = true ;
367405 TreeItem *root = tree->create_item ();
368406
407+ icon_cache.clear ();
408+
369409 // Handles the favorites.
370410 TreeItem *favorites_item = tree->create_item (root);
371411 favorites_item->set_icon (0 , get_editor_theme_icon (SNAME (" Favorites" )));
@@ -413,7 +453,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
413453 int index;
414454 EditorFileSystemDirectory *dir = EditorFileSystem::get_singleton ()->find_file (favorite, &index);
415455 if (dir) {
416- icon = _get_tree_item_icon (dir->get_file_import_is_valid (index), dir->get_file_type (index));
456+ icon = _get_tree_item_icon (dir->get_file_import_is_valid (index), dir->get_file_path (index), dir-> get_file_type (index));
417457 } else {
418458 icon = get_editor_theme_icon (SNAME (" File" ));
419459 }
0 commit comments