Make the "Quick Open" dialog available via EditorInterface

This commit is contained in:
yds 2024-09-30 00:48:08 -03:00
parent e3213aaef5
commit f2f9687cea
3 changed files with 38 additions and 0 deletions

View File

@ -343,6 +343,17 @@
[/codeblock] [/codeblock]
</description> </description>
</method> </method>
<method name="popup_quick_open">
<return type="void" />
<param index="0" name="callback" type="Callable" />
<param index="1" name="base_type" type="String" default="&quot;&quot;" />
<param index="2" name="enable_multi" type="bool" default="false" />
<param index="3" name="dont_clear" type="bool" default="false" />
<param index="4" name="title" type="String" default="&quot;Quick Open&quot;" />
<description>
Pops up an editor dialog for quick selecting a resource file. The [param callback] must take a single argument of type [PackedStringArray] which will be called with a list of selected paths or empty if the dialog is canceled. If [param base_type] is provided, the dialog will only show resources that match the base type. If [param enable_multi] is [code]true[/code], multiple files can be selected. If [param dont_clear] is [code]true[/code], the previous search filter will be reused. The dialog title can be specified in [param title].
</description>
</method>
<method name="reload_scene_from_path"> <method name="reload_scene_from_path">
<return type="void" /> <return type="void" />
<param index="0" name="scene_filepath" type="String" /> <param index="0" name="scene_filepath" type="String" />

View File

@ -36,6 +36,7 @@
#include "editor/editor_main_screen.h" #include "editor/editor_main_screen.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_paths.h" #include "editor/editor_paths.h"
#include "editor/editor_quick_open.h"
#include "editor/editor_resource_preview.h" #include "editor/editor_resource_preview.h"
#include "editor/editor_settings.h" #include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h" #include "editor/editor_undo_redo_manager.h"
@ -336,6 +337,23 @@ void EditorInterface::popup_property_selector(Object *p_object, const Callable &
property_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED); property_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
} }
void EditorInterface::popup_quick_open(const Callable &p_callback, const String &p_base_type, bool p_enable_multi, bool p_dontclear, const String &p_title) {
const Callable selected_callback = callable_mp(this, &EditorInterface::_quick_open).bind(p_callback);
const Callable canceled_callback = callable_mp(this, &EditorInterface::_call_dialog_callback).bind(p_callback, PackedStringArray(), "quick open canceled");
if (!quick_open) {
quick_open = memnew(EditorQuickOpen);
get_base_control()->add_child(quick_open);
} else {
quick_open->disconnect(SNAME("quick_open"), selected_callback);
quick_open->disconnect(SNAME("canceled"), canceled_callback);
}
quick_open->connect(SNAME("quick_open"), selected_callback, CONNECT_DEFERRED);
quick_open->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
quick_open->set_title(p_title);
quick_open->popup_dialog(p_base_type, p_enable_multi, p_dontclear);
}
void EditorInterface::_node_selected(const NodePath &p_node_path, const Callable &p_callback) { void EditorInterface::_node_selected(const NodePath &p_node_path, const Callable &p_callback) {
const NodePath path = get_edited_scene_root()->get_path().rel_path_to(p_node_path); const NodePath path = get_edited_scene_root()->get_path().rel_path_to(p_node_path);
_call_dialog_callback(p_callback, path, "node selected"); _call_dialog_callback(p_callback, path, "node selected");
@ -353,6 +371,10 @@ void EditorInterface::_property_selection_canceled(const Callable &p_callback) {
_call_dialog_callback(p_callback, NodePath(), "property selection canceled"); _call_dialog_callback(p_callback, NodePath(), "property selection canceled");
} }
void EditorInterface::_quick_open(const Callable &p_callback) {
_call_dialog_callback(p_callback, quick_open->get_selected_files(), "quick open");
}
void EditorInterface::_call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context) { void EditorInterface::_call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context) {
Callable::CallError ce; Callable::CallError ce;
Variant ret; Variant ret;
@ -568,6 +590,7 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("popup_node_selector", "callback", "valid_types", "current_value"), &EditorInterface::popup_node_selector, DEFVAL(TypedArray<StringName>()), DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("popup_node_selector", "callback", "valid_types", "current_value"), &EditorInterface::popup_node_selector, DEFVAL(TypedArray<StringName>()), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("popup_property_selector", "object", "callback", "type_filter", "current_value"), &EditorInterface::popup_property_selector, DEFVAL(PackedInt32Array()), DEFVAL(String())); ClassDB::bind_method(D_METHOD("popup_property_selector", "object", "callback", "type_filter", "current_value"), &EditorInterface::popup_property_selector, DEFVAL(PackedInt32Array()), DEFVAL(String()));
ClassDB::bind_method(D_METHOD("popup_quick_open", "callback", "base_type", "enable_multi", "dont_clear", "title"), &EditorInterface::popup_quick_open, DEFVAL(String()), DEFVAL(false), DEFVAL(false), DEFVAL(TTR("Quick Open")));
// Editor docks. // Editor docks.

View File

@ -42,6 +42,7 @@ class EditorFileSystem;
class EditorInspector; class EditorInspector;
class EditorPaths; class EditorPaths;
class EditorPlugin; class EditorPlugin;
class EditorQuickOpen;
class EditorResourcePreview; class EditorResourcePreview;
class EditorSelection; class EditorSelection;
class EditorSettings; class EditorSettings;
@ -67,11 +68,13 @@ class EditorInterface : public Object {
PropertySelector *property_selector = nullptr; PropertySelector *property_selector = nullptr;
SceneTreeDialog *node_selector = nullptr; SceneTreeDialog *node_selector = nullptr;
EditorQuickOpen *quick_open = nullptr;
void _node_selected(const NodePath &p_node_paths, const Callable &p_callback); void _node_selected(const NodePath &p_node_paths, const Callable &p_callback);
void _node_selection_canceled(const Callable &p_callback); void _node_selection_canceled(const Callable &p_callback);
void _property_selected(const String &p_property_name, const Callable &p_callback); void _property_selected(const String &p_property_name, const Callable &p_callback);
void _property_selection_canceled(const Callable &p_callback); void _property_selection_canceled(const Callable &p_callback);
void _quick_open(const Callable &p_callback);
void _call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context); void _call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context);
// Editor tools. // Editor tools.
@ -138,6 +141,7 @@ public:
void popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>(), Node *p_current_value = nullptr); void popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>(), Node *p_current_value = nullptr);
// Must use Vector<int> because exposing Vector<Variant::Type> is not supported. // Must use Vector<int> because exposing Vector<Variant::Type> is not supported.
void popup_property_selector(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter = PackedInt32Array(), const String &p_current_value = String()); void popup_property_selector(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter = PackedInt32Array(), const String &p_current_value = String());
void popup_quick_open(const Callable &p_callback, const String &p_base_type = String(), bool p_enable_multi = false, bool p_dontclear = false, const String &p_title = TTR("Quick Open"));
// Editor docks. // Editor docks.