[Bf-blender-cvs] [022d0ab2f83] asset-metadata: Add File Browser Link/Append option to show only assets

Julian Eisel noreply at git.blender.org
Fri Jul 10 16:58:03 CEST 2020


Commit: 022d0ab2f8393cfae4bd59ba065bde59bd960741
Author: Julian Eisel
Date:   Fri Jul 10 16:57:29 2020 +0200
Branches: asset-metadata
https://developer.blender.org/rB022d0ab2f8393cfae4bd59ba065bde59bd960741

Add File Browser Link/Append option to show only assets

===================================================================

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/intern/wm_operator_props.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 9a39d840149..95e6213eb00 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -154,6 +154,9 @@ class FILEBROWSER_PT_filter(Panel):
                 row.label(icon='BLANK1')  # Indentation
 
                 sub = row.column(align=True)
+
+                sub.prop(params, "use_filter_asset_only")
+
                 filter_id = params.filter_id
                 for identifier in dir(filter_id):
                     if identifier.startswith("category_"):
@@ -324,6 +327,9 @@ class FILEBROWSER_PT_advanced_filter(Panel):
             if params.use_filter_blendid:
                 layout.separator()
                 col = layout.column(align=True)
+
+                col.prop(params, "use_filter_asset_only")
+
                 filter_id = params.filter_id
                 for identifier in dir(filter_id):
                     if identifier.startswith("filter_"):
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index e4908eb7257..8065e2d63b3 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -120,12 +120,20 @@ void BLO_blendfiledata_free(BlendFileData *bfd);
 /** \name BLO Blend File Handle API
  * \{ */
 
+struct BLODataBlockInfo {
+  char name[64]; /* MAX_NAME */
+  bool is_asset;
+};
+
 BlendHandle *BLO_blendhandle_from_file(const char *filepath, struct ReportList *reports);
 BlendHandle *BLO_blendhandle_from_memory(const void *mem, int memsize);
 
 struct LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh,
                                                      int ofblocktype,
                                                      int *tot_names);
+struct LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh,
+                                                    int ofblocktype,
+                                                    int *tot_names);
 struct LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *tot_prev);
 struct LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh);
 
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index cb2094d050f..b9a7094f48e 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -160,6 +160,42 @@ LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype,
   return names;
 }
 
+/**
+ * Gets the names of all the data-blocks in a file of a certain type
+ * (e.g. all the scene names in a file).
+ *
+ * \param bh: The blendhandle to access.
+ * \param ofblocktype: The type of names to get.
+ * \param tot_names: The length of the returned list.
+ * \return A BLI_linklist of BLODataBlockInfo *. The links should be freed with MEM_freeN.
+ */
+LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, int ofblocktype, int *tot_names)
+{
+  FileData *fd = (FileData *)bh;
+  LinkNode *infos = NULL;
+  BHead *bhead;
+  int tot = 0;
+
+  for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
+    if (bhead->code == ofblocktype) {
+      struct BLODataBlockInfo *info = MEM_mallocN(sizeof(*info), __func__);
+      const char *name = blo_bhead_id_name(fd, bhead) + 2;
+
+      STRNCPY(info->name, name);
+      info->is_asset = blo_bhead_id_asset_data(fd, bhead) != NULL;
+
+      BLI_linklist_prepend(&infos, info);
+      tot++;
+    }
+    else if (bhead->code == ENDB) {
+      break;
+    }
+  }
+
+  *tot_names = tot;
+  return infos;
+}
+
 /**
  * Gets the previews of all the data-blocks in a file of a certain type
  * (e.g. all the scene previews in a file).
@@ -255,7 +291,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *to
  * (e.g. "Scene", "Mesh", "Light", etc.).
  *
  * \param bh: The blendhandle to access.
- * \return A BLI_linklist of strings. The string links should be freed with malloc.
+ * \return A BLI_linklist of strings. The string links should be freed with #MEM_freeN().
  */
 LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
 {
@@ -273,7 +309,7 @@ LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
         const char *str = BKE_idtype_idcode_to_name(bhead->code);
 
         if (BLI_gset_add(gathered, (void *)str)) {
-          BLI_linklist_prepend(&names, strdup(str));
+          BLI_linklist_prepend(&names, BLI_strdup(str));
         }
       }
     }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ee8616869f3..fb50d18a526 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1036,6 +1036,14 @@ const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead)
   return (const char *)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_name_offs);
 }
 
