Fix (studio-reported) more possibilities to edit content of linked/override collections.

Existing code for the `Move` operator, and some `Collections` panel
operations (Object properties) was absolutely not override-safe, and
sometimes not even linked-data safe.
This commit is contained in:
Bastien Montagne 2022-05-19 16:48:45 +02:00
parent f8ebb0e1d5
commit 2d5b91d6a0
3 changed files with 30 additions and 4 deletions

View File

@ -1172,14 +1172,21 @@ static bool scene_collections_object_remove(
{
bool removed = false;
/* If given object is removed from all collections in given scene, then it can also be safely
* removed from rigidbody world for given scene. */
if (collection_skip == NULL) {
BKE_scene_remove_rigidbody_object(bmain, scene, ob, free_us);
}
FOREACH_SCENE_COLLECTION_BEGIN (scene, collection) {
if (collection != collection_skip) {
removed |= collection_object_remove(bmain, collection, ob, free_us);
if (ID_IS_LINKED(collection) || ID_IS_OVERRIDE_LIBRARY(collection)) {
continue;
}
if (collection == collection_skip) {
continue;
}
removed |= collection_object_remove(bmain, collection, ob, free_us);
}
FOREACH_SCENE_COLLECTION_END;

View File

@ -526,7 +526,7 @@ void OBJECT_OT_collection_link(wmOperatorType *ot)
ot->prop = prop;
}
static int collection_remove_exec(bContext *C, wmOperator *UNUSED(op))
static int collection_remove_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Object *ob = ED_object_context(C);
@ -535,6 +535,12 @@ static int collection_remove_exec(bContext *C, wmOperator *UNUSED(op))
if (!ob || !collection) {
return OPERATOR_CANCELLED;
}
if (ID_IS_LINKED(collection) || ID_IS_OVERRIDE_LIBRARY(collection)) {
BKE_report(op->reports,
RPT_ERROR,
"Cannot remove an object from a linked or library override collection");
return OPERATOR_CANCELLED;
}
BKE_collection_object_remove(bmain, collection, ob, false);
@ -561,7 +567,7 @@ void OBJECT_OT_collection_remove(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int collection_unlink_exec(bContext *C, wmOperator *UNUSED(op))
static int collection_unlink_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Collection *collection = CTX_data_pointer_get_type(C, "collection", &RNA_Collection).data;
@ -569,6 +575,14 @@ static int collection_unlink_exec(bContext *C, wmOperator *UNUSED(op))
if (!collection) {
return OPERATOR_CANCELLED;
}
if (ID_IS_OVERRIDE_LIBRARY(collection) &&
collection->id.override_library->hierarchy_root != &collection->id) {
BKE_report(op->reports,
RPT_ERROR,
"Cannot unlink a library override collection which is not the root of its override "
"hierarchy");
return OPERATOR_CANCELLED;
}
BKE_id_delete(bmain, collection);

View File

@ -1811,6 +1811,11 @@ static int move_to_collection_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
if (ID_IS_OVERRIDE_LIBRARY(collection)) {
BKE_report(op->reports, RPT_ERROR, "Cannot add objects to a library override collection");
return OPERATOR_CANCELLED;
}
ListBase objects = selected_objects_get(C);
if (is_new) {