Merge pull request #37228 from rcorre/rcorre/better-load-dialog
Use QuickOpen to load resources in the inspector.
This commit is contained in:
commit
4d9b5852f4
|
@ -135,6 +135,10 @@ void EditorResourcePicker::_file_selected(const String &p_path) {
|
||||||
_update_resource();
|
_update_resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorResourcePicker::_file_quick_selected() {
|
||||||
|
_file_selected(quick_open->get_selected());
|
||||||
|
}
|
||||||
|
|
||||||
void EditorResourcePicker::_update_menu() {
|
void EditorResourcePicker::_update_menu() {
|
||||||
_update_menu_items();
|
_update_menu_items();
|
||||||
|
|
||||||
|
@ -153,7 +157,10 @@ void EditorResourcePicker::_update_menu_items() {
|
||||||
// Add options for creating specific subtypes of the base resource type.
|
// Add options for creating specific subtypes of the base resource type.
|
||||||
set_create_options(edit_menu);
|
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_theme_icon(SNAME("Load"), SNAME("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_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Load"), OBJ_MENU_LOAD);
|
edit_menu->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Load"), OBJ_MENU_LOAD);
|
||||||
|
|
||||||
// Add options for changing existing value of the resource.
|
// Add options for changing existing value of the resource.
|
||||||
|
@ -246,6 +253,17 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
|
||||||
file_dialog->popup_file_dialog();
|
file_dialog->popup_file_dialog();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case OBJ_MENU_QUICKLOAD: {
|
||||||
|
if (!quick_open) {
|
||||||
|
quick_open = memnew(EditorQuickOpen);
|
||||||
|
add_child(quick_open);
|
||||||
|
quick_open->connect("quick_open", callable_mp(this, &EditorResourcePicker::_file_quick_selected));
|
||||||
|
}
|
||||||
|
|
||||||
|
quick_open->popup_dialog(base_type);
|
||||||
|
quick_open->set_title(TTR("Resource"));
|
||||||
|
} break;
|
||||||
|
|
||||||
case OBJ_MENU_EDIT: {
|
case OBJ_MENU_EDIT: {
|
||||||
if (edited_resource.is_valid()) {
|
if (edited_resource.is_valid()) {
|
||||||
emit_signal(SNAME("resource_selected"), edited_resource);
|
emit_signal(SNAME("resource_selected"), edited_resource);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define EDITOR_RESOURCE_PICKER_H
|
#define EDITOR_RESOURCE_PICKER_H
|
||||||
|
|
||||||
#include "editor_file_dialog.h"
|
#include "editor_file_dialog.h"
|
||||||
|
#include "quick_open.h"
|
||||||
#include "scene/gui/box_container.h"
|
#include "scene/gui/box_container.h"
|
||||||
#include "scene/gui/button.h"
|
#include "scene/gui/button.h"
|
||||||
#include "scene/gui/popup_menu.h"
|
#include "scene/gui/popup_menu.h"
|
||||||
|
@ -54,9 +55,11 @@ class EditorResourcePicker : public HBoxContainer {
|
||||||
TextureRect *preview_rect;
|
TextureRect *preview_rect;
|
||||||
Button *edit_button;
|
Button *edit_button;
|
||||||
EditorFileDialog *file_dialog = nullptr;
|
EditorFileDialog *file_dialog = nullptr;
|
||||||
|
EditorQuickOpen *quick_open = nullptr;
|
||||||
|
|
||||||
enum MenuOption {
|
enum MenuOption {
|
||||||
OBJ_MENU_LOAD,
|
OBJ_MENU_LOAD,
|
||||||
|
OBJ_MENU_QUICKLOAD,
|
||||||
OBJ_MENU_EDIT,
|
OBJ_MENU_EDIT,
|
||||||
OBJ_MENU_CLEAR,
|
OBJ_MENU_CLEAR,
|
||||||
OBJ_MENU_MAKE_UNIQUE,
|
OBJ_MENU_MAKE_UNIQUE,
|
||||||
|
@ -75,6 +78,7 @@ class EditorResourcePicker : public HBoxContainer {
|
||||||
void _update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj);
|
void _update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj);
|
||||||
|
|
||||||
void _resource_selected();
|
void _resource_selected();
|
||||||
|
void _file_quick_selected();
|
||||||
void _file_selected(const String &p_path);
|
void _file_selected(const String &p_path);
|
||||||
|
|
||||||
void _update_menu();
|
void _update_menu();
|
||||||
|
|
Loading…
Reference in New Issue