diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 5280a8e7d3f5..f32370740773 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2727,6 +2727,29 @@ void EditorPropertyNodePath::_node_clear() { update_property(); } +bool EditorPropertyNodePath::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { + return !is_read_only() && is_drop_valid(p_data); +} + +void EditorPropertyNodePath::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { + ERR_FAIL_COND(!is_drop_valid(p_data)); + Dictionary data = p_data; + Array nodes = data["nodes"]; + Node *node = get_tree()->get_edited_scene_root()->get_node(nodes[0]); + + if (node) { + _node_selected(node->get_path()); + } +} + +bool EditorPropertyNodePath::is_drop_valid(const Dictionary &p_drag_data) const { + if (p_drag_data["type"] != "nodes") { + return false; + } + Array nodes = p_drag_data["nodes"]; + return nodes.size() == 1; +} + void EditorPropertyNodePath::update_property() { NodePath p = get_edited_object()->get(get_edited_property()); @@ -2781,6 +2804,8 @@ void EditorPropertyNodePath::_notification(int p_what) { } void EditorPropertyNodePath::_bind_methods() { + ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::drop_data_fw); } EditorPropertyNodePath::EditorPropertyNodePath() { @@ -2791,6 +2816,7 @@ EditorPropertyNodePath::EditorPropertyNodePath() { assign->set_h_size_flags(SIZE_EXPAND_FILL); assign->set_clip_text(true); assign->connect("pressed", callable_mp(this, &EditorPropertyNodePath::_node_assign)); + assign->set_drag_forwarding(this); hbc->add_child(assign); clear = memnew(Button); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 42ef650adcfa..0b98e4c7c96b 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -625,6 +625,10 @@ class EditorPropertyNodePath : public EditorProperty { void _node_assign(); void _node_clear(); + bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; + void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + bool is_drop_valid(const Dictionary &p_drag_data) const; + protected: virtual void _set_read_only(bool p_read_only) override; static void _bind_methods(); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index b36275322a24..5cb02782ad8f 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -233,7 +233,7 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector &p_files, N } editor_data->get_undo_redo().commit_action(); - editor->push_item(instances[instances.size() - 1]); + _push_item(instances[instances.size() - 1]); for (int i = 0; i < instances.size(); i++) { emit_signal(SNAME("node_created"), instances[i]); } @@ -750,7 +750,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_data->get_undo_redo().commit_action(); if (dupsingle) { - editor->push_item(dupsingle); + _push_item(dupsingle); } } break; case TOOL_REPARENT: { @@ -854,7 +854,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { mne->add_node(root->get_path_to(E.key)); } - EditorNode::get_singleton()->push_item(mne.ptr()); + _push_item(mne.ptr()); } break; @@ -1164,7 +1164,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Object *obj = ObjectDB::get_instance(subresources[idx]); ERR_FAIL_COND(!obj); - editor->push_item(obj); + _push_item(obj); } } } @@ -1368,6 +1368,12 @@ void SceneTreeDock::_script_open_request(const Ref