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

Make the method selector dialog available via EditorInterface #98859

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions doc/classes/EditorInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@
See also [method Window.set_unparent_when_invisible].
</description>
</method>
<method name="popup_method_selector">
<return type="void" />
<param index="0" name="object" type="Object" />
<param index="1" name="callback" type="Callable" />
<param index="2" name="current_value" type="String" default="&quot;&quot;" />
<description>
Pops up an editor dialog for selecting a method from [param object]. The [param callback] must take a single argument of type [String] which will contain the name of the selected method or be empty if the dialog is canceled. If [param current_value] is provided, the method will be selected automatically in the method list, if it exists.
</description>
</method>
<method name="popup_node_selector">
<return type="void" />
<param index="0" name="callback" type="Callable" />
Expand Down
27 changes: 27 additions & 0 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ void EditorInterface::popup_property_selector(Object *p_object, const Callable &
property_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
}

void EditorInterface::popup_method_selector(Object *p_object, const Callable &p_callback, const String &p_current_value) {
if (!method_selector) {
method_selector = memnew(PropertySelector);
get_base_control()->add_child(method_selector);
}

method_selector->select_method_from_instance(p_object, p_current_value);

const Callable selected_callback = callable_mp(this, &EditorInterface::_method_selected).bind(p_callback);
method_selector->connect(SNAME("selected"), selected_callback, CONNECT_DEFERRED);

const Callable canceled_callback = callable_mp(this, &EditorInterface::_method_selected).bind(String(), p_callback);
method_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
}

void EditorInterface::popup_quick_open(const Callable &p_callback, const TypedArray<StringName> &p_base_types) {
StringName required_type = SNAME("Resource");
Vector<StringName> base_types;
Expand Down Expand Up @@ -372,6 +387,17 @@ void EditorInterface::_property_selection_canceled(const Callable &p_callback) {
_call_dialog_callback(p_callback, NodePath(), "property selection canceled");
}

void EditorInterface::_method_selected(const String &p_method_name, const Callable &p_callback) {
method_selector->disconnect(SNAME("selected"), callable_mp(this, &EditorInterface::_method_selected));
method_selector->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_method_selected));

if (p_method_name.is_empty()) {
_call_dialog_callback(p_callback, p_method_name, "method selection canceled");
} else {
_call_dialog_callback(p_callback, p_method_name, "method selected");
}
}

void EditorInterface::_quick_open(const String &p_file_path, const Callable &p_callback) {
EditorQuickOpenDialog *quick_open = EditorNode::get_singleton()->get_quick_open_dialog();
quick_open->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_quick_open));
Expand Down Expand Up @@ -593,6 +619,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_property_selector", "object", "callback", "type_filter", "current_value"), &EditorInterface::popup_property_selector, DEFVAL(PackedInt32Array()), DEFVAL(String()));
ClassDB::bind_method(D_METHOD("popup_method_selector", "object", "callback", "current_value"), &EditorInterface::popup_method_selector, DEFVAL(String()));
ClassDB::bind_method(D_METHOD("popup_quick_open", "callback", "base_types"), &EditorInterface::popup_quick_open, DEFVAL(TypedArray<StringName>()));

// Editor docks.
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ class EditorInterface : public Object {
// Editor dialogs.

PropertySelector *property_selector = nullptr;
PropertySelector *method_selector = nullptr;
SceneTreeDialog *node_selector = nullptr;

void _node_selected(const NodePath &p_node_paths, 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_selection_canceled(const Callable &p_callback);
void _method_selected(const String &p_property_name, const Callable &p_callback);
void _quick_open(const String &p_file_path, const Callable &p_callback);
void _call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context);

Expand Down Expand Up @@ -139,6 +141,7 @@ class EditorInterface : public Object {
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.
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_method_selector(Object *p_object, const Callable &p_callback, const String &p_current_value = String());
void popup_quick_open(const Callable &p_callback, const TypedArray<StringName> &p_base_types = TypedArray<StringName>());

// Editor docks.
Expand Down
Loading