From ae38c672f1454df1f4f21694f21e2a6edf74e815 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 22 Mar 2020 09:31:46 -0400 Subject: [PATCH] Add QuickLoad option to resource picker. When clicking on a resource field in the inspector dock, you now have the "Quick Load" option in addition to "Load". This opens a QuickOpen dialog allowing the user to type in a phrase to quickly locate the desired resource (similar to "Quick Open Scene"). In my experience, this is much faster than clicking through the File Dialog. Relates to godotengine/godot-proposals#346. (cherry picked from commit 470b94fe22b83fb97bb5132a1e4855cd196c956d) --- editor/editor_resource_picker.cpp | 21 ++++++++++++++++++++- editor/editor_resource_picker.h | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 775391885ea..4d316b45aed 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -137,6 +137,10 @@ void EditorResourcePicker::_file_selected(const String &p_path) { _update_resource(); } +void EditorResourcePicker::_file_quick_selected() { + _file_selected(quick_open->get_selected()); +} + void EditorResourcePicker::_update_menu() { _update_menu_items(); @@ -154,7 +158,10 @@ void EditorResourcePicker::_update_menu_items() { // Add options for creating specific subtypes of the base resource type. set_create_options(edit_menu); - // Add an option to load a resource from a file. + // Add an option to load a resource from a file using the QuickOpen dialog. + edit_menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Quick Load"), OBJ_MENU_QUICKLOAD); + + // Add an option to load a resource from a file using the regular file dialog. edit_menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Load"), OBJ_MENU_LOAD); // Add options for changing existing value of the resource. @@ -247,6 +254,17 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { file_dialog->popup_centered_ratio(); } break; + case OBJ_MENU_QUICKLOAD: { + if (!quick_open) { + quick_open = memnew(EditorQuickOpen); + add_child(quick_open); + quick_open->connect("quick_open", this, "_file_quick_selected"); + } + + quick_open->popup_dialog(base_type); + quick_open->set_title(TTR("Resource")); + } break; + case OBJ_MENU_EDIT: { if (edited_resource.is_valid()) { emit_signal("resource_selected", edited_resource); @@ -644,6 +662,7 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_ void EditorResourcePicker::_bind_methods() { // Internal binds. ClassDB::bind_method(D_METHOD("_file_selected"), &EditorResourcePicker::_file_selected); + ClassDB::bind_method(D_METHOD("_file_quick_selected"), &EditorResourcePicker::_file_quick_selected); ClassDB::bind_method(D_METHOD("_resource_selected"), &EditorResourcePicker::_resource_selected); ClassDB::bind_method(D_METHOD("_button_draw"), &EditorResourcePicker::_button_draw); ClassDB::bind_method(D_METHOD("_button_input"), &EditorResourcePicker::_button_input); diff --git a/editor/editor_resource_picker.h b/editor/editor_resource_picker.h index b39d6599986..066dbeeb4ab 100644 --- a/editor/editor_resource_picker.h +++ b/editor/editor_resource_picker.h @@ -32,6 +32,7 @@ #define EDITOR_RESOURCE_PICKER_H #include "editor_file_dialog.h" +#include "quick_open.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/popup_menu.h" @@ -54,9 +55,11 @@ class EditorResourcePicker : public HBoxContainer { TextureRect *preview_rect; Button *edit_button; EditorFileDialog *file_dialog = nullptr; + EditorQuickOpen *quick_open = nullptr; enum MenuOption { OBJ_MENU_LOAD, + OBJ_MENU_QUICKLOAD, OBJ_MENU_EDIT, OBJ_MENU_CLEAR, OBJ_MENU_MAKE_UNIQUE, @@ -75,6 +78,7 @@ class EditorResourcePicker : public HBoxContainer { void _update_resource_preview(const String &p_path, const Ref &p_preview, const Ref &p_small_preview, ObjectID p_obj); void _resource_selected(); + void _file_quick_selected(); void _file_selected(const String &p_path); void _update_menu();