Skip to content

Commit fa65582

Browse files
committed
Allow dragging resources (not just files) onto array property editor
The most common scenario is dragging a file from the filesystem dock, which drags it as type "file", not "resource". This already worked. This change also makes it possible to drag a resource from another property editor.
1 parent 909d236 commit fa65582

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

editor/editor_properties_array_dict.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,28 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
594594
return true;
595595
}
596596

597+
if (drop_type == "resource") {
598+
Ref<Resource> res = drag_data["resource"];
599+
if (res.is_null()) {
600+
return false;
601+
}
602+
603+
String res_type = res->get_class();
604+
StringName script_class;
605+
if (res->get_script()) {
606+
script_class = EditorNode::get_singleton()->get_object_custom_type_name(res->get_script());
607+
}
608+
609+
for (String at : allowed_type.split(",")) {
610+
at = at.strip_edges();
611+
if (ClassDB::is_parent_class(res_type, at) || EditorNode::get_editor_data().script_class_is_parent(script_class, at)) {
612+
return true;
613+
}
614+
}
615+
616+
return false;
617+
}
618+
597619
if (drop_type == "nodes") {
598620
Array node_paths = drag_data["nodes"];
599621

@@ -683,6 +705,16 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d
683705
emit_changed(get_edited_property(), array);
684706
}
685707

708+
if (drop_type == "resource") {
709+
Ref<Resource> res = drag_data["resource"];
710+
711+
if (res.is_valid()) {
712+
array.call("push_back", res);
713+
714+
emit_changed(get_edited_property(), array);
715+
}
716+
}
717+
686718
if (drop_type == "nodes") {
687719
Array node_paths = drag_data["nodes"];
688720
Node *base_node = get_base_node();

0 commit comments

Comments
 (0)