Fix: Disable collection export for linked collections

If a non-instanced collection is linked, any collection exporters on the
linked collection would be active and invokable. This is probably not
desired as it could inadvertently overwrite files from the original.
Disable the operators in this case.

See PR for how each of the various append/link scenarios behave.

Pull Request: https://projects.blender.org/blender/blender/pulls/123149
This commit is contained in:
Jesse Yurkovich
2024-06-21 20:52:18 +02:00
committed by Jesse Yurkovich
parent 2adb9762fa
commit 9d8a90d53c
2 changed files with 17 additions and 3 deletions

View File

@@ -1220,7 +1220,9 @@ static void layer_collection_sync(ViewLayer *view_layer,
child_layer->runtime_flag |= LAYER_COLLECTION_VISIBLE_VIEW_LAYER;
}
if (!BLI_listbase_is_empty(&child_collection->exporters)) {
if (!BLI_listbase_is_empty(&child_collection->exporters) &&
!(ID_IS_LINKED(&child_collection->id) || ID_IS_OVERRIDE_LIBRARY(&child_collection->id)))
{
view_layer->flag |= VIEW_LAYER_HAS_EXPORT_COLLECTIONS;
}
}

View File

@@ -424,15 +424,23 @@ void COLLECTION_OT_create(wmOperatorType *ot)
ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Name of the new collection");
}
static bool collection_exporter_common_check(const Collection *collection)
{
return collection != nullptr &&
!(ID_IS_LINKED(&collection->id) || ID_IS_OVERRIDE_LIBRARY(&collection->id));
}
static bool collection_exporter_poll(bContext *C)
{
return CTX_data_collection(C) != nullptr;
const Collection *collection = CTX_data_collection(C);
return collection_exporter_common_check(collection);
}
static bool collection_exporter_remove_poll(bContext *C)
{
const Collection *collection = CTX_data_collection(C);
return collection != nullptr && !BLI_listbase_is_empty(&collection->exporters);
return collection_exporter_common_check(collection) &&
!BLI_listbase_is_empty(&collection->exporters);
}
static bool collection_export_all_poll(bContext *C)
@@ -696,6 +704,10 @@ static int collection_export_recursive(bContext *C,
return OPERATOR_FINISHED;
}
if (!collection_exporter_common_check(layer_collection->collection)) {
return OPERATOR_FINISHED;
}
if (collection_export(C, op, layer_collection->collection) != OPERATOR_FINISHED) {
return OPERATOR_CANCELLED;
}