From b1754bf8f8e9a42c6a0803e2c2a19164153a38cc Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 12 Nov 2020 22:19:05 +0000 Subject: [PATCH] HackStudio: Use GUI::FileIconProvider::icon_for_path() for Locator icons No need to duplicate file icon association logic as well as artificially limiting the number of recognized file types. --- DevTools/HackStudio/Locator.cpp | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/DevTools/HackStudio/Locator.cpp b/DevTools/HackStudio/Locator.cpp index 8c856aa693..f207df2985 100644 --- a/DevTools/HackStudio/Locator.cpp +++ b/DevTools/HackStudio/Locator.cpp @@ -28,18 +28,13 @@ #include "HackStudio.h" #include "Project.h" #include +#include #include #include #include namespace HackStudio { -static RefPtr s_file_icon; -static RefPtr s_cplusplus_icon; -static RefPtr s_header_icon; -static RefPtr s_form_icon; -static RefPtr s_hackstudio_icon; - class LocatorSuggestionModel final : public GUI::Model { public: explicit LocatorSuggestionModel(Vector&& suggestions) @@ -60,17 +55,8 @@ public: if (role == GUI::ModelRole::Display) { if (index.column() == Column::Name) return suggestion; - if (index.column() == Column::Icon) { - if (suggestion.ends_with(".cpp")) - return *s_cplusplus_icon; - if (suggestion.ends_with(".frm")) - return *s_form_icon; - if (suggestion.ends_with(".h")) - return *s_header_icon; - if (suggestion.ends_with(".hsp")) - return *s_hackstudio_icon; - return *s_file_icon; - } + if (index.column() == Column::Icon) + return GUI::FileIconProvider::icon_for_path(suggestion); } return {}; } @@ -82,14 +68,6 @@ private: Locator::Locator() { - if (!s_cplusplus_icon) { - s_file_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png"); - s_cplusplus_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-cplusplus.png"); - s_header_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-header.png"); - s_form_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-form.png"); - s_hackstudio_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-hackstudio.png"); - } - set_layout(); set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); set_preferred_size(0, 20);