[Bf-blender-cvs] [45e7945b80b] asset-browser: Operator to create asset catalogs (aka smart-filters)
Julian Eisel
noreply at git.blender.org
Thu Oct 29 17:14:48 CET 2020
Commit: 45e7945b80bd1869b96fce8494ea5ee84dea3207
Author: Julian Eisel
Date: Thu Oct 29 16:22:59 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB45e7945b80bd1869b96fce8494ea5ee84dea3207
Operator to create asset catalogs (aka smart-filters)
A catalog at this stage is just a named item stored in a file's asset
repository meta-data.
With these changes one can create a named asset catalog that is written
to the file and can be read successfully.
===================================================================
M release/scripts/startup/bl_ui/space_filebrowser.py
M source/blender/blenkernel/BKE_asset.h
M source/blender/blenkernel/intern/asset.c
M source/blender/blenloader/intern/writefile.c
M source/blender/editors/asset/asset_ops.c
M source/blender/makesdna/DNA_asset_types.h
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 5828f602a0c..e03aa71662a 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -222,6 +222,10 @@ class FILEBROWSER_PT_asset_navigation_bar(Panel):
col.scale_y = 1.3
col.prop(space_file.params, "asset_category", expand=True)
+ col.separator()
+
+ col.operator("asset.catalog_add", text="Add Catalog", icon='ADD')
+
class FILEBROWSER_UL_dir(UIList):
def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index 43604b1cefe..b969bb42525 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -39,6 +39,9 @@ void BKE_asset_repository_info_global_free(void);
void BKE_asset_repository_info_update_for_file_read(struct AssetRepositoryInfo **repository_info);
#endif
+struct AssetCatalog *BKE_asset_repository_catalog_create(const char *name);
+void BKE_asset_repository_catalog_free(struct AssetCatalog *catalog);
+
struct AssetData *BKE_asset_data_create(void);
void BKE_asset_data_free(struct AssetData *asset_data);
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 5351cc1c8f0..a1f7556c2a2 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -49,6 +49,14 @@ AssetRepositoryInfo *BKE_asset_repository_info_global_ensure(void)
void BKE_asset_repository_info_free(AssetRepositoryInfo **repository_info)
{
+ if (!*repository_info) {
+ return;
+ }
+
+ LISTBASE_FOREACH_MUTABLE (AssetCatalog *, catalog, &(*repository_info)->catalogs) {
+ BLI_remlink(&(*repository_info)->catalogs, catalog);
+ BKE_asset_repository_catalog_free(catalog);
+ }
MEM_SAFE_FREE(*repository_info);
}
@@ -65,6 +73,19 @@ void BKE_asset_repository_info_update_for_file_read(AssetRepositoryInfo **old_re
#endif
+AssetCatalog *BKE_asset_repository_catalog_create(const char *name)
+{
+ AssetCatalog *catalog = MEM_callocN(sizeof(*catalog), __func__);
+
+ BLI_strncpy(catalog->name, name, sizeof(catalog->name));
+ return catalog;
+}
+
+void BKE_asset_repository_catalog_free(AssetCatalog *catalog)
+{
+ MEM_freeN(catalog);
+}
+
AssetData *BKE_asset_data_create(void)
{
AssetData *asset_data = MEM_callocN(sizeof(AssetData), __func__);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 3994d732135..18c2eeb275b 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2209,10 +2209,14 @@ static void write_thumb(WriteData *wd, const BlendThumbnail *thumb)
}
#ifdef WITH_ASSET_REPO_INFO
-static void write_asset_repository_info(WriteData *wd, const AssetRepositoryInfo *repository_info)
+static void write_asset_repository_info(BlendWriter *writer,
+ const AssetRepositoryInfo *repository_info)
{
if (repository_info) {
- writestruct(wd, ASSET_REPOSITORY_INFO, AssetRepositoryInfo, 1, repository_info);
+ writestruct(writer->wd, ASSET_REPOSITORY_INFO, AssetRepositoryInfo, 1, repository_info);
+ LISTBASE_FOREACH (const AssetCatalog *, catalog, &repository_info->catalogs) {
+ BLO_write_struct(writer, AssetCatalog, catalog);
+ }
}
}
#endif
@@ -2258,7 +2262,7 @@ static bool write_file_handle(Main *mainvar,
write_renderinfo(wd, mainvar);
write_thumb(wd, thumb);
#ifdef WITH_ASSET_REPO_INFO
- write_asset_repository_info(wd, repository_info);
+ write_asset_repository_info(&writer, repository_info);
#endif
write_global(wd, write_flags, mainvar);
diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.c
index ed4233973f3..fd174f40319 100644
--- a/source/blender/editors/asset/asset_ops.c
+++ b/source/blender/editors/asset/asset_ops.c
@@ -24,6 +24,9 @@
#include "BKE_lib_id.h"
#include "BKE_report.h"
+#include "BLI_listbase.h"
+#include "BLI_string_utils.h"
+
#include "DNA_asset_types.h"
#include "ED_asset.h"
@@ -83,9 +86,50 @@ static void ASSET_OT_make(wmOperatorType *ot)
ot->srna, "id", &RNA_ID, "Data-block", "Data-block to enable asset management for");
}
+static int asset_catalog_add_exec(bContext *C, wmOperator *op)
+{
+ AssetRepositoryInfo *repository_info = BKE_asset_repository_info_global_ensure();
+ char name[MAX_NAME];
+
+ RNA_string_get(op->ptr, "name", name);
+
+ AssetCatalog *catalog = BKE_asset_repository_catalog_create(name);
+ BLI_addtail(&repository_info->catalogs, catalog);
+ BLI_uniquename(&repository_info->catalogs,
+ catalog,
+ name,
+ '.',
+ offsetof(AssetCatalog, name),
+ sizeof(catalog->name));
+
+ /* Use WM notifier for now to denote a global data change. */
+ WM_event_add_notifier(C, NC_WM | ND_DATACHANGED, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ASSET_OT_catalog_add(wmOperatorType *ot)
+{
+ ot->name = "Add Asset Catalog";
+ ot->description =
+ "Create a new asset catalog (a preset of filter settings to define which assets to display)";
+ ot->idname = "ASSET_OT_catalog_add";
+
+ /* TODO Popup should be removed once there's a proper UI to show and edit the catalog names. */
+ ot->invoke = WM_operator_props_popup_confirm;
+ ot->exec = asset_catalog_add_exec;
+
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_string(
+ ot->srna, "name", "Catalog", MAX_NAME, "Name", "Custom identifier for the catalog");
+}
+
/* -------------------------------------------------------------------- */
void ED_operatortypes_asset(void)
{
WM_operatortype_append(ASSET_OT_make);
+
+ WM_operatortype_append(ASSET_OT_catalog_add);
}
diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h
index cfec1a9eafd..70097369564 100644
--- a/source/blender/makesdna/DNA_asset_types.h
+++ b/source/blender/makesdna/DNA_asset_types.h
@@ -35,6 +35,8 @@ typedef struct CustomTag {
#ifdef WITH_ASSET_REPO_INFO
typedef struct AssetCatalog {
+ struct AssetCatalog *next, *prev;
+
char name[64]; /* MAX_NAME */
} AssetCatalog;
More information about the Bf-blender-cvs
mailing list