[Bf-blender-cvs] [ca70271] asset-experiments: Append/link from 'global' level works.
Bastien Montagne
noreply at git.blender.org
Wed Dec 3 18:59:10 CET 2014
Commit: ca702718767b6264199a2a0d072f5dbc32da4ae4
Author: Bastien Montagne
Date: Wed Dec 3 18:55:07 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rBca702718767b6264199a2a0d072f5dbc32da4ae4
Append/link from 'global' level works.
Note I had to implement 'relative' path handling for 'filenames' in
append/link op, we may want to do this a bit differently later?
===================================================================
M source/blender/editors/space_file/file_draw.c
M source/blender/editors/space_file/filelist.c
M source/blender/windowmanager/intern/wm_operators.c
===================================================================
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index b774dc6..b626972 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -292,7 +292,7 @@ static void file_draw_string(int sx, int sy, const char *string, float width, in
fs.align = align;
- BLI_strncpy(fname, BLI_path_basename(string), FILE_MAXFILE);
+ BLI_strncpy(fname, string /*BLI_path_basename(string)*/, FILE_MAXFILE);
file_shorten_string(fname, width + 1.0f, 0);
/* no text clipping needed, UI_fontstyle_draw does it but is a bit too strict (for buttons it works) */
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 6294162..37dcdb7 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1016,16 +1016,17 @@ static void filelist_read_library_flat(struct FileList *filelist)
new_filelist = malloc(sizeof(*new_filelist) * (size_t)new_numfiles);
memcpy(new_filelist, filelist->filelist, sizeof(*new_filelist) * filelist->numfiles);
for (i = filelist->numfiles, j = 0, f = fl->filelist; j < fl->numfiles; j++, f++) {
- printf("%s\n", f->relname);
- //~ if (STREQ(file->relname, "..")) {
+ //~ if (STREQ(f->relname, "..")) {
//~ new_numfiles--;
//~ continue;
//~ }
BLI_join_dirfile(dir, sizeof(dir), fl->dir, f->relname);
+ printf("%s, %s, %s, %s\n", filelist->dir, dir, "", "");
BLI_cleanup_file(filelist->dir, dir);
- printf("%s, %s, %s, %s\n", dir, fl->dir, f->relname, f->path);
+ BLI_path_rel(dir, filelist->dir);
+ printf("\t\t-> %s, %s, %s, %s\n", dir, "", "", "");
new_filelist[i] = *f;
- new_filelist[i].relname = BLI_strdup(dir);
+ new_filelist[i].relname = BLI_strdup(dir + 2); /* + 2 to remove '//' added by BLI_path_rel */
//new_filelist[i].path = BLI_strdup(f->path);
/* those pointers are given to new_filelist... */
f->path = NULL;
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 3ed00cf..92c96f7 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2567,12 +2567,22 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
BlendHandle *bh;
Library *lib;
PropertyRNA *prop;
- char name[FILE_MAX], dir[FILE_MAX], libname[FILE_MAX], group[BLO_GROUP_MAX];
+ char name[FILE_MAXFILE], root_dir[FILE_MAXDIR], dir[FILE_MAXDIR], libname[FILE_MAX], group[BLO_GROUP_MAX];
+ char *slash;
int idcode, totfiles = 0;
short flag;
RNA_string_get(op->ptr, "filename", name);
- RNA_string_get(op->ptr, "directory", dir);
+ RNA_string_get(op->ptr, "directory", root_dir);
+
+ if ((slash = BLI_last_slash(name))) {
+ *slash = '\0';
+ BLI_strncpy(dir, root_dir, sizeof(dir) - 1);
+ BLI_path_append(dir, sizeof(dir) - 1, name);
+ BLI_add_slash(dir);
+ slash++;
+ BLI_strncpy(name, slash, sizeof(name) - (slash - name));
+ }
/* test if we have a valid data */
if (BLO_is_a_library(dir, libname, group) == 0) {
@@ -2604,6 +2614,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ printf("%s\n", libname);
bh = BLO_blendhandle_from_file(libname, op->reports);
if (bh == NULL) {
@@ -2647,10 +2658,24 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
}
else {
+ char tmp_dir[FILE_MAXDIR];
RNA_BEGIN (op->ptr, itemptr, "files")
{
RNA_string_get(&itemptr, "name", name);
- BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
+
+ if ((slash = BLI_last_slash(name))) {
+ *slash = '\0';
+ BLI_strncpy(dir, root_dir, sizeof(dir) - 1);
+ BLI_path_append(dir, sizeof(dir) - 1, name);
+ BLI_add_slash(dir);
+ slash++;
+ BLI_strncpy(name, slash, sizeof(name) - (slash - name));
+ }
+
+ if (BLO_is_a_library(dir, libname, group)) {
+ idcode = BKE_idcode_from_name(group);
+ BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
+ }
}
RNA_END;
}
More information about the Bf-blender-cvs
mailing list