mirror of
https://github.com/godotengine/godot.git
synced 2024-11-24 13:12:42 +00:00
Make the method selector dialog available via EditorInterface
This commit is contained in:
parent
b00e1cbf74
commit
9db8b0e333
@ -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="""" />
|
||||
<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" />
|
||||
|
@ -337,6 +337,19 @@ 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 callback = callable_mp(this, &EditorInterface::_method_selected);
|
||||
method_selector->connect(SNAME("selected"), callback.bind(p_callback), CONNECT_DEFERRED);
|
||||
method_selector->connect(SNAME("canceled"), callback.bind(String(), p_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;
|
||||
@ -372,6 +385,18 @@ 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) {
|
||||
const Callable callback = callable_mp(this, &EditorInterface::_method_selected);
|
||||
method_selector->disconnect(SNAME("selected"), callback);
|
||||
method_selector->disconnect(SNAME("canceled"), callback);
|
||||
|
||||
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));
|
||||
@ -593,6 +618,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.
|
||||
|
@ -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);
|
||||
|
||||
@ -139,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);
|
||||
// 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.
|
||||
|
Loading…
Reference in New Issue
Block a user