From ee307bec882a639c4574480dc7d0505b9812b8dc Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 6 Apr 2012 16:19:30 +0000 Subject: [PATCH] Fix #30798: when linking a datablock, it got simply added to the back of the list, now the linked datablocks are sorted by name too (but still appear after the non-linked datablocks). --- source/blender/blenkernel/BKE_library.h | 1 + source/blender/blenkernel/intern/library.c | 12 ++++++------ source/blender/blenloader/intern/readfile.c | 8 ++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 23da122ed8b..b18d25094dc 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -58,6 +58,7 @@ int id_make_local(struct ID *id, int test); int id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop); int id_copy(struct ID *id, struct ID **newid, int test); int id_unlink(struct ID *id, int test); +void id_sort_by_name(struct ListBase *lb, struct ID *id); int new_id(struct ListBase *lb, struct ID *id, const char *name); void id_clear_lib_data(struct Main *bmain, struct ID *id); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 3c6c3f8c232..0506d606607 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1076,7 +1076,7 @@ void IMAnames_to_pupstring(const char **str, const char *title, const char *extr BLI_dynstr_free(pupds); } -static void sort_alpha_id(ListBase *lb, ID *id) +void id_sort_by_name(ListBase *lb, ID *id) { ID *idtest; @@ -1086,7 +1086,7 @@ static void sort_alpha_id(ListBase *lb, ID *id) idtest= lb->first; while (idtest) { - if (BLI_strcasecmp(idtest->name, id->name)>0 || idtest->lib) { + if (BLI_strcasecmp(idtest->name, id->name)>0 || (idtest->lib && !id->lib)) { BLI_insertlinkbefore(lb, idtest, id); break; } @@ -1270,10 +1270,10 @@ int new_id(ListBase *lb, ID *id, const char *tname) * functions work, so sort every time */ #if 0 if ( result ) - sort_alpha_id(lb, id); + id_sort_by_name(lb, id); #endif - sort_alpha_id(lb, id); + id_sort_by_name(lb, id); return result; } @@ -1415,7 +1415,7 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) /* why sort alphabetically here but not in * id_clear_lib_data() ? - campbell */ - sort_alpha_id(lbarray[a], id); + id_sort_by_name(lbarray[a], id); } else { id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW); @@ -1455,7 +1455,7 @@ void test_idbutton(char *name) /* search for id */ idtest= BLI_findstring(lb, name, offsetof(ID, name) + 2); - if (idtest) if ( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest); + if (idtest) if ( new_id(lb, idtest, name)==0 ) id_sort_by_name(lb, idtest); } void text_idbutton(struct ID *id, char *text) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 798c48dfaac..737a182bbe0 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -14587,9 +14587,17 @@ static ID *append_named_part(Main *mainl, FileData *fd, const char *idname, cons found= 1; id= is_yet_read(fd, mainl, bhead); if (id==NULL) { + /* not read yet */ read_libblock(fd, mainl, bhead, LIB_TESTEXT, &id); + + if (id) { + /* sort by name in list */ + ListBase *lb= which_libbase(mainl, idcode); + id_sort_by_name(lb, id); + } } else { + /* already linked */ printf("append: already linked\n"); oldnewmap_insert(fd->libmap, bhead->old, id, 1); if (id->flag & LIB_INDIRECT) {