Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/lib_id.c
| Show First 20 Lines • Show All 529 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Generic entry point for copying a data-block (new API). | * Generic entry point for copying a data-block (new API). | ||||
| * | * | ||||
| * \note Copy is generally only affecting the given data-block | * \note Copy is generally only affecting the given data-block | ||||
| * (no ID used by copied one will be affected, besides usercount). | * (no ID used by copied one will be affected, besides usercount). | ||||
| * There are exceptions though: | * There are exceptions though: | ||||
| * - Embedded IDs (root node trees and master collections) are always copied with their owner. | * - Embedded IDs (root node trees and master collections) are always copied with their owner. | ||||
| * - If #LIB_ID_COPY_ACTIONS is defined, actions used by animdata will be duplicated. | * - If #LIB_ID_COPY_ACTIONS is defined, actions used by animdata will be duplicated. | ||||
| * - If #LIB_ID_COPY_SHAPEKEY is defined, shapekeys will be duplicated. | * - If #LIB_ID_COPY_SHAPEKEY is defined, shapekeys will be duplicated. | ||||
mont29: Do not add default generic flags either, so do not include `LIB_ID_COPY_ACTIONS` in returned… | |||||
| * - If #LIB_ID_CREATE_LOCAL is defined, root node trees will be deep-duplicated recursively. | * - If #LIB_ID_CREATE_LOCAL is defined, root node trees will be deep-duplicated recursively. | ||||
| * | * | ||||
| * \note Usercount of new copy is always set to 1. | * \note Usercount of new copy is always set to 1. | ||||
| * | * | ||||
| * \param bmain: Main database, may be NULL only if LIB_ID_CREATE_NO_MAIN is specified. | * \param bmain: Main database, may be NULL only if LIB_ID_CREATE_NO_MAIN is specified. | ||||
| * \param id: Source data-block. | * \param id: Source data-block. | ||||
| * \param r_newid: Pointer to new (copied) ID pointer, may be NULL. Used to allow copying into | * \param r_newid: Pointer to new (copied) ID pointer, may be NULL. Used to allow copying into | ||||
| * already allocated memory. | * already allocated memory. | ||||
| ▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) | ||||
| ID *newid = NULL; | ID *newid = NULL; | ||||
| PointerRNA idptr; | PointerRNA idptr; | ||||
| if (id) { | if (id) { | ||||
| /* If property isn't editable, | /* If property isn't editable, | ||||
| * we're going to have an extra block hanging around until we save. */ | * we're going to have an extra block hanging around until we save. */ | ||||
| if (RNA_property_editable(ptr, prop)) { | if (RNA_property_editable(ptr, prop)) { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| /* copy animation actions too */ | /* Take into account user preferences for duplicating actions. */ | ||||
| newid = BKE_id_copy_ex(bmain, id, NULL, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS); | int copy_flag = LIB_ID_COPY_DEFAULT; | ||||
| if ((U.dupflag & USER_DUP_ACT) != 0) { | |||||
| copy_flag |= LIB_ID_COPY_ACTIONS; | |||||
| } | |||||
| newid = BKE_id_copy_ex(bmain, id, NULL, copy_flag); | |||||
| if (newid != NULL) { | if (newid != NULL) { | ||||
| /* us is 1 by convention with new IDs, but RNA_property_pointer_set | /* us is 1 by convention with new IDs, but RNA_property_pointer_set | ||||
| * will also increment it, decrement it here. */ | * will also increment it, decrement it here. */ | ||||
| id_us_min(newid); | id_us_min(newid); | ||||
| /* assign copy */ | /* assign copy */ | ||||
| RNA_id_pointer_create(newid, &idptr); | RNA_id_pointer_create(newid, &idptr); | ||||
| RNA_property_pointer_set(ptr, prop, idptr, NULL); | RNA_property_pointer_set(ptr, prop, idptr, NULL); | ||||
| ▲ Show 20 Lines • Show All 1,626 Lines • Show Last 20 Lines | |||||
Do not add default generic flags either, so do not include LIB_ID_COPY_ACTIONS in returned value, only add specific flags in reactions to the content of dup_flags.