From 4a674d08dda82bddb461101adfe789272109141f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 24 Mar 2022 11:59:41 +0100 Subject: Outliner: tweak handling of liboverrides in delete code. Essentially, we only allow deletion of hierarchy roots of liboverrides, when hierarchy deletion option is enabled. Also add some checking code in the generic, non-object/collection ID delete code, to prevent any deletion of liboverrides that would be part of a hierarchy. --- .../editors/space_outliner/outliner_collections.cc | 2 +- .../editors/space_outliner/outliner_edit.cc | 11 +++++++ .../editors/space_outliner/outliner_tools.cc | 35 ++++++++++++++++------ 3 files changed, 38 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_outliner/outliner_collections.cc b/source/blender/editors/space_outliner/outliner_collections.cc index 716d5b67fe3..a4ff44512ef 100644 --- a/source/blender/editors/space_outliner/outliner_collections.cc +++ b/source/blender/editors/space_outliner/outliner_collections.cc @@ -301,7 +301,7 @@ static TreeTraversalAction collection_find_data_to_edit(TreeElement *te, void *c if (ID_IS_OVERRIDE_LIBRARY_REAL(collection)) { if (ID_IS_OVERRIDE_LIBRARY_HIERARCHY_ROOT(collection)) { - if (!data->is_liboverride_hierarchy_root_allowed) { + if (!(data->is_liboverride_hierarchy_root_allowed || data->is_liboverride_allowed)) { return TRAVERSE_SKIP_CHILDS; } } diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc index a60e082f6a5..ae67e7108bf 100644 --- a/source/blender/editors/space_outliner/outliner_edit.cc +++ b/source/blender/editors/space_outliner/outliner_edit.cc @@ -447,6 +447,17 @@ static void id_delete(bContext *C, ReportList *reports, TreeElement *te, TreeSto (tselem->type == TSE_LAYER_COLLECTION)); UNUSED_VARS_NDEBUG(te); + if (ID_IS_OVERRIDE_LIBRARY(id)) { + if (!ID_IS_OVERRIDE_LIBRARY_REAL(id) || + (id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_NO_HIERARCHY) == 0) { + BKE_reportf(reports, + RPT_WARNING, + "Cannot delete library override id '%s', it is part of an override hierarchy", + id->name); + return; + } + } + if (te->idcode == ID_LI && ((Library *)id)->parent != nullptr) { BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked library '%s'", id->name); return; diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc index 612baaa0752..0aea4521204 100644 --- a/source/blender/editors/space_outliner/outliner_tools.cc +++ b/source/blender/editors/space_outliner/outliner_tools.cc @@ -1677,6 +1677,12 @@ void OUTLINER_OT_object_operation(wmOperatorType *ot) using OutlinerDeleteFn = void (*)(bContext *C, ReportList *reports, Scene *scene, Object *ob); +typedef struct ObjectEditData { + GSet *objects_set; + bool is_liboverride_allowed; + bool is_liboverride_hierarchy_root_allowed; +} ObjectEditData; + static void outliner_do_object_delete(bContext *C, ReportList *reports, Scene *scene, @@ -1693,7 +1699,8 @@ static void outliner_do_object_delete(bContext *C, static TreeTraversalAction outliner_find_objects_to_delete(TreeElement *te, void *customdata) { - GSet *objects_to_delete = (GSet *)customdata; + ObjectEditData *data = reinterpret_cast(customdata); + GSet *objects_to_delete = data->objects_set; TreeStoreElem *tselem = TREESTORE(te); if (outliner_is_collection_tree_element(te)) { @@ -1708,9 +1715,15 @@ static TreeTraversalAction outliner_find_objects_to_delete(TreeElement *te, void ID *id = tselem->id; if (ID_IS_OVERRIDE_LIBRARY_REAL(id)) { - if (!ID_IS_OVERRIDE_LIBRARY_HIERARCHY_ROOT(id)) { - /* Only allow deletion of liboverride objects if they are root overrides. */ - return TRAVERSE_SKIP_CHILDS; + if (ID_IS_OVERRIDE_LIBRARY_HIERARCHY_ROOT(id)) { + if (!(data->is_liboverride_hierarchy_root_allowed || data->is_liboverride_allowed)) { + return TRAVERSE_SKIP_CHILDS; + } + } + else { + if (!data->is_liboverride_allowed) { + return TRAVERSE_SKIP_CHILDS; + } } } @@ -1732,27 +1745,31 @@ static int outliner_delete_exec(bContext *C, wmOperator *op) /* Get selected objects skipping duplicates to prevent deleting objects linked to multiple * collections twice */ - GSet *objects_to_delete = BLI_gset_ptr_new(__func__); + ObjectEditData object_delete_data = {}; + object_delete_data.objects_set = BLI_gset_ptr_new(__func__); + object_delete_data.is_liboverride_allowed = false; + object_delete_data.is_liboverride_hierarchy_root_allowed = delete_hierarchy; outliner_tree_traverse(space_outliner, &space_outliner->tree, 0, TSE_SELECTED, outliner_find_objects_to_delete, - objects_to_delete); + &object_delete_data); if (delete_hierarchy) { BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); outliner_do_object_delete( - C, op->reports, scene, objects_to_delete, object_batch_delete_hierarchy_fn); + C, op->reports, scene, object_delete_data.objects_set, object_batch_delete_hierarchy_fn); BKE_id_multi_tagged_delete(bmain); } else { - outliner_do_object_delete(C, op->reports, scene, objects_to_delete, outliner_object_delete_fn); + outliner_do_object_delete( + C, op->reports, scene, object_delete_data.objects_set, outliner_object_delete_fn); } - BLI_gset_free(objects_to_delete, nullptr); + BLI_gset_free(object_delete_data.objects_set, nullptr); outliner_collection_delete(C, bmain, scene, op->reports, delete_hierarchy); -- cgit v1.2.3