Revision: 41235
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41235
Author:   campbellbarton
Date:     2011-10-24 04:52:43 +0000 (Mon, 24 Oct 2011)
Log Message:
-----------
added function BKE_library_filepath_set which sync's the libraries absolute 
path when setting to a relative value, before this you could never be sure if a 
libraries absolute path was valid or not because the user might have changed 
the relative library path in the outliner, now setting from the outliner and 
py/rna syncs the absolute path.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_library.h
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/editors/space_outliner/outliner_draw.c
    trunk/blender/source/blender/makesdna/DNA_ID.h
    trunk/blender/source/blender/makesrna/intern/rna_ID.c

Modified: trunk/blender/source/blender/blenkernel/BKE_library.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_library.h       2011-10-24 
04:18:28 UTC (rev 41234)
+++ trunk/blender/source/blender/blenkernel/BKE_library.h       2011-10-24 
04:52:43 UTC (rev 41235)
@@ -50,6 +50,7 @@
 void copy_libblock_data(struct ID *id, const struct ID *id_from, const short 
do_action);
 
 void id_lib_extern(struct ID *id);
+void BKE_library_filepath_set(struct Library *lib, const char *filepath);
 void id_us_plus(struct ID *id);
 void id_us_min(struct ID *id);
 int id_make_local(struct ID *id, int test);

Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c    2011-10-24 
04:18:28 UTC (rev 41234)
+++ trunk/blender/source/blender/blenkernel/intern/library.c    2011-10-24 
04:52:43 UTC (rev 41235)
@@ -1461,3 +1461,21 @@
 
        strcpy(name+3, id->name+2);
 }
+
+void BKE_library_filepath_set(Library *lib, const char *filepath)
+{
+       BLI_strncpy(lib->name, filepath, sizeof(lib->name));
+       BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath));
+
+       /* not essential but set filepath is an absolute copy of value which
+        * is more useful if its kept in sync */
+       if (strncmp(lib->filepath, "//", 2) == 0) {
+               /* note that the file may be unsaved, in this case, setting the
+                * filepath on an indirectly linked path is not allowed from the
+                * outliner, and its not really supported but allow from here 
for now
+                * since making local could cause this to be directly linked - 
campbell
+                */
+               const char *basepath= lib->parent ? lib->parent->filepath : 
G.main->name;
+               BLI_path_abs(lib->filepath, basepath);
+       }
+}

Modified: trunk/blender/source/blender/editors/space_outliner/outliner_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_outliner/outliner_draw.c 
2011-10-24 04:18:28 UTC (rev 41234)
+++ trunk/blender/source/blender/editors/space_outliner/outliner_draw.c 
2011-10-24 04:52:43 UTC (rev 41235)
@@ -310,11 +310,19 @@
                        }                                       
                        /* Check the library target exists */
                        if (te->idcode == ID_LI) {
-                               char expanded[FILE_MAXDIR + FILE_MAXFILE];
-                               BLI_strncpy(expanded, ((Library 
*)tselem->id)->name, FILE_MAXDIR + FILE_MAXFILE);
+                               Library *lib= (Library *)tselem->id;
+                               char expanded[FILE_MAX];
+
+                               BLI_strncpy(expanded, lib->name, 
sizeof(expanded));
+
+                               /* even though we already set the name this 
syncs the absolute
+                                * path, this is intentionally not already 
expanded yet to
+                                * avoid copying lib->name to its self. */
+                               BKE_library_filepath_set(lib, expanded);
+
                                BLI_path_abs(expanded, G.main->name);
                                if (!BLI_exists(expanded)) {
-                                       BKE_report(CTX_wm_reports(C), 
RPT_ERROR, "This path does not exist, correct this before saving");
+                                       BKE_reportf(CTX_wm_reports(C), 
RPT_ERROR, "Library path '%s' does not exist, correct this before saving", 
expanded);
                                }
                        }
                }

Modified: trunk/blender/source/blender/makesdna/DNA_ID.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_ID.h      2011-10-24 04:18:28 UTC 
(rev 41234)
+++ trunk/blender/source/blender/makesdna/DNA_ID.h      2011-10-24 04:52:43 UTC 
(rev 41235)
@@ -116,7 +116,13 @@
        ID *idblock;
        struct FileData *filedata;
        char name[240];                 /* path name used for reading, can be 
relative and edited in the outliner */
-       char filepath[240];             /* temp. absolute filepath, only used 
while reading */
+       char filepath[240];             /* absolute filepath, this is only for 
convenience,
+                                                        * 'name' is the real 
path used on file read but in
+                                                        * some cases its 
useful to access the absolute one,
+                                                        * This is set on file 
read.
+                                                        * Use 
BKE_library_filepath_set() rather than
+                                                        * setting 'name' 
directly and it will be kepk in
+                                                        * sync - campbell */
        int tot, pad;                   /* tot, idblock and filedata are only 
fo read and write */
        struct Library *parent; /* set for indirectly linked libs, used in the 
outliner and while reading */
 } Library;

Modified: trunk/blender/source/blender/makesrna/intern/rna_ID.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ID.c       2011-10-24 
04:18:28 UTC (rev 41234)
+++ trunk/blender/source/blender/makesrna/intern/rna_ID.c       2011-10-24 
04:52:43 UTC (rev 41235)
@@ -326,6 +326,12 @@
        }
 }
 
+void rna_Library_filepath_set(PointerRNA *ptr, const char *value)
+{
+       Library *lib= (Library*)ptr->data;
+       BKE_library_filepath_set(lib, value);
+}
+
 #else
 
 static void rna_def_ID_properties(BlenderRNA *brna)
@@ -521,7 +527,7 @@
        prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
        RNA_def_property_string_sdna(prop, NULL, "name");
        RNA_def_property_ui_text(prop, "File Path", "Path to the library .blend 
file");
-       /* TODO - lib->filename isnt updated, however the outliner also skips 
this, probably only needed on read. */
+       RNA_def_property_string_funcs(prop, NULL, NULL, 
"rna_Library_filepath_set");
        
        prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
        RNA_def_property_struct_type(prop, "Library");

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to