Merge pull request #62417 from willnationsdev/gdres-quickopen

Enable QuickOpen to see scripted resources
This commit is contained in:
Rémi Verschelde 2022-09-18 10:53:53 +02:00
commit 7a0a3fea94
2 changed files with 18 additions and 4 deletions

View File

@ -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.

View File

@ -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;