Outliner: Sanitize material unlinking callback, report errors
The callback would just assume that it's only called on materials, which may in fact not be the case. It could also be called for other ID types and layer collections (see `outliner_do_libdata_operation()`). Properly check this now. Also avoid faling silently when the object or object-data to unlink from couldn't be determined. Report this to the user. Operators that just do nothing are confusing.
This commit is contained in:
parent
e772087ed6
commit
67254ea37c
|
@ -222,16 +222,30 @@ static void unlink_action_fn(bContext *C,
|
|||
}
|
||||
|
||||
static void unlink_material_fn(bContext *UNUSED(C),
|
||||
ReportList *UNUSED(reports),
|
||||
ReportList *reports,
|
||||
Scene *UNUSED(scene),
|
||||
TreeElement *te,
|
||||
TreeStoreElem *tsep,
|
||||
TreeStoreElem *UNUSED(tselem),
|
||||
TreeStoreElem *tselem,
|
||||
void *UNUSED(user_data))
|
||||
{
|
||||
const bool te_is_material = TSE_IS_REAL_ID(tselem) && (GS(tselem->id->name) == ID_MA);
|
||||
|
||||
if (!te_is_material) {
|
||||
/* Just fail silently. Another element may be selected that is a material, we don't want to
|
||||
* confuse users with an error in that case. */
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tsep || !TSE_IS_REAL_ID(tsep)) {
|
||||
/* Valid case, no parent element of the material or it is not an ID (could be a #TSE_ID_BASE
|
||||
* for example) so there's no data to unlink from. */
|
||||
BKE_reportf(reports,
|
||||
RPT_WARNING,
|
||||
"Cannot unlink material '%s'. It's not clear which object or object-data it "
|
||||
"should be unlinked from, there's no object or object-data as parent in the "
|
||||
"Outliner tree",
|
||||
tselem->id->name + 2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue