[Bf-blender-cvs] [7898089de3f] master: Assets: Add an active asset library per workspace, for the UI to use

Julian Eisel noreply at git.blender.org
Thu Jul 15 16:14:24 CEST 2021


Commit: 7898089de3f20b08a08516bd2fd2be7dd1c565fe
Author: Julian Eisel
Date:   Thu Jul 8 22:16:50 2021 +0200
Branches: master
https://developer.blender.org/rB7898089de3f20b08a08516bd2fd2be7dd1c565fe

Assets: Add an active asset library per workspace, for the UI to use

This per-workspace active asset library will be used by the asset views
later. Note that Asset Browsers have their own active asset library,
overriding the one from the workspace.

As part of this the `FileSelectAssetLibraryUID` type gets replaced by
`AssetLibraryReference` which is on the asset level now, not the
File/Asset Browser level. But some more work is needed to complete that,
which is better done in a separate commit.
This also moves the asset library from/to enum-value logic from RNA to
the editor asset level, which will later be used by the asset view.

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

M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/intern/asset.cc
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/editors/asset/CMakeLists.txt
M	source/blender/editors/asset/asset_edit.cc
M	source/blender/editors/include/ED_asset.h
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/makesdna/DNA_asset_defaults.h
M	source/blender/makesdna/DNA_asset_types.h
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesdna/DNA_workspace_types.h
M	source/blender/makesdna/intern/dna_defaults.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_asset.c
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_workspace.c

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

diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index d1f543b1f38..50eb2859279 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -26,6 +26,7 @@
 extern "C" {
 #endif
 
+struct AssetLibraryReference;
 struct BlendDataReader;
 struct BlendWriter;
 struct ID;
@@ -45,6 +46,8 @@ 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);
 
+void BKE_asset_library_reference_init_default(struct AssetLibraryReference *library_ref);
+
 struct PreviewImage *BKE_asset_metadata_preview_get_from_id(const struct AssetMetaData *asset_data,
                                                             const struct ID *owner_id);
 
diff --git a/source/blender/blenkernel/intern/asset.cc b/source/blender/blenkernel/intern/asset.cc
index b5a7f5e37a6..f74018b20c5 100644
--- a/source/blender/blenkernel/intern/asset.cc
+++ b/source/blender/blenkernel/intern/asset.cc
@@ -110,6 +110,11 @@ void BKE_asset_metadata_tag_remove(AssetMetaData *asset_data, AssetTag *tag)
   BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags);
 }
 
+void BKE_asset_library_reference_init_default(AssetLibraryReference *library_ref)
+{
+  memcpy(library_ref, DNA_struct_default_get(AssetLibraryReference), sizeof(*library_ref));
+}
+
 /* Queries -------------------------------------------- */
 
 PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *UNUSED(asset_data),
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 533107b2bf6..5cac149c503 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -29,6 +29,7 @@
 
 #include "BLT_translation.h"
 
+#include "BKE_asset.h"
 #include "BKE_global.h"
 #include "BKE_idprop.h"
 #include "BKE_idtype.h"
@@ -53,6 +54,13 @@
 
 /* -------------------------------------------------------------------- */
 
+static void workspace_init_data(ID *id)
+{
+  WorkSpace *workspace = (WorkSpace *)id;
+
+  BKE_asset_library_reference_init_default(&workspace->active_asset_library);
+}
+
 static void workspace_free_data(ID *id)
 {
   WorkSpace *workspace = (WorkSpace *)id;
@@ -180,7 +188,7 @@ IDTypeInfo IDType_ID_WS = {
     .translation_context = BLT_I18NCONTEXT_ID_WORKSPACE,
     .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_NO_MAKELOCAL | IDTYPE_FLAGS_NO_ANIMDATA,
 
-    .init_data = NULL,
+    .init_data = workspace_init_data,
     .copy_data = NULL,
     .free_data = workspace_free_data,
     .make_local = NULL,
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 3c58c29c162..d36c622c572 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -33,9 +33,11 @@
 #include "DNA_listBase.h"
 #include "DNA_modifier_types.h"
 #include "DNA_text_types.h"
+#include "DNA_workspace_types.h"
 
 #include "BKE_action.h"
 #include "BKE_animsys.h"
+#include "BKE_asset.h"
 #include "BKE_collection.h"
 #include "BKE_deform.h"
 #include "BKE_fcurve_driver.h"
@@ -517,6 +519,15 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
       }
     }
     FOREACH_NODETREE_END;
