From 826096bac37a240157fb75188749648d4825489d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 13 Nov 2020 00:34:09 +0000 Subject: LibGUI: Make FileIconProvider aware of all supported image formats By using Gfx::Bitmap::is_path_a_supported_image_format() we can automatically provide the image icon for all supported image formats, without keeping a second list of image file extensions. --- Libraries/LibGUI/FileIconProvider.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/FileIconProvider.cpp b/Libraries/LibGUI/FileIconProvider.cpp index 8b4c0c6695..b836923eb8 100644 --- a/Libraries/LibGUI/FileIconProvider.cpp +++ b/Libraries/LibGUI/FileIconProvider.cpp @@ -39,7 +39,6 @@ namespace GUI { F(hackstudio, ".hsp") \ F(header, ".h", ".hpp", ".hxx", ".hh", ".h++") \ F(html, ".html", ".htm") \ - F(image, ".png") \ F(java, ".java") \ F(javascript, ".js", ".mjs") \ F(library, ".so", ".a") \ @@ -68,6 +67,7 @@ static Icon s_file_icon; static Icon s_symlink_icon; static Icon s_socket_icon; static Icon s_executable_icon; +static Icon s_filetype_image_icon; static void initialize_if_needed() { @@ -84,6 +84,7 @@ static void initialize_if_needed() s_symlink_icon = Icon::default_icon("filetype-symlink"); s_socket_icon = Icon::default_icon("filetype-socket"); s_executable_icon = Icon::default_icon("filetype-executable"); + s_filetype_image_icon = Icon::default_icon("filetype-image"); #define __ENUMERATE_FILETYPE(filetype_name, ...) \ s_filetype_##filetype_name##_icon = Icon::default_icon("filetype-" #filetype_name); @@ -150,6 +151,9 @@ Icon FileIconProvider::icon_for_path(const String& path, mode_t mode) if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) return s_executable_icon; + if (Gfx::Bitmap::is_path_a_supported_image_format(path.view())) + return s_filetype_image_icon; + #define __ENUMERATE_FILETYPE(filetype_name, filetype_extensions...) \ for (auto& extension : { filetype_extensions }) { \ if (path.ends_with(extension, CaseSensitivity::CaseInsensitive)) \ -- cgit v1.2.3