Fake user: add BKE_library helpers to set/clear that flag.
Since it also involves usercount manipulation, safer and cleaner to do it in BKE_library...
This commit is contained in:
parent
f761ae8f11
commit
9c6fe810a3
|
@ -64,6 +64,8 @@ void BKE_library_filepath_set(struct Library *lib, const char *filepath);
|
|||
void id_us_ensure_real(struct ID *id);
|
||||
void id_us_plus(struct ID *id);
|
||||
void id_us_min(struct ID *id);
|
||||
void id_fake_user_set(struct ID *id);
|
||||
void id_fake_user_clear(struct ID *id);
|
||||
|
||||
bool id_make_local(struct ID *id, bool test);
|
||||
bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop);
|
||||
|
|
|
@ -136,7 +136,7 @@ void BKE_brush_init(Brush *brush)
|
|||
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id));
|
||||
|
||||
/* enable fake user by default */
|
||||
brush->id.flag |= LIB_FAKEUSER;
|
||||
id_fake_user_set(&brush->id);
|
||||
|
||||
brush_defaults(brush);
|
||||
|
||||
|
@ -193,11 +193,8 @@ Brush *BKE_brush_copy(Brush *brush)
|
|||
brushn->curve = curvemapping_copy(brush->curve);
|
||||
|
||||
/* enable fake user by default */
|
||||
if (!(brushn->id.flag & LIB_FAKEUSER)) {
|
||||
brushn->id.flag |= LIB_FAKEUSER;
|
||||
id_us_plus(&brushn->id);
|
||||
}
|
||||
|
||||
id_fake_user_set(&brush->id);
|
||||
|
||||
if (brush->id.lib) {
|
||||
BKE_id_lib_local_paths(G.main, brush->id.lib, &brushn->id);
|
||||
}
|
||||
|
@ -280,15 +277,11 @@ void BKE_brush_make_local(Brush *brush)
|
|||
extern_local_brush(brush);
|
||||
|
||||
/* enable fake user by default */
|
||||
if (!(brush->id.flag & LIB_FAKEUSER)) {
|
||||
brush->id.flag |= LIB_FAKEUSER;
|
||||
id_us_plus(&brush->id);
|
||||
}
|
||||
id_fake_user_set(&brush->id);
|
||||
}
|
||||
else if (is_local && is_lib) {
|
||||
Brush *brush_new = BKE_brush_copy(brush);
|
||||
Brush *brush_new = BKE_brush_copy(brush); /* Ensures FAKE_USER is set */
|
||||
brush_new->id.us = 1; /* only keep fake user */
|
||||
brush_new->id.flag |= LIB_FAKEUSER;
|
||||
|
||||
/* Remap paths of new ID using old library as base. */
|
||||
BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id);
|
||||
|
|
|
@ -196,6 +196,22 @@ void id_us_min(ID *id)
|
|||
}
|
||||
}
|
||||
|
||||
void id_fake_user_set(ID *id)
|
||||
{
|
||||
if (id && !(id->flag & LIB_FAKEUSER)) {
|
||||
id->flag |= LIB_FAKEUSER;
|
||||
id_us_plus(id);
|
||||
}
|
||||
}
|
||||
|
||||
void id_fake_user_clear(ID *id)
|
||||
{
|
||||
if (id && (id->flag & LIB_FAKEUSER)) {
|
||||
id->flag &= ~LIB_FAKEUSER;
|
||||
id_us_min(id);
|
||||
}
|
||||
}
|
||||
|
||||
/* calls the appropriate make_local method for the block, unless test. Returns true
|
||||
* if the block can be made local. */
|
||||
bool id_make_local(ID *id, bool test)
|
||||
|
@ -1610,10 +1626,7 @@ void id_clear_lib_data(Main *bmain, ID *id)
|
|||
|
||||
BKE_id_lib_local_paths(bmain, id->lib, id);
|
||||
|
||||
if (id->flag & LIB_FAKEUSER) {
|
||||
id->us--;
|
||||
id->flag &= ~LIB_FAKEUSER;
|
||||
}
|
||||
id_fake_user_clear(id);
|
||||
|
||||
id->lib = NULL;
|
||||
id->flag = LIB_LOCAL;
|
||||
|
|
|
@ -804,7 +804,7 @@ static Mask *mask_alloc(Main *bmain, const char *name)
|
|||
|
||||
mask = BKE_libblock_alloc(bmain, ID_MSK, name);
|
||||
|
||||
mask->id.flag |= LIB_FAKEUSER;
|
||||
id_fake_user_set(&mask->id);
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
@ -843,10 +843,7 @@ Mask *BKE_mask_copy_nolib(Mask *mask)
|
|||
BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers);
|
||||
|
||||
/* enable fake user by default */
|
||||
if (!(mask_new->id.flag & LIB_FAKEUSER)) {
|
||||
mask_new->id.flag |= LIB_FAKEUSER;
|
||||
id_us_plus(&mask_new->id);
|
||||
}
|
||||
id_fake_user_set(&mask->id);
|
||||
|
||||
return mask_new;
|
||||
}
|
||||
|
@ -862,10 +859,7 @@ Mask *BKE_mask_copy(Mask *mask)
|
|||
BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers);
|
||||
|
||||
/* enable fake user by default */
|
||||
if (!(mask_new->id.flag & LIB_FAKEUSER)) {
|
||||
mask_new->id.flag |= LIB_FAKEUSER;
|
||||
id_us_plus(&mask_new->id);
|
||||
}
|
||||
id_fake_user_set(&mask->id);
|
||||
|
||||
if (mask->id.lib) {
|
||||
BKE_id_lib_local_paths(G.main, mask->id.lib, &mask_new->id);
|
||||
|
|
|
@ -373,7 +373,7 @@ Palette *BKE_palette_add(Main *bmain, const char *name)
|
|||
palette = BKE_libblock_alloc(bmain, ID_PAL, name);
|
||||
|
||||
/* enable fake user by default */
|
||||
palette->id.flag |= LIB_FAKEUSER;
|
||||
id_fake_user_set(&palette->id);
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
|
|
@ -7928,8 +7928,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
|
|||
/* clear first 8 bits */
|
||||
id->flag = (id->flag & 0xFF00) | flag | LIB_NEED_LINK;
|
||||
id->lib = main->curlib;
|
||||
if (id->flag & LIB_FAKEUSER) id->us= 1;
|
||||
else id->us = 0;
|
||||
id->us = (id->flag & LIB_FAKEUSER) ? 1 : 0;
|
||||
id->icon_id = 0;
|
||||
id->flag &= ~(LIB_ID_RECALC | LIB_ID_RECALC_DATA | LIB_DOIT | LIB_MISSING);
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
|
|||
|
||||
if (id && CTX_wm_window(C)->eventstate->shift) {
|
||||
/* only way to force-remove data (on save) */
|
||||
id->flag &= ~LIB_FAKEUSER;
|
||||
id_fake_user_clear(id);
|
||||
id->us = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -581,10 +581,7 @@ void ED_animedit_unlink_action(bContext *C, ID *id, AnimData *adt, bAction *act,
|
|||
}
|
||||
|
||||
/* Clear Fake User */
|
||||
if (act->id.flag & LIB_FAKEUSER) {
|
||||
act->id.flag &= ~LIB_FAKEUSER;
|
||||
id_us_min(&act->id);
|
||||
}
|
||||
id_fake_user_clear(&act->id);
|
||||
}
|
||||
|
||||
/* If in Tweak Mode, don't unlink. Instead, this
|
||||
|
|
|
@ -421,10 +421,7 @@ static void id_fake_user_set_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeE
|
|||
{
|
||||
ID *id = tselem->id;
|
||||
|
||||
if ((id) && ((id->flag & LIB_FAKEUSER) == 0)) {
|
||||
id->flag |= LIB_FAKEUSER;
|
||||
id_us_plus(id);
|
||||
}
|
||||
id_fake_user_set(id);
|
||||
}
|
||||
|
||||
static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te),
|
||||
|
@ -432,10 +429,7 @@ static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), Tre
|
|||
{
|
||||
ID *id = tselem->id;
|
||||
|
||||
if ((id) && (id->flag & LIB_FAKEUSER)) {
|
||||
id->flag &= ~LIB_FAKEUSER;
|
||||
id_us_min(id);
|
||||
}
|
||||
id_fake_user_clear(id);
|
||||
}
|
||||
|
||||
static void id_select_linked_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
|
||||
|
|
|
@ -223,13 +223,11 @@ void rna_ID_fake_user_set(PointerRNA *ptr, int value)
|
|||
{
|
||||
ID *id = (ID *)ptr->data;
|
||||
|
||||
if (value && !(id->flag & LIB_FAKEUSER)) {
|
||||
id->flag |= LIB_FAKEUSER;
|
||||
id_us_plus(id);
|
||||
if (value) {
|
||||
id_fake_user_set(id);
|
||||
}
|
||||
else if (!value && (id->flag & LIB_FAKEUSER)) {
|
||||
id->flag &= ~LIB_FAKEUSER;
|
||||
id_us_min(id);
|
||||
else {
|
||||
id_fake_user_clear(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,8 +327,8 @@ static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
|
|||
|
||||
static void rna_ID_user_clear(ID *id)
|
||||
{
|
||||
id_fake_user_clear(id);
|
||||
id->us = 0; /* don't save */
|
||||
id->flag &= ~LIB_FAKEUSER;
|
||||
}
|
||||
|
||||
static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
|
||||
|
|
|
@ -639,8 +639,7 @@ static void rna_Main_armatures_remove(Main *bmain, ReportList *reports, PointerR
|
|||
static bAction *rna_Main_actions_new(Main *bmain, const char *name)
|
||||
{
|
||||
bAction *act = add_empty_action(bmain, name);
|
||||
id_us_min(&act->id);
|
||||
act->id.flag &= ~LIB_FAKEUSER;
|
||||
id_fake_user_clear(&act->id);
|
||||
return act;
|
||||
}
|
||||
static void rna_Main_actions_remove(Main *bmain, ReportList *reports, PointerRNA *act_ptr)
|
||||
|
|
Loading…
Reference in New Issue