diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-18 10:53:53 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-18 10:53:53 +0200 |
commit | 7a0a3fea94e9fc70736ef93f2a024e023d53d6ed (patch) | |
tree | 2d1118807a86800da2b499fc5c5ed28db88d65c6 | |
parent | 469eb3dfd7ae9b3899cc67821f1dbb073fa26348 (diff) | |
parent | cc5a736c0b92eb66d754d4a423921129e78524cb (diff) |
Merge pull request #62417 from willnationsdev/gdres-quickopen
Enable QuickOpen to see scripted resources
-rw-r--r-- | editor/editor_quick_open.cpp | 21 | ||||
-rw-r--r-- | editor/editor_quick_open.h | 1 |
2 files changed, 18 insertions, 4 deletions
diff --git a/editor/editor_quick_open.cpp b/editor/editor_quick_open.cpp index 539cb7cd8a..b4ec3bca15 100644 --- a/editor/editor_quick_open.cpp +++ b/editor/editor_quick_open.cpp @@ -31,6 +31,7 @@ #include "editor_quick_open.h" #include "core/os/keyboard.h" +#include "editor/editor_node.h" void EditorQuickOpen::popup_dialog(const StringName &p_base, bool p_enable_multi, bool p_dontclear) { base_type = p_base; @@ -57,17 +58,29 @@ void EditorQuickOpen::_build_search_cache(EditorFileSystemDirectory *p_efsd) { Vector<String> base_types = String(base_type).split(String(",")); for (int i = 0; i < p_efsd->get_file_count(); i++) { - String file_type = p_efsd->get_file_type(i); + String file = p_efsd->get_file_path(i); + String engine_type = p_efsd->get_file_type(i); + // TODO: Fix lack of caching for resource's script's global class name (if applicable). + String script_type; + if (_load_resources) { + Ref<Resource> res = ResourceLoader::load(file); + if (res.is_valid()) { + Ref<Script> scr = res->get_script(); + if (scr.is_valid()) { + script_type = scr->get_language()->get_global_class_name(file); + } + } + } + String actual_type = script_type.is_empty() ? engine_type : script_type; // Iterate all possible base types. for (String &parent_type : base_types) { - if (ClassDB::is_parent_class(file_type, parent_type)) { - String file = p_efsd->get_file_path(i); + if (ClassDB::is_parent_class(engine_type, parent_type) || EditorNode::get_editor_data().script_class_is_parent(script_type, parent_type)) { files.push_back(file.substr(6, file.length())); // Store refs to used icons. String ext = file.get_extension(); if (!icons.has(ext)) { - icons.insert(ext, get_theme_icon((has_theme_icon(file_type, SNAME("EditorIcons")) ? file_type : String("Object")), SNAME("EditorIcons"))); + icons.insert(ext, get_theme_icon((has_theme_icon(actual_type, SNAME("EditorIcons")) ? actual_type : String("Object")), SNAME("EditorIcons"))); } // Stop testing base types as soon as we got a match. diff --git a/editor/editor_quick_open.h b/editor/editor_quick_open.h index e41a8c7e75..86a419b538 100644 --- a/editor/editor_quick_open.h +++ b/editor/editor_quick_open.h @@ -43,6 +43,7 @@ class EditorQuickOpen : public ConfirmationDialog { Tree *search_options = nullptr; StringName base_type; bool allow_multi_select = false; + bool _load_resources = true; Vector<String> files; OAHashMap<String, Ref<Texture2D>> icons; |