Cleanup: rename BKE_library's `new_id()` to `BKE_id_new_name_validate()`.

The former was probably one of the worst function names in our whole
code base, totally misleading, and quiet often used as a variable name too.
This commit is contained in:
Bastien Montagne 2019-03-06 11:10:45 +01:00
parent 208fafb285
commit 173c023197
3 changed files with 15 additions and 15 deletions

View File

@ -187,7 +187,7 @@ void id_sort_by_name(struct ListBase *lb, struct ID *id);
void BKE_id_expand_local(struct Main *bmain, struct ID *id);
void BKE_id_copy_ensure_local(struct Main *bmain, const struct ID *old_id, struct ID *new_id);
bool new_id(struct ListBase *lb, struct ID *id, const char *name) ATTR_NONNULL(1, 2);
bool BKE_id_new_name_validate(struct ListBase *lb, struct ID *id, const char *name) ATTR_NONNULL(1, 2);
void id_clear_lib_data(struct Main *bmain, struct ID *id);
void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, const bool id_in_mainlist);
@ -227,7 +227,7 @@ bool BKE_id_is_in_global_main(struct ID *id);
void BKE_id_ordered_list(struct ListBase *ordered_lb, const struct ListBase *lb);
void BKE_id_reorder(const struct ListBase *lb, struct ID *id, struct ID *relative, bool after);
/* use when "" is given to new_id() */
/* use when "" is given to BKE_id_new_name_validate() */
#define ID_FALLBACK_NAME N_("Untitled")
#define IS_TAGGED(_id) ((_id) && (((ID *)_id)->tag & LIB_TAG_DOIT))

View File

@ -843,7 +843,7 @@ void BKE_libblock_management_main_add(Main *bmain, void *idv)
ListBase *lb = which_libbase(bmain, GS(id->name));
BKE_main_lock(bmain);
BLI_addtail(lb, id);
new_id(lb, id, NULL);
BKE_id_new_name_validate(lb, id, NULL);
/* alphabetic insertion: is in new_id */
id->tag &= ~(LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT);
bmain->is_memfile_undo_written = false;
@ -993,7 +993,7 @@ void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb)
}
for (i = 0; i < lb_len; i++) {
if (!BLI_gset_add(gset, id_array[i]->name + 2)) {
new_id(lb, id_array[i], NULL);
BKE_id_new_name_validate(lb, id_array[i], NULL);
}
}
BLI_gset_free(gset, NULL);
@ -1125,7 +1125,7 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int fl
BKE_main_lock(bmain);
BLI_addtail(lb, id);
new_id(lb, id, name);
BKE_id_new_name_validate(lb, id, name);
bmain->is_memfile_undo_written = false;
/* alphabetic insertion: is in new_id */
BKE_main_unlock(bmain);
@ -1571,14 +1571,14 @@ static bool check_for_dupid(ListBase *lb, ID *id, char *name)
#undef MAX_IN_USE
}
/*
* Only for local blocks: external en indirect blocks already have a
* unique ID.
/**
* Ensures given ID has a unique name in given listbase.
*
* return true: created a new name
* Only for local IDs (linked ones already have a unique ID in their library).
*
* \return true if a new name had to be created.
*/
bool new_id(ListBase *lb, ID *id, const char *tname)
bool BKE_id_new_name_validate(ListBase *lb, ID *id, const char *tname)
{
bool result;
char name[MAX_ID_NAME - 2];
@ -1637,7 +1637,7 @@ void id_clear_lib_data_ex(Main *bmain, ID *id, const bool id_in_mainlist)
id->lib = NULL;
id->tag &= ~(LIB_TAG_INDIRECT | LIB_TAG_EXTERN);
if (id_in_mainlist) {
if (new_id(which_libbase(bmain, GS(id->name)), id, NULL)) {
if (BKE_id_new_name_validate(which_libbase(bmain, GS(id->name)), id, NULL)) {
bmain->is_memfile_undo_written = false;
}
}
@ -2015,7 +2015,7 @@ void BLI_libblock_ensure_unique_name(Main *bmain, const char *name)
/* search for id */
idtest = BLI_findstring(lb, name + 2, offsetof(ID, name) + 2);
if (idtest != NULL) {
if (!new_id(lb, idtest, idtest->name + 2)) {
if (!BKE_id_new_name_validate(lb, idtest, idtest->name + 2)) {
id_sort_by_name(lb, idtest);
}
bmain->is_memfile_undo_written = false;
@ -2028,7 +2028,7 @@ void BLI_libblock_ensure_unique_name(Main *bmain, const char *name)
void BKE_libblock_rename(Main *bmain, ID *id, const char *name)
{
ListBase *lb = which_libbase(bmain, GS(id->name));
if (new_id(lb, id, name)) {
if (BKE_id_new_name_validate(lb, id, name)) {
bmain->is_memfile_undo_written = false;
}
}

View File

@ -441,7 +441,7 @@ static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name)
id->flag = LIB_FAKEUSER;
*( (short *)id->name) = ID_GD;
new_id(lb, id, name);
BKE_id_new_name_validate(lb, id, name);
/* alphabetic insertion: is in new_id */
if (G.debug & G_DEBUG)