[Bf-blender-cvs] [378e0d96fca] blender-projects-basics: Make custom asset libraries independent of Preferences

Julian Eisel noreply at git.blender.org
Wed Oct 12 16:31:31 CEST 2022


Commit: 378e0d96fcab0e03bc8763669eca76ad6e11d732
Author: Julian Eisel
Date:   Wed Oct 12 16:00:20 2022 +0200
Branches: blender-projects-basics
https://developer.blender.org/rB378e0d96fcab0e03bc8763669eca76ad6e11d732

Make custom asset libraries independent of Preferences

Projects are supposed to support custom asset libraries too. So the
custom asset library types should be generalized and not be preferences
specific.

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

A	source/blender/blenkernel/BKE_asset_library_custom.h
M	source/blender/blenkernel/BKE_preferences.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/asset_catalog_test.cc
M	source/blender/blenkernel/intern/asset_library.cc
A	source/blender/blenkernel/intern/asset_library_custom.cc
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenkernel/intern/preferences.c
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/blenloader/intern/writefile.cc
M	source/blender/editors/asset/intern/asset_indexer.cc
M	source/blender/editors/asset/intern/asset_library_reference_enum.cc
M	source/blender/editors/asset/intern/asset_list.cc
M	source/blender/editors/asset/intern/asset_ops.cc
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/space_file/filelist.cc
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_node/add_node_search.cc
M	source/blender/editors/space_node/link_drag_search.cc
M	source/blender/editors/space_userpref/userpref_ops.c
M	source/blender/makesdna/DNA_asset_types.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesdna/intern/dna_rename_defs.h
M	source/blender/makesrna/intern/rna_asset.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/windowmanager/WM_types.h

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