+
+    {
+      if (!DNA_struct_elem_find(
+              fd->filesdna, "WorkSpace", "AssetLibraryReference", "active_asset_library")) {
+        LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
+          BKE_asset_library_reference_init_default(&workspace->active_asset_library);
+        }
+      }
+    }
   }
 
   if (!MAIN_VERSION_ATLEAST(bmain, 300, 10)) {
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index 8c5f91561b7..794e64fa420 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -19,6 +19,7 @@ set(INC
     ../include
     ../../blenkernel
     ../../blenlib
+    ../../blenloader
     ../../makesdna
     ../../makesrna
     ../../windowmanager
@@ -34,6 +35,7 @@ set(SRC
 )
 
 set(LIB
+  bf_blenloader
 )
 
 blender_add_lib(bf_editor_asset "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/asset/asset_edit.cc b/source/blender/editors/asset/asset_edit.cc
index d20de4141cb..5ae07a54b11 100644
--- a/source/blender/editors/asset/asset_edit.cc
+++ b/source/blender/editors/asset/asset_edit.cc
@@ -65,3 +65,56 @@ bool ED_asset_can_make_single_from_context(const bContext *C)
   /* Context needs a "id" pointer to be set for #ASSET_OT_mark()/#ASSET_OT_clear() to use. */
   return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != nullptr;
 }
+
+/* TODO better place? */
+/* TODO What about the setter and the itemf? */
+#include "BKE_preferences.h"
+#include "DNA_asset_types.h"
+#include "DNA_userdef_types.h"
+int ED_asset_library_reference_to_enum_value(const AssetLibraryReference *library)
+{
+  /* Simple case: Predefined repo, just set the value. */
+  if (library->type < ASSET_LIBRARY_CUSTOM) {
+    return library->type;
+  }
+
+  /* Note that the path isn't checked for validity here. If an invalid library path is used, the
+   * Asset Browser can give a nice hint on what's wrong. */
+  const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index(
+      &U, library->custom_library_index);
+  if (user_library) {
+    return ASSET_LIBRARY_CUSTOM + library->custom_library_index;
+  }
+
+  BLI_assert(0);
+  return ASSET_LIBRARY_LOCAL;
+}
+
+AssetLibraryReference ED_asset_library_reference_from_enum_value(int value)
+{
+  AssetLibraryReference library;
+
+  /* Simple case: Predefined repo, just set the value. */
+  if (value < ASSET_LIBRARY_CUSTOM) {
+    library.type = value;
+    library.custom_library_index = -1;
+    BLI_assert(ELEM(value, ASSET_LIBRARY_LOCAL));
+    return library;
+  }
+
+  const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index(
+      &U, value - ASSET_LIBRARY_CUSTOM);
+
+  /* Note that the path isn't checked for validity here. If an invalid library path is used, the
+   * Asset Browser can give a nice hint on what's wrong. */
+  const bool is_valid = (user_library->name[0] && user_library->path[0]);
+  if (!user_library) {
+    library.type = ASSET_LIBRARY_LOCAL;
+    library.custom_library_index = -1;
+  }
+  else if (user_library && is_valid) {
+    library.custom_library_index = value - ASSET_LIBRARY_CUSTOM;
+    library.type = ASSET_LIBRARY_CUSTOM;
+  }
+  return library;
+}
diff --git a/source/blender/editors/include/ED_asset.h b/source/blender/editors/include/ED_asset.h
index dd505167fe5..a2ef0755fbd 100644
--- a/source/blender/editors/include/ED_asset.h
+++ b/source/blender/editors/include/ED_asset.h
@@ -24,11 +24,17 @@
 extern "C" {
 #endif
 
+struct AssetLibraryReference;
+struct bContext;
+
 bool ED_asset_mark_id(const struct bContext *C, struct ID *id);
 bool ED_asset_clear_id(struct ID *id);
 
 bool ED_asset_can_make_single_from_context(const struct bContext *C);
 
+int ED_asset_library_reference_to_enum_value(const struct AssetLibraryReference *library);
+struct AssetLibraryReference ED_asset_library_reference_from_enum_value(int value);
+
 void ED_operatortypes_asset(void);
 
 #ifdef __cplusplus
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index faa4b3cc9cc..a314a85491d 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -1105,7 +1105,7 @@ bool file_draw_hint_if_invalid(const SpaceFile *sfile, const ARegion *region)
     return false;
   }
   /* Check if the library exists. */
-  if ((asset_params->asset_library.type == FILE_ASSET_LIBRARY_LOCAL) ||
+  if ((asset_params->asset_library.type == ASSET_LIBRARY_LOCAL) ||
       filelist_is_dir(sfile->files, asset_params->base_params.dir)) {
     return false;
   }
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 0e15538e03b..c4b895dc54d 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1050,7 +1050,7 @@ static bool filelist_compare_asset_libraries(const FileSelectAssetLibraryUID *li
   if (library_a->type != library_b->type) {
     return false;
   }
-  if (library_a->type == FILE_ASSET_LIBRARY_CUSTOM) {
+  if (library_a->type == ASSET_LIBRARY_CUSTOM) {
     /* Don't only check the index, also check that it's valid. */
     bUserAssetLibrary *library_ptr_a = BKE_preferences_asset_library_find_from_index(
         &U, library_a->custom_library_index);
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 7ab93df81d2..7bc83e8fc79 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -118,7 +118,7 @@ static void fileselect_ensure_updated_asset_params(SpaceFile *sfile)
     asset_params = sfile->asset_params = MEM_callocN(sizeof(*asset_params),
                                                      "FileAssetSelectParams");
     asset_params->base_params.details_flags = U_default.file_space_data.details_flags;
-    asset_params->asset_library.type = FILE_ASSET_LIBRARY_LOCAL;
+    asset_params->asset_library.type = ASSET_LIBRARY_LOCAL;
     asset_params->asset_library.custom_library_index = -1;
     asset_params->import_type = FILE_ASSET_IMPORT_APPEND;
   }
@@ -420,26 +420,26 @@ static void fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
   bUserAssetLibrary *user_library = NULL;
 
   /* Ensure valid repository, or fall-back to local one. */
-  if (library->type == FILE_ASSET_LIBRARY_CUSTOM) {
+  if (library->type == ASSET_LIBRARY_CUSTOM) {
     BLI_assert(library->custom_library_index >= 0);
 
     user_library = BKE_preferences_asset_library_find_from_index(&U,
                                                                  library->custom_library_index);
     if (!user_library

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list