Skip to content

Commit 92afd2c

Browse files
committed
Merge pull request godotengine#90278 from KoBeWi/self_dropping_resources
Prevent dropping Resource to the same resource picker
2 parents dd9aacd + b9c78ba commit 92afd2c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

editor/editor_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5324,7 +5324,7 @@ bool EditorNode::is_distraction_free_mode_enabled() const {
53245324
return distraction_free->is_pressed();
53255325
}
53265326

5327-
Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
5327+
Dictionary EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
53285328
Control *drag_control = memnew(Control);
53295329
TextureRect *drag_preview = memnew(TextureRect);
53305330
Label *label = memnew(Label);
@@ -5364,7 +5364,7 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
53645364
return drag_data;
53655365
}
53665366

5367-
Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from) {
5367+
Dictionary EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from) {
53685368
bool has_folder = false;
53695369
bool has_file = false;
53705370
for (int i = 0; i < p_paths.size(); i++) {

editor/editor_node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ class EditorNode : public Node {
870870

871871
bool is_exiting() const { return exiting; }
872872

873-
Variant drag_resource(const Ref<Resource> &p_res, Control *p_from);
874-
Variant drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
873+
Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
874+
Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
875875

876876
void add_tool_menu_item(const String &p_name, const Callable &p_callback);
877877
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);

editor/editor_resource_picker.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,13 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, HashSet<Strin
615615
}
616616

617617
bool EditorResourcePicker::_is_drop_valid(const Dictionary &p_drag_data) const {
618+
{
619+
const ObjectID source_picker = p_drag_data.get("source_picker", ObjectID());
620+
if (source_picker == get_instance_id()) {
621+
return false;
622+
}
623+
}
624+
618625
if (base_type.is_empty()) {
619626
return true;
620627
}
@@ -670,7 +677,9 @@ bool EditorResourcePicker::_is_type_valid(const String &p_type_name, const HashS
670677

671678
Variant EditorResourcePicker::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
672679
if (edited_resource.is_valid()) {
673-
return EditorNode::get_singleton()->drag_resource(edited_resource, p_from);
680+
Dictionary drag_data = EditorNode::get_singleton()->drag_resource(edited_resource, p_from);
681+
drag_data["source_picker"] = get_instance_id();
682+
return drag_data;
674683
}
675684

676685
return Variant();

0 commit comments

Comments
 (0)