+/* Warning! Caller's responsibility to ensure given bhead **is** and ID one! */
+AssetData *blo_bhead_id_asset_data(const FileData *fd, const BHead *bhead)
+{
+  return (fd->id_asset_data_offs > 0) ?
+             *(AssetData **)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_asset_data_offs) :
+             NULL;
+}
+
 static void decode_blender_header(FileData *fd)
 {
   char header[SIZEOFBLENDERHEADER], num[4];
@@ -1110,6 +1118,7 @@ static bool read_file_dna(FileData *fd, const char **r_error_message)
         fd->compflags = DNA_struct_get_compareflags(fd->filesdna, fd->memsdna);
         /* used to retrieve ID names from (bhead+1) */
         fd->id_name_offs = DNA_elem_offset(fd->filesdna, "ID", "char", "name[]");
+        fd->id_asset_data_offs = DNA_elem_offset(fd->filesdna, "ID", "AssetData", "*asset_data");
 
         return true;
       }
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index f8c91c77634..d60bcf6a04f 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -107,6 +107,9 @@ typedef struct FileData {
   int fileversion;
   /** Used to retrieve ID names from (bhead+1). */
   int id_name_offs;
+  /** Used to retrieve asset data from (bhead+1). NOTE: This may not be available in old files,
+   * will be 0 then! */
+  int id_asset_data_offs;
   /** For do_versions patching. */
   int globalf, fileflags;
 
@@ -165,6 +168,7 @@ BHead *blo_bhead_next(FileData *fd, BHead *thisblock);
 BHead *blo_bhead_prev(FileData *fd, BHead *thisblock);
 
 const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead);
+struct AssetData *blo_bhead_id_asset_data(const FileData *fd, const BHead *bhead);
 
 /* do versions stuff */
 
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index cb785495ad5..a1b5178d070 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -208,6 +208,8 @@ typedef struct FileListInternEntry {
   int typeflag;
   /** ID type, in case typeflag has FILE_TYPE_BLENDERLIB set. */
   int blentype;
+  /** Tag for assets, in case typeflag has FILE_TYPE_BLENDERLIB set. */
+  bool is_asset;
 
   char *relpath;
   /** Optional argument for shortcuts, aliases etc. */
@@ -289,6 +291,7 @@ enum {
   FLF_HIDE_DOT = 1 << 1,
   FLF_HIDE_PARENT = 1 << 2,
   FLF_HIDE_LIB_DIR = 1 << 3,
+  FLF_ASSETS_ONLY = 1 << 4,
 };
 
 typedef struct FileList {
@@ -696,6 +699,9 @@ static bool is_filtered_hidden(const char *filename,
     return true;
   }
 #endif
+  if ((filter->flags & FLF_ASSETS_ONLY) && !file->is_asset) {
+    return true;
+  }
 
   return false;
 }
@@ -860,6 +866,7 @@ void filelist_setfilter_options(FileList *filelist,
                                 const bool hide_parent,
                                 const uint64_t filter,
                                 const uint64_t filter_id,
+                                const bool filter_assets_only,
                                 const char *filter_glob,
                                 const char *filter_search)
 {
@@ -877,6 +884,10 @@ void filelist_setfilter_options(FileList *filelist,
     filelist->filter_data.flags ^= FLF_HIDE_PARENT;
     update = true;
   }
+  if (((filelist->filter_data.flags & FLF_ASSETS_ONLY) != 0) != (filter_assets_only != 0)) {
+    filelist->filter_data.flags ^= FLF_ASSETS_ONLY;
+    update = true;
+  }
   if (filelist->filter_data.filter != filter) {
     filelist->filter_data.filter = filter;
     update = true;
@@ -2569,8 +2580,8 @@ static int filelist_readjob_list_dir(const char *root,
 static int filelist_readjob_list_lib(const char *root, ListBase *entries, const bool skip_currpar)
 {
   FileListInternEntry *entry;
-  LinkNode *ln, *names;
-  int i, nnames, idcode = 0, nbr_entries = 0;
+  LinkNode *ln, *names, *datablock_infos = NULL;
+  int i, nitems, idcode = 0, nbr_entries = 0;
   char dir[FILE_MAX_LIBEXTRA], *group;
   bool ok;
 
@@ -2592,11 +2603,11 @@ static int filelist_readjob_list_lib(const char *root, ListBase *entries, const
    * and freed in filelist_entry_free. */
   if (group) {
     idcode = groupname_to_code(group);
-    names = BLO_blendhandle_get_datablock_names(libfiledata, idcode, &nnames);
+    datablock_infos = BLO_blendhandle_get_datablock_info(libfiledata, idcode, &nitems);
   }
   else {
     names = BLO_blendhandle_get_linkable_groups(libfiledata);
-    nnames = BLI_linklist_count(names);
+    nitems = BLI_linklist_count(names);
   }
 
   BLO_blendhandle_close(libfiledata);
@@ -2609,12 +2620,14 @@ static int filelist_readjob_list_lib(const char *root, ListBase *entries, const
     nbr_entries++;
   }
 
-  for (i = 0, ln = names; i < nnames; i++, ln = ln->next) {
-    const char *blockname = ln->link;
+  for (i = 0, ln = (datablock_infos ? datablock_infos : names); i < nitems; i++, ln = ln->next) {
+    struct BLODataBlockInfo *info = datablock_infos ? ln->link : NULL;
+    const char *blockname = info ? info->name : ln->link;
 
     entry = MEM_callocN(sizeof(*entry), __func__);
     entry->relpath = BLI_strdup(blockname);
     entry->typef

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list