Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable QuickOpen to see scripted resources #62417

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions editor/editor_quick_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions editor/editor_quick_open.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down