[Bf-blender-cvs] [9e3ac31aa5c] asset-browser: Asset Browser: "Make Asset" operator and UI integration

Julian Eisel noreply at git.blender.org
Thu Dec 3 01:58:53 CET 2020


Commit: 9e3ac31aa5cbe7e202213a9a061984523462bde8
Author: Julian Eisel
Date:   Wed Dec 2 16:42:17 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB9e3ac31aa5cbe7e202213a9a061984523462bde8

Asset Browser: "Make Asset" operator and UI integration

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

M	doc/doxygen/doxygen.source.h
M	release/scripts/startup/bl_ui/properties_material.py
M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/BKE_icons.h
M	source/blender/blenkernel/intern/asset.c
M	source/blender/blenkernel/intern/context.c
M	source/blender/blenkernel/intern/icons.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/CMakeLists.txt
A	source/blender/editors/asset/CMakeLists.txt
A	source/blender/editors/asset/asset_edit.c
A	source/blender/editors/asset/asset_ops.c
A	source/blender/editors/include/ED_asset.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_context_menu.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/space_outliner/CMakeLists.txt
A	source/blender/editors/space_outliner/outliner_context.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/space_outliner/space_outliner.c
M	source/blender/editors/util/CMakeLists.txt
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/windowmanager/WM_types.h

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

diff --git a/doc/doxygen/doxygen.source.h b/doc/doxygen/doxygen.source.h
index 613e513bcc6..510f3fe8ffe 100644
--- a/doc/doxygen/doxygen.source.h
+++ b/doc/doxygen/doxygen.source.h
@@ -121,6 +121,10 @@
  *  \ingroup editors
  */
 
+/** \defgroup edasset asset
+ *  \ingroup editors
+ */
+
 /** \defgroup edcurve curve
  *  \ingroup editors
  */
diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py
index 6aaec9940e8..cd6bebfea94 100644
--- a/release/scripts/startup/bl_ui/properties_material.py
+++ b/release/scripts/startup/bl_ui/properties_material.py
@@ -42,6 +42,9 @@ class MATERIAL_UL_matslots(UIList):
         # ob = data
         slot = item
         ma = slot.material
+
+        layout.context_pointer_set("focused_id", ma)
+
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             if ma:
                 layout.prop(ma, "name", text="", emboss=False, icon_value=icon)
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index edd49dd9851..20df6109c13 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -46,6 +46,9 @@ struct AssetTagEnsureResult BKE_asset_metadata_tag_ensure(struct AssetMetaData *
                                                           const char *name);
 void BKE_asset_metadata_tag_remove(struct AssetMetaData *asset_data, struct AssetTag *tag);
 
+struct PreviewImage *BKE_asset_metadata_preview_get_from_id(const struct AssetMetaData *asset_data,
+                                                            const struct ID *owner_id);
+
 void BKE_asset_metadata_write(struct BlendWriter *writer, struct AssetMetaData *asset_data);
 void BKE_asset_metadata_read(struct BlendDataReader *reader, struct AssetMetaData *asset_data);
 
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 5c534803781..94392dd78da 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -143,8 +143,9 @@ bContext *CTX_copy(const bContext *C);
 
 /* Stored Context */
 
-bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr);
+bContextStore *CTX_store_add(ListBase *contexts, const char *name, const PointerRNA *ptr);
 bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context);
+bContextStore *CTX_store_get(bContext *C);
 void CTX_store_set(bContext *C, bContextStore *store);
 bContextStore *CTX_store_copy(bContextStore *store);
 void CTX_store_free(bContextStore *store);
@@ -288,6 +289,9 @@ enum eContextObjectMode CTX_data_mode_enum(const bContext *C);
 void CTX_data_main_set(bContext *C, struct Main *bmain);
 void CTX_data_scene_set(bContext *C, struct Scene *scene);
 
+/* Only Outliner currently! */
+int CTX_data_selected_ids(const bContext *C, ListBase *list);
+
 int CTX_data_selected_editable_objects(const bContext *C, ListBase *list);
 int CTX_data_selected_editable_bases(const bContext *C, ListBase *list);
 
diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h
index d6cf5eae323..9452717539c 100644
--- a/source/blender/blenkernel/BKE_icons.h
+++ b/source/blender/blenkernel/BKE_icons.h
@@ -129,6 +129,8 @@ void BKE_previewimg_clear_single(struct PreviewImage *prv, enum eIconSizes size)
 
 /* get the preview from any pointer */
 struct PreviewImage **BKE_previewimg_id_get_p(const struct ID *id);
