From 236cec06330f321e92867b30abbd168d7ea0b3aa Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Fri, 17 Feb 2023 22:37:38 +0100 Subject: Add a custom icon for the `project.godot` file in the EditorFileDialog --- editor/editor_file_dialog.cpp | 12 ++++++++++-- editor/editor_file_dialog.h | 2 +- editor/icons/GodotFile.svg | 1 + editor/icons/GodotMonochrome.svg | 1 + editor/icons/editor_icons_builders.py | 2 ++ editor/project_manager.cpp | 18 ++++++++++++++---- editor/project_manager.h | 1 + scene/gui/file_dialog.cpp | 1 - scene/gui/file_dialog.h | 1 - 9 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 editor/icons/GodotFile.svg create mode 100644 editor/icons/GodotMonochrome.svg diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 80d1e9dcd7..3de4379c5d 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -50,7 +50,7 @@ #include "servers/display_server.h" EditorFileDialog::GetIconFunc EditorFileDialog::get_icon_func = nullptr; -EditorFileDialog::GetIconFunc EditorFileDialog::get_large_icon_func = nullptr; +EditorFileDialog::GetIconFunc EditorFileDialog::get_thumbnail_func = nullptr; EditorFileDialog::RegisterFunc EditorFileDialog::register_func = nullptr; EditorFileDialog::RegisterFunc EditorFileDialog::unregister_func = nullptr; @@ -902,7 +902,15 @@ void EditorFileDialog::update_file_list() { if (get_icon_func) { Ref icon = get_icon_func(cdir.path_join(files.front()->get())); if (display_mode == DISPLAY_THUMBNAILS) { - item_list->set_item_icon(-1, file_thumbnail); + Ref thumbnail; + if (get_thumbnail_func) { + thumbnail = get_thumbnail_func(cdir.path_join(files.front()->get())); + } + if (thumbnail.is_null()) { + thumbnail = file_thumbnail; + } + + item_list->set_item_icon(-1, thumbnail); item_list->set_item_tag_icon(-1, icon); } else { item_list->set_item_icon(-1, icon); diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h index 021f2e6d4c..1944cacf70 100644 --- a/editor/editor_file_dialog.h +++ b/editor/editor_file_dialog.h @@ -68,7 +68,7 @@ public: typedef void (*RegisterFunc)(EditorFileDialog *); static GetIconFunc get_icon_func; - static GetIconFunc get_large_icon_func; + static GetIconFunc get_thumbnail_func; static RegisterFunc register_func; static RegisterFunc unregister_func; diff --git a/editor/icons/GodotFile.svg b/editor/icons/GodotFile.svg new file mode 100644 index 0000000000..3989c842dc --- /dev/null +++ b/editor/icons/GodotFile.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GodotMonochrome.svg b/editor/icons/GodotMonochrome.svg new file mode 100644 index 0000000000..d0991e7343 --- /dev/null +++ b/editor/icons/GodotMonochrome.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/editor_icons_builders.py b/editor/icons/editor_icons_builders.py index fb9a57c429..2b621071ce 100644 --- a/editor/icons/editor_icons_builders.py +++ b/editor/icons/editor_icons_builders.py @@ -58,6 +58,8 @@ def make_editor_icons_action(target, source, env): thumb_medium_indices.append(str(index)) if icon_name.endswith("BigThumb"): # don't know a better way to handle this thumb_big_indices.append(str(index)) + if icon_name.endswith("GodotFile"): # don't know a better way to handle this + thumb_big_indices.append(str(index)) s.write('\t"{0}"'.format(icon_name)) diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index dc019d8e7c..1d510703b0 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -2013,16 +2013,25 @@ void ProjectManager::_notification(int p_what) { } Ref ProjectManager::_file_dialog_get_icon(const String &p_path) { - return singleton->icon_type_cache["ObjectHR"]; + if (p_path.get_extension().to_lower() == "godot") { + return singleton->icon_type_cache["GodotMonochrome"]; + } + + return singleton->icon_type_cache["Object"]; +} + +Ref ProjectManager::_file_dialog_get_thumbnail(const String &p_path) { + if (p_path.get_extension().to_lower() == "godot") { + return singleton->icon_type_cache["GodotFile"]; + } + + return Ref(); } void ProjectManager::_build_icon_type_cache(Ref p_theme) { List tl; p_theme->get_icon_list(SNAME("EditorIcons"), &tl); for (List::Element *E = tl.front(); E; E = E->next()) { - if (!ClassDB::class_exists(E->get())) { - continue; - } icon_type_cache[E->get()] = p_theme->get_icon(E->get(), SNAME("EditorIcons")); } } @@ -2651,6 +2660,7 @@ ProjectManager::ProjectManager() { break; } EditorFileDialog::get_icon_func = &ProjectManager::_file_dialog_get_icon; + EditorFileDialog::get_thumbnail_func = &ProjectManager::_file_dialog_get_thumbnail; } // TRANSLATORS: This refers to the application where users manage their Godot projects. diff --git a/editor/project_manager.h b/editor/project_manager.h index d96f5e2641..60d9c1d45b 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -144,6 +144,7 @@ class ProjectManager : public Control { void _on_search_term_changed(const String &p_term); static Ref _file_dialog_get_icon(const String &p_path); + static Ref _file_dialog_get_thumbnail(const String &p_path); protected: void _notification(int p_what); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index ee065cccbf..02abddaa43 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -35,7 +35,6 @@ #include "scene/gui/label.h" FileDialog::GetIconFunc FileDialog::get_icon_func = nullptr; -FileDialog::GetIconFunc FileDialog::get_large_icon_func = nullptr; FileDialog::RegisterFunc FileDialog::register_func = nullptr; FileDialog::RegisterFunc FileDialog::unregister_func = nullptr; diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index d85cdcac90..7f80caf01d 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -60,7 +60,6 @@ public: typedef void (*RegisterFunc)(FileDialog *); static GetIconFunc get_icon_func; - static GetIconFunc get_large_icon_func; static RegisterFunc register_func; static RegisterFunc unregister_func; -- cgit v1.2.3