Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent dropping Resource to the same resource picker #90278

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5324,7 +5324,7 @@ bool EditorNode::is_distraction_free_mode_enabled() const {
return distraction_free->is_pressed();
}

Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
Dictionary EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
Control *drag_control = memnew(Control);
TextureRect *drag_preview = memnew(TextureRect);
Label *label = memnew(Label);
Expand Down Expand Up @@ -5364,7 +5364,7 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
return drag_data;
}

Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from) {
Dictionary EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from) {
bool has_folder = false;
bool has_file = false;
for (int i = 0; i < p_paths.size(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ class EditorNode : public Node {

bool is_exiting() const { return exiting; }

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

void add_tool_menu_item(const String &p_name, const Callable &p_callback);
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
Expand Down
11 changes: 10 additions & 1 deletion editor/editor_resource_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,13 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, HashSet<Strin
}

bool EditorResourcePicker::_is_drop_valid(const Dictionary &p_drag_data) const {
{
const ObjectID source_picker = p_drag_data.get("source_picker", ObjectID());
if (source_picker == get_instance_id()) {
return false;
}
}

if (base_type.is_empty()) {
return true;
}
Expand Down Expand Up @@ -670,7 +677,9 @@ bool EditorResourcePicker::_is_type_valid(const String &p_type_name, const HashS

Variant EditorResourcePicker::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (edited_resource.is_valid()) {
return EditorNode::get_singleton()->drag_resource(edited_resource, p_from);
Dictionary drag_data = EditorNode::get_singleton()->drag_resource(edited_resource, p_from);
drag_data["source_picker"] = get_instance_id();
return drag_data;
}

return Variant();
Expand Down
Loading