Nasty Library linking and appending stuff!
authorTon Roosendaal <ton@blender.org>
Thu, 22 Apr 2004 19:58:54 +0000 (19:58 +0000)
committerTon Roosendaal <ton@blender.org>
Thu, 22 Apr 2004 19:58:54 +0000 (19:58 +0000)
Problem: when appending data, it called the local_all() function, which
indeed made all data local, including all other dynamic linked data.
Not very nice... but mixing dynamic & appending data from single file is
headcrunching code.

Solution: when appending data, it now only makes local_all() the data from
that specific library file, leaving dynamic data from other files linked.

(Bug report 1183)

source/blender/blenkernel/BKE_library.h
source/blender/blenkernel/intern/library.c
source/blender/blenloader/intern/readfile.c
source/blender/src/editobject.c
source/blender/src/filesel.c

index 0331afe580bc75cc8f35ecf2eb4f9c9a283a6366..e4c7006959c3e1c38ea6acc14c7191cf88fc6fba 100644 (file)
@@ -59,7 +59,7 @@ void free_main(struct Main *mainvar);
 void splitIDname(char *name, char *left, int *nr);
 void rename_id(struct ID *id, char *name);
 void test_idbutton(char *name);
-void all_local(void);
+void all_local(Library *lib);
 struct ID *find_id(char *type, char *name);
 void clear_id_newpoins(void);
 
index 3b325a0662774f0ae4d50132a7b4e1fdf59c6e9f..48355d6cc49c30620ec852c391978f1dd80dddcb 100644 (file)
 #include "BPI_script.h"
 
 #define MAX_IDPUP              30      /* was 24 */
-#define MAX_LIBARRAY   100 /* was 30 */
+#define MAX_LIBARRAY   100 /* was 30, warning: used it readfile.c too */
 
 /* ************* general ************************ */
 
@@ -836,7 +836,8 @@ void clear_id_newpoins()
        }
 }
 
-void all_local(void)
+/* if lib!=NULL, only all from lib local */
+void all_local(Library *lib)
 {
        ListBase *lbarray[MAX_LIBARRAY], tempbase={0, 0};
        ID *id, *idn;
@@ -847,35 +848,20 @@ void all_local(void)
                id= lbarray[a]->first;
                
                while(id) {
-                       id->newid= 0;
-                       id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW);
-                       
+                       id->newid= NULL;
                        idn= id->next;          /* id is possibly being inserted again */
-                       if(id->lib) {
-                               id->lib= 0;
-                               new_id(lbarray[a], id, 0);      /* new_id only does it with double names */
-                               sort_alpha_id(lbarray[a], id);
-                       }
-                       else {
-                               /* patch: check for alphabetic ordering */
-                               /* has been removed... why!? (ton) */
-/*
-                               if(idn) {
-                                       if(strcasecmp(id->name, idn->name)>0) {
-                                               remlink(lbarray[a], id);
-                                               addtail(&tempbase, id);
-                                       }
-                                       else if(id->prev) {
-                                               idp= id->prev;
-                                               if(strcasecmp(idp->name, id->name)>0) {
-                                                       remlink(lbarray[a], id);
-                                                       addtail(&tempbase, id);
-                                               }
+                       
+                       if(id->flag & (LIB_EXTERN|LIB_INDIRECT|LIB_NEW)) {
+                               if(lib==NULL || id->lib==lib) {
+                                       id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW);
+
+                                       if(id->lib) {
+                                               id->lib= NULL;
+                                               new_id(lbarray[a], id, 0);      /* new_id only does it with double names */
+                                               sort_alpha_id(lbarray[a], id);
                                        }
                                }
-*/                             
                        }
-                       
                        id= idn;
                }
                
index 6d8272f7a4835d395ba2ef67fe2bdf5adc79751f..42d4e3c52a45edb594084956efd1db56b9f2214d 100644 (file)
@@ -374,7 +374,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist);
 
 static void add_main_to_main(Main *mainvar, Main *from)
 {
-       ListBase *lbarray[30], *fromarray[30];
+       ListBase *lbarray[100], *fromarray[100];        // define in library.c too
        int a;
        
        a= set_listbasepointers(mainvar, lbarray);
index 41ea244c3e79b575093177d29d69b9020cb66165..6b9344a5014b64835ae817ba0963d0254473d65d 100644 (file)
@@ -6466,7 +6466,7 @@ void make_local(void)
        mode= pupmenu("Make Local%t|Selected %x1|All %x2");
        
        if(mode==2) {
-               all_local();
+               all_local(NULL);        // NULL is all libs
                allqueue(REDRAWALL, 0);
                return;
        }
index 0bc79c84ef7dbb4c17fd0500a7913ac892ca0609..88b7f793c2c23bdc6a3980fcc392c8782c86dda8 100644 (file)
@@ -2231,6 +2231,7 @@ static int is_a_library(SpaceFile *sfile, char *dir, char *group)
 
 static void do_library_append(SpaceFile *sfile)
 {
+       Library *lib;
        char dir[FILE_MAXDIR], group[32];
        
        if ( is_a_library(sfile, dir, group)==0 ) {
@@ -2269,7 +2270,14 @@ static void do_library_append(SpaceFile *sfile)
                /* in sfile->dir is the whole lib name */
                strcpy(G.lib, sfile->dir);
                
-               if((sfile->flag & FILE_LINK)==0) all_local();
+               /* and now find the latest append lib file */
+               lib= G.main->library.first;
+               while(lib) {
+                       if (BLI_streq(dir, lib->name)) break;
+                       lib= lib->id.next;
+               }
+               
+               if((sfile->flag & FILE_LINK)==0) all_local(lib);
        }
 }