Fix: Linked/liboverride objects can get their materials assignments modified by drag and drop
Changes would be lost (or worse things can happen, see below), so this is now prevented by polishing the polls for these operations. Behavior of Materials in override objects was considered shaky as well (lost on reload, no undo or crash on undo, see #127605, #127606, #101552 in general) , so conclusion was to prevent this on linked as well as liboverride objects. Pull Request: https://projects.blender.org/blender/blender/pulls/129064
This commit is contained in:
committed by
Philipp Oeser
parent
5e5c387159
commit
58248c34cb
@@ -90,7 +90,18 @@ static void ui_drop_name_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
|
||||
static bool ui_drop_material_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
|
||||
{
|
||||
PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
|
||||
return WM_drag_is_ID_type(drag, ID_MA) && !RNA_pointer_is_null(&mat_slot);
|
||||
if (RNA_pointer_is_null(&mat_slot)) {
|
||||
return false;
|
||||
}
|
||||
PointerRNA ob_ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
|
||||
if (RNA_pointer_is_null(&ob_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object *ob = static_cast<Object *>(ob_ptr.data);
|
||||
|
||||
return WM_drag_is_ID_type(drag, ID_MA) && ID_IS_EDITABLE(&ob->id) &&
|
||||
!ID_IS_OVERRIDE_LIBRARY(&ob->id);
|
||||
}
|
||||
|
||||
static void ui_drop_material_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
|
||||
|
||||
@@ -626,7 +626,9 @@ static bool material_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
||||
{
|
||||
/* Ensure item under cursor is valid drop target */
|
||||
Material *ma = (Material *)WM_drag_get_local_ID(drag, ID_MA);
|
||||
return (ma && (outliner_ID_drop_find(C, event, ID_OB) != nullptr));
|
||||
Object *ob = reinterpret_cast<Object *>(outliner_ID_drop_find(C, event, ID_OB));
|
||||
|
||||
return (!ELEM(nullptr, ob, ma) && ID_IS_EDITABLE(&ob->id) && !ID_IS_OVERRIDE_LIBRARY(&ob->id));
|
||||
}
|
||||
|
||||
static int material_drop_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event)
|
||||
@@ -635,7 +637,7 @@ static int material_drop_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
|
||||
Object *ob = (Object *)outliner_ID_drop_find(C, event, ID_OB);
|
||||
Material *ma = (Material *)WM_drag_get_local_ID_from_event(event, ID_MA);
|
||||
|
||||
if (ELEM(nullptr, ob, ma)) {
|
||||
if (ELEM(nullptr, ob, ma) || !BKE_id_is_editable(bmain, &ob->id)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
|
||||
@@ -601,7 +601,13 @@ static bool view3d_collection_drop_poll_external_asset(bContext *C,
|
||||
|
||||
static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
||||
{
|
||||
return view3d_drop_id_in_main_region_poll(C, drag, event, ID_MA);
|
||||
if (!view3d_drop_id_in_main_region_poll(C, drag, event, ID_MA)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object *ob = ED_view3d_give_object_under_cursor(C, event->mval);
|
||||
|
||||
return (ob && ID_IS_EDITABLE(&ob->id) && !ID_IS_OVERRIDE_LIBRARY(&ob->id));
|
||||
}
|
||||
|
||||
static std::string view3d_mat_drop_tooltip(bContext *C,
|
||||
|
||||
Reference in New Issue
Block a user