+struct PreviewImage *BKE_previewimg_id_get(const struct ID *id);
+
 
 /* free the preview image belonging to the id */
 void BKE_previewimg_id_free(struct ID *id);
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 37fbf9a2837..c68e4106fcc 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -104,6 +104,14 @@ void BKE_asset_metadata_tag_remove(AssetMetaData *asset_data, AssetTag *tag)
   BLI_freelinkN(&asset_data->tags, tag);
 }
 
+/* Queries -------------------------------------------- */
+
+PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *UNUSED(asset_data),
+                                                     const ID *id)
+{
+  return BKE_previewimg_id_get(id);
+}
+
 /* .blend file API -------------------------------------------- */
 
 void BKE_asset_metadata_write(BlendWriter *writer, AssetMetaData *asset_data)
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index a1edfd1c56d..65accc66084 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -123,7 +123,7 @@ void CTX_free(bContext *C)
 
 /* store */
 
-bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr)
+bContextStore *CTX_store_add(ListBase *contexts, const char *name, const PointerRNA *ptr)
 {
   /* ensure we have a context to put the entry in, if it was already used
    * we have to copy the context to ensure */
@@ -178,6 +178,11 @@ bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context)
   return ctx;
 }
 
+bContextStore *CTX_store_get(bContext *C)
+{
+  return C->wm.store;
+}
+
 void CTX_store_set(bContext *C, bContextStore *store)
 {
   C->wm.store = store;
@@ -1202,6 +1207,11 @@ ToolSettings *CTX_data_tool_settings(const bContext *C)
   return NULL;
 }
 
+int CTX_data_selected_ids(const bContext *C, ListBase *list)
+{
+  return ctx_data_collection_get(C, "selected_ids", list);
+}
+
 int CTX_data_selected_nodes(const bContext *C, ListBase *list)
 {
   return ctx_data_collection_get(C, "selected_nodes", list);
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index eec9013d067..a2e251afc45 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -342,6 +342,12 @@ PreviewImage **BKE_previewimg_id_get_p(const ID *id)
   return NULL;
 }
 
+PreviewImage *BKE_previewimg_id_get(const ID *id)
+{
+  PreviewImage **prv_p = BKE_previewimg_id_get_p(id);
+  return prv_p ? *prv_p : NULL;
+}
+
 void BKE_previewimg_id_free(ID *id)
 {
   PreviewImage **prv_p = BKE_previewimg_id_get_p(id);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 11fe240620a..a28072ba4d4 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -93,6 +93,7 @@
 /* allow writefile to use deprecated functionality (for forward compatibility code) */
 #define DNA_DEPRECATED_ALLOW
 
+#include "DNA_asset_types.h"
 #include "DNA_fileglobal_types.h"
 #include "DNA_genfile.h"
 #include "DNA_sdna_types.h"
diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt
index 1f5dc73f732..a2ae350ce4b 100644
--- a/source/blender/editors/CMakeLists.txt
+++ b/source/blender/editors/CMakeLists.txt
@@ -22,6 +22,7 @@ if(WITH_BLENDER)
 
   add_subdirectory(animation)
   add_subdirectory(armature)
+  add_subdirectory(asset)
   add_subdirectory(curve)
   add_subdirectory(geometry)
   add_subdirectory(gizmo_library)
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
new file mode 100644
index 00000000000..63a1761b264
--- /dev/null
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -0,0 +1,39 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+    ../include
+    ../../blenlib
+    ../../blenkernel
+    ../../makesdna
+    ../../makesrna
+    ../../windowmanager
+    ../../../../intern/guardedalloc
+)
+
+set(INC_SYS
+)
+
+set(SRC
+  asset_edit.c
+  asset_ops.c
+)
+
+set(LIB
+)
+
+blender_add_lib(bf_editor_asset "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/asset/asset_edit.c b/source/blender/editors/asset/asset_edit.c
new file mode 100644
index 00000000000..ab4f40cca98
--- /dev/null
+++ b/source/blender/editors/asset/asset_edit.c
@@ -0,0 +1,53 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#include "BKE_asset.h"
+#include "BKE_context.h"
+#include "BKE_lib_id.h"
+
+#include "DNA_ID.h"
+#include "DNA_asset_types.h"
+
+#include "UI_interface_icons.h"
+
+#include "RNA_access.h"
+
+#include "ED_asset.h"
+
+bool ED_asset_make_for_id(const bContext *C, ID *id)
+{
+  if (id->asset_data) {
+    return false;
+  }
+
+  id_fake_user_set(id);
+
+  id->asset_data = BKE_asset_metadata_create();
+
+  UI_icon_render_id(C, NULL, id, true, true);
+
+  return true;
+}
+
+bool ED_asset_can_make_single_from_context(const bContext *C)
+{
+  /* Context needs a "focused_id" pointer to be set for #ASSET_OT_make() to use. */
+  return CTX_data_pointer_get_type_silent(C, "focused_id", &RNA_ID).

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list