BLO_library_append_named_part now returns the newly linked/appended datablock.

This commit is contained in:
Campbell Barton 2011-05-24 15:02:46 +00:00
parent 6a4a8854b5
commit a8cb91e64a
2 changed files with 14 additions and 11 deletions

@ -224,7 +224,7 @@ struct Main* BLO_library_append_begin(const struct bContext *C, BlendHandle** bh
* @param flag Options for linking, used for instancing.
* @return Boolean, 0 when the datablock could not be found.
*/
int BLO_library_append_named_part(const struct bContext *C, struct Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag);
struct ID *BLO_library_append_named_part(const struct bContext *C, struct Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag);
void BLO_library_append_end(const struct bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag);
void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname);

@ -12804,13 +12804,13 @@ static void give_base_to_groups(Main *mainvar, Scene *scene)
/* returns true if the item was found
* but it may already have already been appended/linked */
static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *idname, int idcode, short flag)
static ID *append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *idname, int idcode, short flag)
{
Scene *scene= CTX_data_scene(C);
Scene *scene= CTX_data_scene(C); /* can be NULL */
Object *ob;
Base *base;
BHead *bhead;
ID *id;
ID *id= NULL;
int endloop=0;
int found=0;
@ -12825,7 +12825,7 @@ static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const
found= 1;
id= is_yet_read(fd, mainl, bhead);
if(id==NULL) {
read_libblock(fd, mainl, bhead, LIB_TESTEXT, NULL);
read_libblock(fd, mainl, bhead, LIB_TESTEXT, &id);
}
else {
printf("append: already linked\n");
@ -12836,13 +12836,13 @@ static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const
}
}
if(idcode==ID_OB && scene) { /* loose object: give a base */
/* TODO, move out of append and into own func the caller can use */
if(scene && id && (GS(id->name) == ID_OB)) { /* loose object: give a base */
base= MEM_callocN( sizeof(Base), "app_nam_part");
BLI_addtail(&scene->base, base);
if(id==NULL) ob= mainl->object.last;
else ob= (Object *)id;
ob= (Object *)id;
/* link at active layer (view3d->lay if in context, else scene->lay */
if((flag & FILE_ACTIVELAY)) {
View3D *v3d = CTX_wm_view3d(C);
@ -12870,10 +12870,13 @@ static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const
bhead = blo_nextbhead(fd, bhead);
}
return found;
/* if we found the id but the id is NULL, this is really bad */
BLI_assert((found != 0) == (id != NULL));
return found ? id : NULL;
}
int BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag)
ID *BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag)
{
FileData *fd= (FileData*)(*bh);
return append_named_part(C, mainl, fd, idname, idcode, flag);