[Bf-blender-cvs] [74ae847] asset-experiments: First (awful) tests to get a whole blend file content shown flat
Bastien Montagne
noreply at git.blender.org
Wed Dec 3 18:59:06 CET 2014
Commit: 74ae847cfa55fdc22e72471a25f1b0b81048d2db
Author: Bastien Montagne
Date: Wed Dec 3 15:29:18 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rB74ae847cfa55fdc22e72471a25f1b0b81048d2db
First (awful) tests to get a whole blend file content shown flat
Main goal is to see whether we can use existing filelist to handle that
(by default it is 100% tree-oriented).
Also, getting some strange issues with ID name currently...
===================================================================
M source/blender/editors/space_file/file_ops.c
M source/blender/editors/space_file/filelist.c
M source/blender/editors/space_file/filesel.c
M source/blender/makesdna/DNA_space_types.h
===================================================================
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index df3f989..6912970 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -859,7 +859,7 @@ int file_parent_exec(bContext *C, wmOperator *UNUSED(unused))
if (BLI_parent_dir(sfile->params->dir)) {
BLI_cleanup_dir(G.main->name, sfile->params->dir);
/* if not browsing in .blend file, we still want to check whether the path is a directory */
- if (sfile->params->type == FILE_LOADLIB) {
+ if (ELEM(sfile->params->type, FILE_LOADLIB, FILE_ASSET)) {
char tdir[FILE_MAX], tgroup[FILE_MAX];
if (BLO_is_a_library(sfile->params->dir, tdir, tgroup)) {
file_change_dir(C, 0);
@@ -1334,7 +1334,7 @@ void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg
UI_textbutton_activate_but(C, but);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
}
- else if (sfile->params->type == FILE_LOADLIB) {
+ else if (ELEM(sfile->params->type, FILE_LOADLIB, FILE_ASSET)) {
char tdir[FILE_MAX], tgroup[FILE_MAX];
BLI_add_slash(filepath);
if (BLO_is_a_library(filepath, tdir, tgroup)) {
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 871abbd..f10ec3c 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -532,14 +532,19 @@ ListBase *folderlist_duplicate(ListBase *folderlist)
}
+/* ------------------FILELIST------------------------ */
+
static void filelist_read_main(struct FileList *filelist);
static void filelist_read_library(struct FileList *filelist);
+static void filelist_read_library_flat(struct FileList *filelist);
static void filelist_read_dir(struct FileList *filelist);
-/* ------------------FILELIST------------------------ */
+static int groupname_to_code(const char *group);
+
FileList *filelist_new(short type)
{
FileList *p = MEM_callocN(sizeof(FileList), "filelist");
+ printf("%d\n", type);
switch (type) {
case FILE_MAIN:
p->readf = filelist_read_main;
@@ -549,6 +554,10 @@ FileList *filelist_new(short type)
p->readf = filelist_read_library;
p->filterf = is_filtered_lib;
break;
+ case FILE_ASSET:
+ p->readf = filelist_read_library_flat;
+ p->filterf = is_filtered_lib;
+ break;
default:
p->readf = filelist_read_dir;
p->filterf = is_filtered_file;
@@ -926,6 +935,103 @@ static void filelist_read_library(struct FileList *filelist)
}
}
+static void filelist_read_library_flat(struct FileList *filelist)
+{
+ if (!filelist) return;
+ BLI_cleanup_dir(G.main->name, filelist->dir);
+ filelist_from_library(filelist);
+ if (!filelist->libfiledata) {
+ int num;
+ struct direntry *file;
+
+ printf("%s has no libfiledata\n", __func__);
+
+ BLI_make_exist(filelist->dir);
+ filelist_read_dir(filelist);
+ file = filelist->filelist;
+ for (num = 0; num < filelist->numfiles; num++, file++) {
+ if (BLO_has_bfile_extension(file->relname)) {
+ char name[FILE_MAX];
+
+ BLI_join_dirfile(name, sizeof(name), filelist->dir, file->relname);
+
+ /* prevent current file being used as acceptable dir */
+ if (BLI_path_cmp(G.main->name, name) != 0) {
+ file->type &= ~S_IFMT;
+ file->type |= S_IFDIR;
+ }
+ }
+ }
+ }
+ else {
+ struct direntry *file;
+ struct direntry *org_filelist = filelist->filelist;
+ int num, org_numfiles = filelist->numfiles;
+
+ char dir[FILE_MAX], group[BLO_GROUP_MAX];
+
+ BLI_assert(filelist_islibrary(filelist, dir, group));
+
+ printf("%s has libfiledata (%s)\n", __func__, group);
+
+ if (groupname_to_code(group)) {
+ /* We are at lowest possible level, nothing else to do. */
+ return;
+ }
+
+ file = org_filelist;
+ for (num = 0; num < org_numfiles; num++, file++) {
+ FileList *fl = filelist_new(FILE_LOADLIB);
+
+ char dir[FILE_MAX];
+
+ BLI_join_dirfile(dir, sizeof(dir), filelist->dir, file->relname);
+ filelist_setdir(fl, dir);
+ BLI_cleanup_dir(G.main->name, fl->dir);
+ filelist_from_library(fl);
+
+ if (fl->numfiles) {
+ int new_numfiles = fl->numfiles + filelist->numfiles;
+ struct direntry *new_filelist = malloc(sizeof(*new_filelist) * (size_t)new_numfiles);
+ struct direntry *f;
+ int i;
+
+ memcpy(&new_filelist[fl->numfiles], filelist->filelist, sizeof(*new_filelist) * filelist->numfiles);
+ for (i = 0, f = fl->filelist; i < fl->numfiles; i++, f++) {
+ printf("%s\n", file->relname);
+ BLI_join_dirfile(dir, sizeof(dir), fl->dir, file->relname);
+ BLI_cleanup_file(filelist->dir, dir);
+ printf("%s, %s, %s, %s\n", dir, fl->dir, file->relname, file->path);
+ new_filelist[i] = *f;
+ new_filelist[i].relname = BLI_strdup(dir);
+ //new_filelist[i].path = BLI_strdup(f->path);
+ /* those pointers are given to new_filelist... */
+ f->path = NULL;
+ f->poin = NULL;
+ f->image = NULL;
+ }
+
+ if (filelist->filelist != org_filelist) {
+ free(filelist->filelist);
+ }
+ filelist->filelist = new_filelist;
+ filelist->numfiles = new_numfiles;
+ }
+
+ filelist_free(fl);
+ }
+
+ if (filelist->filelist != org_filelist) {
+ free(org_filelist);
+ }
+
+ filelist_sort(filelist, FILE_SORT_ALPHA);
+
+ filelist->filter = 0;
+ filelist_filter(filelist);
+ }
+}
+
void filelist_readdir(struct FileList *filelist)
{
filelist->readf(filelist);
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index bdeb6e3..a98365c 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -208,6 +208,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0;
params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0;
params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0;
+ params->type = FILE_ASSET;
}
if (RNA_struct_find_property(op->ptr, "display_type"))
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 6489853..07ee542 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -666,6 +666,7 @@ enum FileSortTypeE {
#define FILE_LOADLIB 1
#define FILE_MAIN 2
#define FILE_LOADFONT 3
+#define FILE_ASSET 4
/* filesel op property -> action */
typedef enum eFileSel_Action {
More information about the Bf-blender-cvs
mailing list