diff --git a/source/blender/blenkernel/BKE_asset_library_custom.h b/source/blender/blenkernel/BKE_asset_library_custom.h
new file mode 100644
index 00000000000..f0331b4adc7
--- /dev/null
+++ b/source/blender/blenkernel/BKE_asset_library_custom.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup bke
+ *
+ * API to manage a list of #CustomAssetLibraryDefinition items.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "BLI_compiler_attrs.h"
+
+struct CustomAssetLibraryDefinition;
+struct ListBase;
+
+struct CustomAssetLibraryDefinition *BKE_asset_library_custom_add(
+    struct ListBase *custom_libraries, const char *name, const char *path) ATTR_NONNULL(1);
+/**
+ * Unlink and free a library preference member.
+ * \note Free's \a library itself.
+ */
+void BKE_asset_library_custom_remove(struct ListBase *custom_libraries,
+                                     struct CustomAssetLibraryDefinition *library) ATTR_NONNULL();
+
+void BKE_asset_library_custom_name_set(struct ListBase *custom_libraries,
+                                       struct CustomAssetLibraryDefinition *library,
+                                       const char *name) ATTR_NONNULL();
+
+/**
+ * Set the library path, ensuring it is pointing to a directory.
+ * Single blend files can only act as "Current File" library; libraries on disk
+ * should always be directories. If the path does not exist, that's fine; it can
+ * created as directory if necessary later.
+ */
+void BKE_asset_library_custom_path_set(struct CustomAssetLibraryDefinition *library,
+                                       const char *path) ATTR_NONNULL();
+
+struct CustomAssetLibraryDefinition *BKE_asset_library_custom_find_from_index(
+    const struct ListBase *custom_libraries, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+struct CustomAssetLibraryDefinition *BKE_asset_library_custom_find_from_name(
+    const struct ListBase *custom_libraries, const char *name)
+    ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+
+/**
+ * Return the #CustomAssetLibraryDefinition that contains the given file/directory path. The given
+ * path can be the library's top-level directory, or any path inside that directory.
+ *
+ * When more than one asset libraries match, the first matching one is returned (no smartness when
+ * there nested asset libraries).
+ *
+ * Return NULL when no such asset library is found. */
+struct CustomAssetLibraryDefinition *BKE_asset_library_custom_containing_path(
+    const struct ListBase *custom_libraries, const char *path)
+    ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+
+int BKE_asset_library_custom_get_index(
+    const struct ListBase /*#CustomAssetLibraryDefinition*/ *custom_libraries,
+    const struct CustomAssetLibraryDefinition *library) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/BKE_preferences.h b/source/blender/blenkernel/BKE_preferences.h
index 9d33848b3d1..93119af0710 100644
--- a/source/blender/blenkernel/BKE_preferences.h
+++ b/source/blender/blenkernel/BKE_preferences.h
@@ -13,55 +13,11 @@ extern "C" {
 #include "BLI_compiler_attrs.h"
 
 struct UserDef;
-struct bUserAssetLibrary;
 
 /** Name of the asset library added by default. Needs translation with `DATA_()` still. */
 #define BKE_PREFS_ASSET_LIBRARY_DEFAULT_NAME N_("User Library")
 
-struct bUserAssetLibrary *BKE_preferences_asset_library_add(struct UserDef *userdef,
-                                                            const char *name,
-                                                            const char *path) ATTR_NONNULL(1);
-/**
- * Unlink and free a library preference member.
- * \note Free's \a library itself.
- */
-void BKE_preferences_asset_library_remove(struct UserDef *userdef,
-                                          struct bUserAssetLibrary *library) ATTR_NONNULL();
-
-void BKE_preferences_asset_library_name_set(struct UserDef *userdef,
-                                            struct bUserAssetLibrary *library,
-                                            const char *name) ATTR_NONNULL();
-
-/**
- * Set the library path, ensuring it is pointing to a directory.
- * Single blend files can only act as "Current File" library; libraries on disk
- * should always be directories. If the path does not exist, that's fine; it can
- * created as directory if necessary later.
- */
-void BKE_preferences_asset_library_path_set(struct bUserAssetLibrary *library, const char *path)
-    ATTR_NONNULL();
-
-struct bUserAssetLibrary *BKE_preferences_asset_library_find_from_index(
-    const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
-struct bUserAssetLibrary *BKE_preferences_asset_library_find_from_name(
-    const struct UserDef *userdef, const char *name) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
-
-/**
- * Return the bUserAssetLibrary that contains the given file/directory path. The given path can be
- * the library's top-level directory, or any path inside that directory.
- *
- * When more than one asset libraries match, the first matching one is returned (no smartness when
- * there nested asset libraries).
- *
- * Return NULL when no such asset library is found. */
-struct bUserAssetLibrary *BKE_preferences_asset_library_containing_path(
-    const struct UserDef *userdef, const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
-
-int BKE_preferences_asset_library_get_index(const struct UserDef *userdef,
-                                            const struct bUserAssetLibrary *library)
-    ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
-
-void BKE_preferences_asset_library_default_add(struct UserDef *userdef) ATTR_NONNULL();
+void BKE_preferences_custom_asset_library_default_add(struct UserDef *userdef) ATTR_NONNULL();
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index a5cec7b6f50..25dd74ed40d 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -74,6 +74,7 @@ set(SRC
   intern/asset_catalog.cc
   intern/asset_catalog_path.cc
   intern/asset_library.cc
+  intern/asset_library_custom.cc
   intern/asset_library_service.cc
   intern/attribute.cc
   intern/attribute_access.cc
@@ -324,6 +325,7 @@ set(SRC
   BKE_asset_catalog_path.hh
   BKE_asset_library.h
   BKE_asset_library.hh
+  BKE_asset_library_custom.h
   BKE_attribute.h
   BKE_attribute.hh
   BKE_attribute_math.hh
diff --git a/source/blender/blenkernel/intern/asset_catalog_test.cc b/source/blender/blenkernel/intern/asset_catalog_test.cc
index 81eb1786322..d8d7aede513 100644
--- a/source/blender/blenkernel/intern/asset_catalog_test.cc
+++ b/source/blender/blenkernel/intern/asset_catalog_test.cc
@@ -3,7 +3,7 @@
 
 #include "BKE_appdir.h"
 #include "BKE_asset_catalog.hh"
-#include "BKE_preferences.h"
+#include "BKE_asset_library_custom.h"
 
 #include "BLI_fileops.h"
 #include "BLI_path_util.h"
@@ -213,8 +213,8 @@ class AssetCatalogTest : public testing::Test {
     BLI_path_slash_native(cdf_in_subdir.data());
 
     /* Set up a temporary asset library for testing. */
-    bUserAssetLibrary *asset_lib_pref = BKE_preferences_asset_library_add(
-        &U, "Test", registered_asset_lib.c_str());
+    CustomAssetLibraryDefinition *asset_lib_pref = BKE_asset_library_custom_add(
+        &U.asset_libraries, "Test", registered_asset_lib.c_str());
     ASSERT_NE(nullptr, asset_lib_pref);
     ASSERT_TRUE(BLI_dir_create_recursive(asset_lib_subdir.c_str()));
 
@@ -265,7 +265,7 @@ class AssetCatalogTest : public testing::Test {
     /* Test that the "red herring" CDF has not been touched. */
     EXPECT_EQ(0, BLI_file_size(cdf_in_subdir.c_str()));
 
-    BKE_preferences_asset_library_remove(&U, asset_lib_pref);
+    BKE_asset_library_custom_remove(&U.asset_libraries, asset_lib_pref);
   }
 };
 
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc
index 968873cbcbe..543b71e9da8 100644
--- a/source/blender/blenkernel/intern/asset_library.cc
+++ b/source/blender/blenkernel/intern/asset_library.cc
@@ -7,8 +7,8 @@
 #include <memory>
 
 #include "BKE_asset_library.hh"
+#include "BKE_asset_library_custom.h"
 #include "BKE_main.h"
-#include "BKE_preferences.h"
 
 #include "BLI_path_util.h"
 
@@ -45,8 +45,8 @@ bool BKE_asset_library_has_any_unsaved_catalogs()
 bool BKE_asset_library_find_suitable_root_path_from_path(const char *input_path,
                                                          char *r_library_path)
 {
-  if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path(
-          &U, input_path)) {
+  if (CustomAssetLibraryDefinition *preferences_lib = BKE_asset_library_custom_containing_path(
+          &U.asset_libraries, input_path)) {
     BLI_strncpy(r_library_path, preferences_lib->path, FILE_MAXDIR);
     return true;
   }
diff --git a/source/blender/blenkernel/intern/asset_library_custom.cc b/source/blender/blenkernel/intern/asset_library_custom.cc
new file mode 100644
index 00000000000..9627bd8a10b
--- /dev/null
+++ b/source/blender/blenkernel/intern/asset_library_custom.cc
@@ -0,0 +1,113 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup bke
+ */
+
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_fileops.h"
+#include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_appdir.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_asset_types.h"
+#include "DNA_userdef_types.h"
+
+#include "BKE_asset_library_custom.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Asset Libraries
+ * \{ */
+
+CustomAssetLibraryDefinition *BKE_asset_library_custom_add(ListBase *custom_libraries,
+                                                           const char *name,
+                                                           const char *path)
+{
+  CustomAssetLibraryDefinition *library = MEM_cnew<CustomAssetLibraryDefinition>(
+    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list