[Bf-blender-cvs] [371325141da] temp-asset-browser-poselib-merge: Assets: Expose active asset library in context

Julian Eisel noreply at git.blender.org
Wed Jul 14 22:53:08 CEST 2021


Commit: 371325141da0046ba3a1ae08d93b8ce37ba2c3ac
Author: Julian Eisel
Date:   Thu Jul 8 22:33:02 2021 +0200
Branches: temp-asset-browser-poselib-merge
https://developer.blender.org/rB371325141da0046ba3a1ae08d93b8ce37ba2c3ac

Assets: Expose active asset library in context

For the Asset Browser, this returns the active asset library of the
Asset Browser, otherwise it returns the one active in the workspace.

This gives simple access to the active asset library from UI code and
Python scripts. For example the upcoming Pose Library add-on uses this,
as well as the upcoming asset view template.

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

M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/editors/screen/screen_context.c
M	source/blender/editors/space_file/space_file.c

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

diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 50aa6027840..416947e0b62 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -357,6 +357,8 @@ int CTX_data_visible_gpencil_layers(const bContext *C, ListBase *list);
 int CTX_data_editable_gpencil_layers(const bContext *C, ListBase *list);
 int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
 
+const struct AssetLibraryReference *CTX_wm_asset_library(const bContext *C);
+
 bool CTX_wm_interface_locked(const bContext *C);
 
 /* Gets pointer to the dependency graph.
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 1028790856c..4c91a3f3387 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1448,6 +1448,11 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list)
   return ctx_data_collection_get(C, "editable_gpencil_strokes", list);
 }
 
+const AssetLibraryReference *CTX_wm_asset_library(const bContext *C)
+{
+  return ctx_data_pointer_get(C, "asset_library");
+}
+
 Depsgraph *CTX_data_depsgraph_pointer(const bContext *C)
 {
   Main *bmain = CTX_data_main(C);
diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c
index d50962a56a9..ece6ba986f3 100644
--- a/source/blender/editors/screen/screen_context.c
+++ b/source/blender/editors/screen/screen_context.c
@@ -36,6 +36,7 @@
 #include "DNA_sequence_types.h"
 #include "DNA_space_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
 
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
@@ -111,6 +112,7 @@ const char *screen_context_dir[] = {
     "selected_editable_fcurves",
     "active_editable_fcurve",
     "selected_editable_keyframes",
+    "asset_library",
     NULL,
 };
 
@@ -1024,6 +1026,14 @@ static eContextResult screen_ctx_selected_editable_keyframes(const bContext *C,
   return CTX_RESULT_NO_DATA;
 }
 
+static eContextResult screen_ctx_asset_library(const bContext *C, bContextDataResult *result)
+{
+  WorkSpace *workspace = CTX_wm_workspace(C);
+  CTX_data_pointer_set(
+      result, &workspace->id, &RNA_AssetLibraryReference, &workspace->active_asset_library);
+  return CTX_RESULT_OK;
+}
+
 /* Registry of context callback functions. */
 
 typedef eContextResult (*context_callback)(const bContext *C, bContextDataResult *result);
@@ -1098,6 +1108,7 @@ static void ensure_ed_screen_context_functions(void)
   register_context_function("selected_visible_fcurves", screen_ctx_selected_visible_fcurves);
   register_context_function("active_editable_fcurve", screen_ctx_active_editable_fcurve);
   register_context_function("selected_editable_keyframes", screen_ctx_selected_editable_keyframes);
+  register_context_function("asset_library", screen_ctx_asset_library);
 }
 
 /* Entry point for the screen context. */
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 05d484d8e2e..e71c00e2312 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -868,7 +868,12 @@ static void file_space_subtype_item_extend(bContext *UNUSED(C),
   }
 }
 
-static const char *file_context_dir[] = {"active_file", "id", NULL};
+static const char *file_context_dir[] = {
+    "active_file",
+    "asset_library",
+    "id",
+    NULL,
+};
 
 static int /*eContextResult*/ file_context(const bContext *C,
                                            const char *member,
@@ -899,6 +904,23 @@ static int /*eContextResult*/ file_context(const bContext *C,
     CTX_data_pointer_set(result, &screen->id, &RNA_FileSelectEntry, file);
     return CTX_RESULT_OK;
   }
+  if (CTX_data_equals(member, "asset_library")) {
+    FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
+    if (!asset_params) {
+      return CTX_RESULT_NO_DATA;
+    }
+
+    BLI_STATIC_ASSERT(offsetof(FileSelectAssetLibraryUID, type) ==
+                          offsetof(AssetLibraryReference, type),
+                      "Expected FileSelectAssetLibraryUID to match AssetLibraryReference");
+    BLI_STATIC_ASSERT(offsetof(FileSelectAssetLibraryUID, custom_library_index) ==
+                          offsetof(AssetLibraryReference, custom_library_index),
+                      "Expected FileSelectAssetLibraryUID to match AssetLibraryReference");
+
+    CTX_data_pointer_set(
+        result, &screen->id, &RNA_AssetLibraryReference, &asset_params->asset_library);
+    return CTX_RESULT_OK;
+  }
   if (CTX_data_equals(member, "id")) {
     const FileDirEntry *file = filelist_file(sfile->files, params->active_file);
     if (file == NULL) {



More information about the Bf-blender-cvs mailing list