diff options
author | Bastien Montagne <bastien@blender.org> | 2021-02-25 12:17:31 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-02-25 13:39:10 +0300 |
commit | de25b79ff5c4da7d2d604eaa33b8c520c246679b (patch) | |
tree | cf5f47ff016802ca3c90171d290ad0a2edb9a361 /source/blender/editors/space_outliner | |
parent | b5d39f9b469e6a1688bb4498f6635bd5e23a35ef (diff) |
Refactor: IDTypeInfo: Add `owner_get` to get owner of embedded IDs.
This concerns currently only collections (`master_collection` of scenes)
and root node trees. It removes the matching type-specific helpers
(`BKE_collection_master_scene_search` and `BKE_node_tree_find_owner_ID`).
No functional change expected here.
NOTE: Current implementation of `owner_get` is far from optimal, we
could probably do it better, see {T69169}.
NOTE: While it could also have it, shapekeys IDTypeInfo was left out of
this change for now. Mainly because it sould not be used currently, and
we ultimately want to demote shape keys from ID status anyway.
Diffstat (limited to 'source/blender/editors/space_outliner')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_collections.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c index e686648038d..0afc26e0d8a 100644 --- a/source/blender/editors/space_outliner/outliner_collections.c +++ b/source/blender/editors/space_outliner/outliner_collections.c @@ -28,6 +28,7 @@ #include "BKE_collection.h" #include "BKE_context.h" +#include "BKE_idtype.h" #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_main.h" @@ -361,8 +362,14 @@ void outliner_collection_delete( break; } if (parent->flag & COLLECTION_IS_MASTER) { - Scene *parent_scene = BKE_collection_master_scene_search(bmain, parent); - if (ID_IS_LINKED(parent_scene)) { + BLI_assert(parent->id.flag & LIB_EMBEDDED_DATA); + + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(&parent->id); + BLI_assert(id_type->owner_get != NULL); + + ID *scene_owner = id_type->owner_get(bmain, &parent->id); + BLI_assert(GS(scene_owner->name) == ID_SCE); + if (ID_IS_LINKED(scene_owner)) { skip = true; break; } @@ -592,11 +599,18 @@ static int collection_duplicate_exec(bContext *C, wmOperator *op) scene->master_collection; } else if (parent != NULL && (parent->flag & COLLECTION_IS_MASTER) != 0) { - Scene *scene = BKE_collection_master_scene_search(bmain, parent); - BLI_assert(scene != NULL); - if (ID_IS_LINKED(scene) || ID_IS_OVERRIDE_LIBRARY(scene)) { - scene = CTX_data_scene(C); - parent = ID_IS_LINKED(scene) ? NULL : scene->master_collection; + BLI_assert(parent->id.flag & LIB_EMBEDDED_DATA); + + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(&parent->id); + BLI_assert(id_type->owner_get != NULL); + + Scene *scene_owner = (Scene *)id_type->owner_get(bmain, &parent->id); + BLI_assert(scene_owner != NULL); + BLI_assert(GS(scene_owner->id.name) == ID_SCE); + + if (ID_IS_LINKED(scene_owner) || ID_IS_OVERRIDE_LIBRARY(scene_owner)) { + scene_owner = CTX_data_scene(C); + parent = ID_IS_LINKED(scene_owner) ? NULL : scene_owner->master_collection; } } |