Ejemplo n.º 1
0
int new_id(ListBase *lb, ID *id, const char *tname)
{
    int result;
    char name[MAX_ID_NAME - 2];

    /* if library, don't rename */
    if (id->lib) return 0;

    /* if no libdata given, look up based on ID */
    if (lb == NULL) lb = which_libbase(G.main, GS(id->name));

    /* if no name given, use name of current ID
     * else make a copy (tname args can be const) */
    if (tname == NULL)
        tname = id->name + 2;

    strncpy(name, tname, sizeof(name) - 1);

    /* if result > MAX_ID_NAME-3, strncpy don't put the final '\0' to name.
     * easier to assign each time then to check if its needed */
    name[sizeof(name) - 1] = 0;

    if (name[0] == '\0') {
        /* disallow empty names */
        strcpy(name, ID_FALLBACK_NAME);
    }
    else {
        /* disallow non utf8 chars,
         * the interface checks for this but new ID's based on file names don't */
        BLI_utf8_invalid_strip(name, strlen(name));
    }

    result = check_for_dupid(lb, id, name);
    strcpy(id->name + 2, name);

    /* This was in 2.43 and previous releases
     * however all data in blender should be sorted, not just duplicate names
     * sorting should not hurt, but noting just incause it alters the way other
     * functions work, so sort every time */
#if 0
    if (result)
        id_sort_by_name(lb, id);
#endif

    id_sort_by_name(lb, id);

    return result;
}
Ejemplo n.º 2
0
int new_id(ListBase *lb, ID *id, const char *tname)
{
	int result;
	char name[22];
	
	/* if library, don't rename */
	if(id->lib) return 0;

	/* if no libdata given, look up based on ID */
	if(lb==NULL) lb= wich_libbase(G.main, GS(id->name));

	if(tname==0) {	/* if no name given, use name of current ID */
		strncpy(name, id->name+2, 21);
		result= strlen(id->name+2);
	}
	else { /* else make a copy (tname args can be const) */
		strncpy(name, tname, 21);
		result= strlen(tname);
	}

	/* if result > 21, strncpy don't put the final '\0' to name. */
	if( result >= 21 ) name[21]= 0;

	result = check_for_dupid( lb, id, name );
	strcpy( id->name+2, name );

	/* This was in 2.43 and previous releases
	 * however all data in blender should be sorted, not just duplicate names
	 * sorting should not hurt, but noting just incause it alters the way other
	 * functions work, so sort every time */
	/* if( result )
		sort_alpha_id(lb, id);*/
	
	sort_alpha_id(lb, id);
	
	return result;
}