summaryrefslogtreecommitdiffstats
path: root/editor/editor_interface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_interface.cpp')
-rw-r--r--editor/editor_interface.cpp94
1 files changed, 58 insertions, 36 deletions
diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp
index 4bb531ce9e..8873bb2e76 100644
--- a/editor/editor_interface.cpp
+++ b/editor/editor_interface.cpp
@@ -45,6 +45,7 @@
#include "editor/gui/editor_quick_open_dialog.h"
#include "editor/gui/editor_run_bar.h"
#include "editor/gui/editor_scene_tabs.h"
+#include "editor/gui/editor_toaster.h"
#include "editor/gui/scene_tree_editor.h"
#include "editor/inspector_dock.h"
#include "editor/plugins/node_3d_editor_plugin.h"
@@ -91,6 +92,10 @@ Ref<EditorSettings> EditorInterface::get_editor_settings() const {
return EditorSettings::get_singleton();
}
+EditorToaster *EditorInterface::get_editor_toaster() const {
+ return EditorToaster::get_singleton();
+}
+
EditorUndoRedoManager *EditorInterface::get_editor_undo_redo() const {
return EditorUndoRedoManager::get_singleton();
}
@@ -282,14 +287,10 @@ void EditorInterface::set_current_feature_profile(const String &p_profile_name)
// Editor dialogs.
void EditorInterface::popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types, Node *p_current_value) {
- // TODO: Should reuse dialog instance instead of creating a fresh one, but need to rework set_valid_types first.
- if (node_selector) {
- node_selector->disconnect(SNAME("selected"), callable_mp(this, &EditorInterface::_node_selected).bind(p_callback));
- node_selector->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_node_selection_canceled).bind(p_callback));
- get_base_control()->remove_child(node_selector);
- node_selector->queue_free();
+ if (!node_selector) {
+ node_selector = memnew(SceneTreeDialog);
+ get_base_control()->add_child(node_selector);
}
- node_selector = memnew(SceneTreeDialog);
Vector<StringName> valid_types;
int length = p_valid_types.size();
@@ -298,27 +299,18 @@ void EditorInterface::popup_node_selector(const Callable &p_callback, const Type
valid_types.write[i] = p_valid_types[i];
}
node_selector->set_valid_types(valid_types);
-
- get_base_control()->add_child(node_selector);
-
node_selector->popup_scenetree_dialog(p_current_value);
- const Callable selected_callback = callable_mp(this, &EditorInterface::_node_selected).bind(p_callback);
- node_selector->connect(SNAME("selected"), selected_callback, CONNECT_DEFERRED);
-
- const Callable canceled_callback = callable_mp(this, &EditorInterface::_node_selection_canceled).bind(p_callback);
- node_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
+ const Callable callback = callable_mp(this, &EditorInterface::_node_selected);
+ node_selector->connect(SNAME("selected"), callback.bind(p_callback), CONNECT_DEFERRED);
+ node_selector->connect(SNAME("canceled"), callback.bind(NodePath(), p_callback), CONNECT_DEFERRED);
}
void EditorInterface::popup_property_selector(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter, const String &p_current_value) {
- // TODO: Should reuse dialog instance instead of creating a fresh one, but need to rework set_type_filter first.
- if (property_selector) {
- property_selector->disconnect(SNAME("selected"), callable_mp(this, &EditorInterface::_property_selected).bind(p_callback));
- property_selector->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_property_selection_canceled).bind(p_callback));
- get_base_control()->remove_child(property_selector);
- property_selector->queue_free();
+ if (!property_selector) {
+ property_selector = memnew(PropertySelector);
+ get_base_control()->add_child(property_selector);
}
- property_selector = memnew(PropertySelector);
Vector<Variant::Type> type_filter;
int length = p_type_filter.size();
@@ -327,16 +319,24 @@ void EditorInterface::popup_property_selector(Object *p_object, const Callable &
type_filter.write[i] = (Variant::Type)p_type_filter[i];
}
property_selector->set_type_filter(type_filter);
+ property_selector->select_property_from_instance(p_object, p_current_value);
- get_base_control()->add_child(property_selector);
+ const Callable callback = callable_mp(this, &EditorInterface::_property_selected);
+ property_selector->connect(SNAME("selected"), callback.bind(p_callback), CONNECT_DEFERRED);
+ property_selector->connect(SNAME("canceled"), callback.bind(String(), p_callback), CONNECT_DEFERRED);
+}
- property_selector->select_property_from_instance(p_object, p_current_value);
+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);
+ }
- const Callable selected_callback = callable_mp(this, &EditorInterface::_property_selected).bind(p_callback);
- property_selector->connect(SNAME("selected"), selected_callback, CONNECT_DEFERRED);
+ method_selector->select_method_from_instance(p_object, p_current_value);
- const Callable canceled_callback = callable_mp(this, &EditorInterface::_property_selection_canceled).bind(p_callback);
- property_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
+ 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) {
@@ -358,20 +358,40 @@ void EditorInterface::popup_quick_open(const Callable &p_callback, const TypedAr
}
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);
- _call_dialog_callback(p_callback, path, "node selected");
-}
+ const Callable callback = callable_mp(this, &EditorInterface::_node_selected);
+ node_selector->disconnect(SNAME("selected"), callback);
+ node_selector->disconnect(SNAME("canceled"), callback);
-void EditorInterface::_node_selection_canceled(const Callable &p_callback) {
- _call_dialog_callback(p_callback, NodePath(), "node selection canceled");
+ if (p_node_path.is_empty()) {
+ _call_dialog_callback(p_callback, NodePath(), "node selection canceled");
+ } else {
+ const NodePath path = get_edited_scene_root()->get_path().rel_path_to(p_node_path);
+ _call_dialog_callback(p_callback, path, "node selected");
+ }
}
void EditorInterface::_property_selected(const String &p_property_name, const Callable &p_callback) {
- _call_dialog_callback(p_callback, NodePath(p_property_name).get_as_property_path(), "property selected");
+ const Callable callback = callable_mp(this, &EditorInterface::_property_selected);
+ property_selector->disconnect(SNAME("selected"), callback);
+ property_selector->disconnect(SNAME("canceled"), callback);
+
+ if (p_property_name.is_empty()) {
+ _call_dialog_callback(p_callback, NodePath(p_property_name).get_as_property_path(), "property selection canceled");
+ } else {
+ _call_dialog_callback(p_callback, NodePath(p_property_name).get_as_property_path(), "property selected");
+ }
}
-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) {
@@ -558,6 +578,7 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_resource_previewer"), &EditorInterface::get_resource_previewer);
ClassDB::bind_method(D_METHOD("get_selection"), &EditorInterface::get_selection);
ClassDB::bind_method(D_METHOD("get_editor_settings"), &EditorInterface::get_editor_settings);
+ ClassDB::bind_method(D_METHOD("get_editor_toaster"), &EditorInterface::get_editor_toaster);
ClassDB::bind_method(D_METHOD("get_editor_undo_redo"), &EditorInterface::get_editor_undo_redo);
ClassDB::bind_method(D_METHOD("make_mesh_previews", "meshes", "preview_size"), &EditorInterface::_make_mesh_previews);
@@ -595,6 +616,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.