[Bf-blender-cvs] [1ea095c2563] asset-browser: Sync with review branches

Julian Eisel noreply at git.blender.org
Thu Dec 3 01:43:32 CET 2020


Commit: 1ea095c256337db4651172025dfdb31358e321c5
Author: Julian Eisel
Date:   Thu Dec 3 01:42:16 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB1ea095c256337db4651172025dfdb31358e321c5

Sync with review branches

Some minor changes (mostly cleanups) done while splitting up the branch for review.

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

M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/asset/asset_ops.c
M	source/blender/makesdna/DNA_ID.h

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

diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index 30743fed598..20df6109c13 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -32,9 +32,6 @@ struct BlendDataReader;
 struct ID;
 struct PreviewImage;
 
-struct AssetCatalog *BKE_asset_repository_catalog_create(const char *name);
-void BKE_asset_repository_catalog_free(struct AssetCatalog **catalog);
-
 struct AssetMetaData *BKE_asset_metadata_create(void);
 void BKE_asset_metadata_free(struct AssetMetaData **asset_data);
 
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index f5eddc6ea02..21e76d679a4 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -160,8 +160,8 @@ LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype,
 }
 
 /**
- * Gets the names of all the data-blocks in a file of a certain type
- * (e.g. all the scene names in a file).
+ * Gets the names and asset-data (if ID is an asset) 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.
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 4502e6f9006..fa1077469b3 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -44,9 +44,7 @@
 #define DNA_DEPRECATED_ALLOW
 
 #include "DNA_anim_types.h"
-#include "DNA_armature_types.h"
 #include "DNA_asset_types.h"
-#include "DNA_brush_types.h"
 #include "DNA_cachefile_types.h"
 #include "DNA_fileglobal_types.h"
 #include "DNA_genfile.h"
@@ -74,9 +72,7 @@
 
 #include "BKE_anim_data.h"
 #include "BKE_animsys.h"
-#include "BKE_armature.h"
 #include "BKE_asset.h"
-#include "BKE_brush.h"
 #include "BKE_collection.h"
 #include "BKE_global.h" /* for G */
 #include "BKE_idprop.h"
diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.c
index a6a43d8c208..10010b6485e 100644
--- a/source/blender/editors/asset/asset_ops.c
+++ b/source/blender/editors/asset/asset_ops.c
@@ -18,6 +18,8 @@
  * \ingroup edasset
  */
 
+#include <string.h>
+
 #include "BKE_asset.h"
 #include "BKE_context.h"
 #include "BKE_report.h"
@@ -37,6 +39,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+/* -------------------------------------------------------------------- */
+
 /**
  * Return the IDs to operate on as list of #CollectionPointerLink links. Needs freeing.
  */
@@ -58,70 +62,61 @@ static ListBase asset_make_get_ids_from_context(const bContext *C)
   return list;
 }
 
-static bool asset_make_poll(bContext *C)
+struct AssetMakeResultStats {
+  int tot_created;
+  int tot_selected_ids;
+  int tot_already_asset;
+  ID *last_id;
+};
+
+static void asset_make_for_idptr_list(const bContext *C,
+                                      const ListBase *ids,
+                                      struct AssetMakeResultStats *r_stats)
 {
-  ListBase ids = asset_make_get_ids_from_context(C);
+  memset(r_stats, 0, sizeof(*r_stats));
 
-  int tot_selected = 0;
-  bool can_make_asset = false;
+  LISTBASE_FOREACH (CollectionPointerLink *, ctx_id, ids) {
+    BLI_assert(RNA_struct_is_ID(ctx_id->ptr.type));
+    r_stats->tot_selected_ids++;
 
-  /* Note that this isn't entirely cheap. Iterates over entire Outliner tree and allocates a link
-   * for each selected item. The button only shows in the context menu though, so acceptable. */
-  LISTBASE_FOREACH (CollectionPointerLink *, ctx_id, &ids) {
     ID *id = ctx_id->ptr.data;
-
-    tot_selected++;
-    if (!id->asset_data) {
-      can_make_asset = true;
-      break;
+    if (id->asset_data) {
+      r_stats->tot_already_asset++;
+      continue;
     }
-  }
-  BLI_freelistN(&ids);
 
-  if (!can_make_asset) {
-    if (tot_selected > 0) {
-      CTX_wm_operator_poll_msg_set(C, "Selected data-blocks are already assets.");
-    }
-    else {
-      CTX_wm_operator_poll_msg_set(C, "No data-blocks selected");
-    }
-    return false;
-  }
+    ED_asset_make_for_id(C, id);
 
-  return true;
+    r_stats->last_id = id;
+    r_stats->tot_created++;
+  }
 }
 
 static int asset_make_exec(bContext *C, wmOperator *op)
 {
   ListBase ids = asset_make_get_ids_from_context(C);
 
-  ID *last_id = NULL;
-  int tot_created = 0;
-
-  LISTBASE_FOREACH (CollectionPointerLink *, ctx_id, &ids) {
-    ID *id = ctx_id->ptr.data;
-    BLI_assert(RNA_struct_is_ID(ctx_id->ptr.type));
-    if (id->asset_data) {
-      continue;
-    }
-
-    ED_asset_make_for_id(C, id);
-    last_id = id;
-    tot_created++;
-  }
+  struct AssetMakeResultStats stats;
+  asset_make_for_idptr_list(C, &ids, &stats);
   BLI_freelistN(&ids);
 
-  /* User feedback. */
-  if (tot_created < 1) {
+  /* User feedback on failure. */
+  if ((stats.tot_created < 1) && (stats.tot_already_asset > 0)) {
+    BKE_report(op->reports, RPT_ERROR, "Selected data-blocks are already assets");
+    return OPERATOR_CANCELLED;
+  }
+  if (stats.tot_created < 1) {
     BKE_report(op->reports, RPT_ERROR, "No data-blocks to create assets for found");
     return OPERATOR_CANCELLED;
   }
-  if (tot_created == 1) {
+
+  /* User feedback on success. */
+  if (stats.tot_created == 1) {
     /* If only one data-block: Give more useful message by printing asset name. */
-    BKE_reportf(op->reports, RPT_INFO, "Data-block '%s' is now an asset", last_id->name + 2);
+    BKE_reportf(op->reports, RPT_INFO, "Data-block '%s' is now an asset", stats.last_id->name + 2);
   }
   else {
-    BKE_reportf(op->reports, RPT_INFO, "%i data-blocks are now assets", tot_created);
+    BKE_reportf(op->reports, RPT_INFO, "%i data-blocks are now assets", stats.tot_created);
   }
 
   WM_main_add_notifier(NC_ID | NA_EDITED, NULL);
@@ -136,7 +131,6 @@ static void ASSET_OT_make(wmOperatorType *ot)
   ot->description = "Enable asset management for a data-block";
   ot->idname = "ASSET_OT_make";
 
-  ot->poll = asset_make_poll;
   ot->exec = asset_make_exec;
 
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 24cf290f5f3..5625c1beb0c 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -267,9 +267,7 @@ typedef struct ID {
 
   struct Library *lib;
 
-  /** If this ID is an asset, this pointer is set and references all data defining an asset. */
-  /* TODO this will probably not stay here. Instead we might want a new asset ID-type that
-   * references another ID. */
+  /** If the ID is an asset, this pointer is set. Owning pointer. */
   struct AssetMetaData *asset_data;
 
   /** MAX_ID_NAME. */



More information about the Bf-blender-cvs mailing list