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.
This commit is contained in:
Julian Eisel 2022-10-12 16:00:20 +02:00
parent 416a486c00
commit 378e0d96fc
27 changed files with 321 additions and 236 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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);
}
};

View File

@ -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;
}

View File

@ -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>(
"CustomAssetLibraryDefinition");
BLI_addtail(custom_libraries, library);
if (name) {
BKE_asset_library_custom_name_set(custom_libraries, library, name);
}
if (path) {
BLI_strncpy(library->path, path, sizeof(library->path));
}
return library;
}
void BKE_asset_library_custom_remove(ListBase *custom_libraries,
CustomAssetLibraryDefinition *library)
{
BLI_freelinkN(custom_libraries, library);
}
void BKE_asset_library_custom_name_set(ListBase *custom_libraries,
CustomAssetLibraryDefinition *library,
const char *name)
{
BLI_strncpy_utf8(library->name, name, sizeof(library->name));
BLI_uniquename(custom_libraries,
library,
name,
'.',
offsetof(CustomAssetLibraryDefinition, name),
sizeof(library->name));
}
void BKE_asset_library_custom_path_set(CustomAssetLibraryDefinition *library, const char *path)
{
BLI_strncpy(library->path, path, sizeof(library->path));
if (BLI_is_file(library->path)) {
BLI_path_parent_dir(library->path);
}
}
CustomAssetLibraryDefinition *BKE_asset_library_custom_find_from_index(
const ListBase *custom_libraries, int index)
{
return static_cast<CustomAssetLibraryDefinition *>(BLI_findlink(custom_libraries, index));
}
CustomAssetLibraryDefinition *BKE_asset_library_custom_find_from_name(
const ListBase *custom_libraries, const char *name)
{
return static_cast<CustomAssetLibraryDefinition *>(
BLI_findstring(custom_libraries, name, offsetof(CustomAssetLibraryDefinition, name)));
}
CustomAssetLibraryDefinition *BKE_asset_library_custom_containing_path(
const ListBase *custom_libraries, const char *path)
{
LISTBASE_FOREACH (CustomAssetLibraryDefinition *, asset_lib_pref, custom_libraries) {
if (BLI_path_contains(asset_lib_pref->path, path)) {
return asset_lib_pref;
}
}
return NULL;
}
int BKE_asset_library_custom_get_index(const ListBase *custom_libraries,
const CustomAssetLibraryDefinition *library)
{
return BLI_findindex(custom_libraries, library);
}
/** \} */

View File

@ -691,7 +691,7 @@ UserDef *BKE_blendfile_userdef_from_defaults(void)
/* Default studio light. */
BKE_studiolight_default(userdef->light_param, userdef->light_ambient);
BKE_preferences_asset_library_default_add(userdef);
BKE_preferences_custom_asset_library_default_add(userdef);
return userdef;
}

View File

@ -2,26 +2,17 @@
/** \file
* \ingroup bke
*
* User defined asset library API.
*/
#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 "BKE_asset_library_custom.h"
#include "BKE_preferences.h"
#include "BLT_translation.h"
#include "DNA_asset_types.h"
#include "DNA_userdef_types.h"
#define U BLI_STATIC_ASSERT(false, "Global 'U' not allowed, only use arguments passed in!")
@ -30,79 +21,7 @@
/** \name Asset Libraries
* \{ */
bUserAssetLibrary *BKE_preferences_asset_library_add(UserDef *userdef,
const char *name,
const char *path)
{
bUserAssetLibrary *library = MEM_callocN(sizeof(*library), "bUserAssetLibrary");
BLI_addtail(&userdef->asset_libraries, library);
if (name) {
BKE_preferences_asset_library_name_set(userdef, library, name);
}
if (path) {
BLI_strncpy(library->path, path, sizeof(library->path));
}
return library;
}
void BKE_preferences_asset_library_remove(UserDef *userdef, bUserAssetLibrary *library)
{
BLI_freelinkN(&userdef->asset_libraries, library);
}
void BKE_preferences_asset_library_name_set(UserDef *userdef,
bUserAssetLibrary *library,
const char *name)
{
BLI_strncpy_utf8(library->name, name, sizeof(library->name));
BLI_uniquename(&userdef->asset_libraries,
library,
name,
'.',
offsetof(bUserAssetLibrary, name),
sizeof(library->name));
}
void BKE_preferences_asset_library_path_set(bUserAssetLibrary *library, const char *path)
{
BLI_strncpy(library->path, path, sizeof(library->path));
if (BLI_is_file(library->path)) {
BLI_path_parent_dir(library->path);
}
}
bUserAssetLibrary *BKE_preferences_asset_library_find_from_index(const UserDef *userdef, int index)
{
return BLI_findlink(&userdef->asset_libraries, index);
}
bUserAssetLibrary *BKE_preferences_asset_library_find_from_name(const UserDef *userdef,
const char *name)
{
return BLI_findstring(&userdef->asset_libraries, name, offsetof(bUserAssetLibrary, name));
}
bUserAssetLibrary *BKE_preferences_asset_library_containing_path(const UserDef *userdef,
const char *path)
{
LISTBASE_FOREACH (bUserAssetLibrary *, asset_lib_pref, &userdef->asset_libraries) {
if (BLI_path_contains(asset_lib_pref->path, path)) {
return asset_lib_pref;
}
}
return NULL;
}
int BKE_preferences_asset_library_get_index(const UserDef *userdef,
const bUserAssetLibrary *library)
{
return BLI_findindex(&userdef->asset_libraries, library);
}
void BKE_preferences_asset_library_default_add(UserDef *userdef)
void BKE_preferences_custom_asset_library_default_add(UserDef *userdef)
{
char documents_path[FILE_MAXDIR];
@ -111,8 +30,8 @@ void BKE_preferences_asset_library_default_add(UserDef *userdef)
return;
}
bUserAssetLibrary *library = BKE_preferences_asset_library_add(
userdef, DATA_(BKE_PREFS_ASSET_LIBRARY_DEFAULT_NAME), NULL);
CustomAssetLibraryDefinition *library = BKE_asset_library_custom_add(
&userdef->asset_libraries, DATA_(BKE_PREFS_ASSET_LIBRARY_DEFAULT_NAME), NULL);
/* Add new "Default" library under '[doc_path]/Blender/Assets'. */
BLI_path_join(

View File

@ -22,6 +22,7 @@
#include "DNA_windowmanager_types.h"
#include "BKE_addon.h"
#include "BKE_asset_library_custom.h"
#include "BKE_blender_version.h"
#include "BKE_colorband.h"
#include "BKE_idprop.h"
@ -679,7 +680,7 @@ void blo_do_versions_userdef(UserDef *userdef)
if (!USER_VERSION_ATLEAST(292, 9)) {
if (BLI_listbase_is_empty(&userdef->asset_libraries)) {
BKE_preferences_asset_library_default_add(userdef);
BKE_preferences_custom_asset_library_default_add(userdef);
}
}
@ -732,11 +733,11 @@ void blo_do_versions_userdef(UserDef *userdef)
* since it doesn't handle translations and ignores user changes. But this was an alpha build
* (experimental) feature and the name is just for display in the UI anyway. So it doesn't have
* to work perfectly at all. */
LISTBASE_FOREACH (bUserAssetLibrary *, asset_library, &userdef->asset_libraries) {
LISTBASE_FOREACH (CustomAssetLibraryDefinition *, asset_library, &userdef->asset_libraries) {
/* Ignores translations, since that would depend on the current preferences (global `U`). */
if (STREQ(asset_library->name, "Default")) {
BKE_preferences_asset_library_name_set(
userdef, asset_library, BKE_PREFS_ASSET_LIBRARY_DEFAULT_NAME);
BKE_asset_library_custom_name_set(
&userdef->asset_libraries, asset_library, BKE_PREFS_ASSET_LIBRARY_DEFAULT_NAME);
}
}
}

View File

@ -923,8 +923,9 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
BLO_write_struct(writer, bPathCompare, path_cmp);
}
LISTBASE_FOREACH (const bUserAssetLibrary *, asset_library_ref, &userdef->asset_libraries) {
BLO_write_struct(writer, bUserAssetLibrary, asset_library_ref);
LISTBASE_FOREACH (
const CustomAssetLibraryDefinition *, asset_library_ref, &userdef->asset_libraries) {
BLO_write_struct(writer, CustomAssetLibraryDefinition, asset_library_ref);
}
LISTBASE_FOREACH (const uiStyle *, style, &userdef->uistyles) {

View File

@ -26,7 +26,6 @@
#include "BKE_asset.h"
#include "BKE_asset_catalog.hh"
#include "BKE_idprop.hh"
#include "BKE_preferences.h"
#include "CLG_log.h"

View File

@ -11,7 +11,7 @@
#include "BLI_listbase.h"
#include "BKE_preferences.h"
#include "BKE_asset_library_custom.h"
#include "DNA_userdef_types.h"
@ -30,8 +30,8 @@ int ED_asset_library_reference_to_enum_value(const AssetLibraryReference *librar
/* 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);
const CustomAssetLibraryDefinition *user_library = BKE_asset_library_custom_find_from_index(
&U.asset_libraries, library->custom_library_index);
if (user_library) {
return ASSET_LIBRARY_CUSTOM + library->custom_library_index;
}
@ -51,8 +51,8 @@ AssetLibraryReference ED_asset_library_reference_from_enum_value(int value)
return library;
}
const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index(
&U, value - ASSET_LIBRARY_CUSTOM);
const CustomAssetLibraryDefinition *user_library = BKE_asset_library_custom_find_from_index(
&U.asset_libraries, value - ASSET_LIBRARY_CUSTOM);
/* Note that there is no check if the path exists here. If an invalid library path is used, the
* Asset Browser can give a nice hint on what's wrong. */
@ -98,7 +98,7 @@ const EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(
}
int i;
LISTBASE_FOREACH_INDEX (bUserAssetLibrary *, user_library, &U.asset_libraries, i) {
LISTBASE_FOREACH_INDEX (CustomAssetLibraryDefinition *, user_library, &U.asset_libraries, i) {
/* Note that the path itself 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]);

View File

@ -12,6 +12,7 @@
#include <optional>
#include <string>
#include "BKE_asset_library_custom.h"
#include "BKE_context.h"
#include "BLI_map.hh"
@ -20,8 +21,6 @@
#include "DNA_space_types.h"
#include "BKE_preferences.h"
#include "ED_fileselect.h"
#include "WM_api.h"
@ -131,14 +130,14 @@ void AssetList::setup()
{
FileList *files = filelist_;
bUserAssetLibrary *user_library = nullptr;
CustomAssetLibraryDefinition *user_library = nullptr;
/* Ensure valid repository, or fall-back to local one. */
if (library_ref_.type == ASSET_LIBRARY_CUSTOM) {
BLI_assert(library_ref_.custom_library_index >= 0);
user_library = BKE_preferences_asset_library_find_from_index(
&U, library_ref_.custom_library_index);
user_library = BKE_asset_library_custom_find_from_index(&U.asset_libraries,
library_ref_.custom_library_index);
}
/* Relevant bits from file_refresh(). */

View File

@ -5,12 +5,12 @@
*/
#include "BKE_asset_library.hh"
#include "BKE_asset_library_custom.h"
#include "BKE_bpath.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_preferences.h"
#include "BKE_report.h"
#include "BLI_fileops.h"
@ -669,7 +669,7 @@ static void ASSET_OT_catalogs_save(struct wmOperatorType *ot)
/* -------------------------------------------------------------------- */
static bool could_be_asset_bundle(const Main *bmain);
static const bUserAssetLibrary *selected_asset_library(struct wmOperator *op);
static const CustomAssetLibraryDefinition *selected_asset_library(struct wmOperator *op);
static bool is_contained_in_selected_asset_library(struct wmOperator *op, const char *filepath);
static bool set_filepath_for_asset_lib(const Main *bmain, struct wmOperator *op);
static bool has_external_files(Main *bmain, struct ReportList *reports);
@ -691,8 +691,8 @@ static bool asset_bundle_install_poll(bContext *C)
}
/* Check whether this file is already located inside any asset library. */
const struct bUserAssetLibrary *asset_lib = BKE_preferences_asset_library_containing_path(
&U, bmain->filepath);
const struct CustomAssetLibraryDefinition *asset_lib = BKE_asset_library_custom_containing_path(
&U.asset_libraries, bmain->filepath);
if (asset_lib) {
return false;
}
@ -763,7 +763,7 @@ static int asset_bundle_install_exec(bContext *C, wmOperator *op)
return operator_result;
}
const bUserAssetLibrary *lib = selected_asset_library(op);
const CustomAssetLibraryDefinition *lib = selected_asset_library(op);
BLI_assert_msg(lib, "If the asset library is not known, how did we get here?");
BKE_reportf(op->reports,
RPT_INFO,
@ -823,18 +823,18 @@ static bool could_be_asset_bundle(const Main *bmain)
return fnmatch("*_bundle.blend", bmain->filepath, FNM_CASEFOLD) == 0;
}
static const bUserAssetLibrary *selected_asset_library(struct wmOperator *op)
static const CustomAssetLibraryDefinition *selected_asset_library(struct wmOperator *op)
{
const int enum_value = RNA_enum_get(op->ptr, "asset_library_ref");
const AssetLibraryReference lib_ref = ED_asset_library_reference_from_enum_value(enum_value);
const bUserAssetLibrary *lib = BKE_preferences_asset_library_find_from_index(
&U, lib_ref.custom_library_index);
const CustomAssetLibraryDefinition *lib = BKE_asset_library_custom_find_from_index(
&U.asset_libraries, lib_ref.custom_library_index);
return lib;
}
static bool is_contained_in_selected_asset_library(struct wmOperator *op, const char *filepath)
{
const bUserAssetLibrary *lib = selected_asset_library(op);
const CustomAssetLibraryDefinition *lib = selected_asset_library(op);
if (!lib) {
return false;
}
@ -848,7 +848,7 @@ static bool is_contained_in_selected_asset_library(struct wmOperator *op, const
static bool set_filepath_for_asset_lib(const Main *bmain, struct wmOperator *op)
{
/* Find the directory path of the selected asset library. */
const bUserAssetLibrary *lib = selected_asset_library(op);
const CustomAssetLibraryDefinition *lib = selected_asset_library(op);
if (lib == nullptr) {
return false;
}

View File

@ -676,7 +676,7 @@ static bool ui_rna_is_userdef(PointerRNA *ptr, PropertyRNA *prop)
&RNA_AddonPreferences,
&RNA_KeyConfigPreferences,
&RNA_KeyMapItem,
&RNA_UserAssetLibrary);
&RNA_CustomAssetLibraryDefinition);
}
bool UI_but_is_userdef(const uiBut *but)

View File

@ -42,6 +42,7 @@
#include "BKE_asset.h"
#include "BKE_asset_library.h"
#include "BKE_asset_library_custom.h"
#include "BKE_blender_project.h"
#include "BKE_context.h"
#include "BKE_global.h"
@ -50,7 +51,6 @@
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_main_idmap.h"
#include "BKE_preferences.h"
#include "BLO_readfile.h"
#include "DNA_asset_types.h"
@ -1040,8 +1040,8 @@ static bool filelist_compare_asset_libraries(const AssetLibraryReference *librar
}
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);
CustomAssetLibraryDefinition *library_ptr_a = BKE_asset_library_custom_find_from_index(
&U.asset_libraries, library_a->custom_library_index);
return (library_ptr_a != nullptr) &&
(library_a->custom_library_index == library_b->custom_library_index);
}

View File

@ -39,10 +39,10 @@
#include "BLT_translation.h"
#include "BKE_appdir.h"
#include "BKE_asset_library_custom.h"
#include "BKE_context.h"
#include "BKE_idtype.h"
#include "BKE_main.h"
#include "BKE_preferences.h"
#include "BLF_api.h"
@ -409,14 +409,14 @@ static void fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
{
AssetLibraryReference *library = &asset_params->asset_library_ref;
FileSelectParams *base_params = &asset_params->base_params;
bUserAssetLibrary *user_library = NULL;
CustomAssetLibraryDefinition *user_library = NULL;
/* Ensure valid repository, or fall-back to local one. */
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);
user_library = BKE_asset_library_custom_find_from_index(&U.asset_libraries,
library->custom_library_index);
if (!user_library) {
library->type = ASSET_LIBRARY_LOCAL;
}

View File

@ -123,7 +123,8 @@ static void gather_search_items_for_all_assets(const bContext &C,
Vector<AddNodeItem> &search_items)
{
int i;
LISTBASE_FOREACH_INDEX (const bUserAssetLibrary *, asset_library, &U.asset_libraries, i) {
LISTBASE_FOREACH_INDEX (
const CustomAssetLibraryDefinition *, asset_library, &U.asset_libraries, i) {
AssetLibraryReference library_ref{};
library_ref.custom_library_index = i;
library_ref.type = ASSET_LIBRARY_CUSTOM;

View File

@ -243,7 +243,8 @@ static void gather_search_link_ops_for_all_assets(const bContext &C,
Vector<SocketLinkOperation> &search_link_ops)
{
int i;
LISTBASE_FOREACH_INDEX (const bUserAssetLibrary *, asset_library, &U.asset_libraries, i) {
LISTBASE_FOREACH_INDEX (
const CustomAssetLibraryDefinition *, asset_library, &U.asset_libraries, i) {
AssetLibraryReference library_ref{};
library_ref.custom_library_index = i;
library_ref.type = ASSET_LIBRARY_CUSTOM;

View File

@ -16,9 +16,9 @@
#endif
#include "BLI_path_util.h"
#include "BKE_asset_library_custom.h"
#include "BKE_context.h"
#include "BKE_main.h"
#include "BKE_preferences.h"
#include "BKE_report.h"
@ -134,7 +134,7 @@ static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *o
BLI_split_file_part(path, dirname, sizeof(dirname));
/* NULL is a valid directory path here. A library without path will be created then. */
BKE_preferences_asset_library_add(&U, dirname, path);
BKE_asset_library_custom_add(&U.asset_libraries, dirname, path);
U.runtime.is_dirty = true;
/* There's no dedicated notifier for the Preferences. */
@ -185,9 +185,9 @@ static void PREFERENCES_OT_asset_library_add(wmOperatorType *ot)
static int preferences_asset_library_remove_exec(bContext *UNUSED(C), wmOperator *op)
{
const int index = RNA_int_get(op->ptr, "index");
bUserAssetLibrary *library = BLI_findlink(&U.asset_libraries, index);
CustomAssetLibraryDefinition *library = BLI_findlink(&U.asset_libraries, index);
if (library) {
BKE_preferences_asset_library_remove(&U, library);
BKE_asset_library_custom_remove(&U.asset_libraries, library);
U.runtime.is_dirty = true;
/* Trigger refresh for the Asset Browser. */
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, NULL);

View File

@ -2,6 +2,9 @@
/** \file
* \ingroup DNA
*
* Only contains types that need writing to files or that are accessed directly via RNA (as opposed
* to being opaque types accessed via an API).
*/
#pragma once
@ -88,10 +91,8 @@ typedef enum eAssetLibraryType {
// ASSET_LIBRARY_PROJECT = 2,
/** Display assets from custom asset libraries, as defined in the preferences
* (#bUserAssetLibrary). The name will be taken from #FileSelectParams.asset_library_ref.idname
* then.
* In RNA, we add the index of the custom library to this to identify it by index. So keep
* this last! */
* (#CustomAssetLibraryDefinition). In RNA, we add the index of the custom library to this to
* identify it by index. So keep this last! */
ASSET_LIBRARY_CUSTOM = 100,
} eAssetLibraryType;
@ -107,12 +108,19 @@ typedef struct AssetLibraryReference {
char _pad1[2];
/**
* If showing a custom asset library (#ASSET_LIBRARY_CUSTOM), this is the index of the
* #bUserAssetLibrary within #UserDef.asset_libraries.
* #CustomAssetLibraryDefinition within #UserDef.asset_libraries.
* Should be ignored otherwise (but better set to -1 then, for sanity and debugging).
*/
int custom_library_index;
} AssetLibraryReference;
typedef struct CustomAssetLibraryDefinition {
struct CustomAssetLibraryDefinition *next, *prev;
char name[64]; /* MAX_NAME */
char path[1024]; /* FILE_MAX */
} CustomAssetLibraryDefinition;
/**
* Not part of the core design, we should try to get rid of it. Only needed to wrap FileDirEntry
* into a type with PropertyGroup as base, so we can have an RNA collection of #AssetHandle's to

View File

@ -572,13 +572,6 @@ enum {
USER_MENU_TYPE_PROP = 4,
};
typedef struct bUserAssetLibrary {
struct bUserAssetLibrary *next, *prev;
char name[64]; /* MAX_NAME */
char path[1024]; /* FILE_MAX */
} bUserAssetLibrary;
typedef struct SolidLight {
int flag;
float smooth;
@ -772,7 +765,7 @@ typedef struct UserDef {
struct ListBase autoexec_paths;
/** #bUserMenu. */
struct ListBase user_menus;
/** #bUserAssetLibrary */
/** #CustomAssetLibraryDefinition */
struct ListBase asset_libraries;
char keyconfigstr[64];

View File

@ -41,6 +41,7 @@ DNA_STRUCT_RENAME(Lamp, Light)
DNA_STRUCT_RENAME(SpaceButs, SpaceProperties)
DNA_STRUCT_RENAME(SpaceIpo, SpaceGraph)
DNA_STRUCT_RENAME(SpaceOops, SpaceOutliner)
DNA_STRUCT_RENAME(bUserAssetLibrary, CustomAssetLibraryDefinition)
DNA_STRUCT_RENAME_ELEM(BPoint, alfa, tilt)
DNA_STRUCT_RENAME_ELEM(BezTriple, alfa, tilt)
DNA_STRUCT_RENAME_ELEM(Bone, curveInX, curve_in_x)

View File

@ -19,6 +19,7 @@
# include "BKE_asset.h"
# include "BKE_asset_library.h"
# include "BKE_asset_library_custom.h"
# include "BKE_context.h"
# include "BKE_idprop.h"
@ -30,6 +31,9 @@
# include "RNA_access.h"
# include "WM_api.h"
# include "WM_types.h"
static bool rna_AssetMetaData_editable_from_owner_id(const ID *owner_id,
const AssetMetaData *asset_data,
const char **r_info)
@ -254,6 +258,41 @@ void rna_AssetMetaData_catalog_id_update(struct bContext *C, struct PointerRNA *
BKE_asset_library_refresh_catalog_simplename(asset_library, asset_data);
}
static bool rna_CustomAssetLibraryDefinition_is_from_prefs(
const CustomAssetLibraryDefinition *library)
{
return BLI_findindex(&U.asset_libraries, library) > -1;
}
static void rna_CustomAssetLibraryDefinition_name_set(PointerRNA *ptr, const char *value)
{
CustomAssetLibraryDefinition *library = (CustomAssetLibraryDefinition *)ptr->data;
if (!rna_CustomAssetLibraryDefinition_is_from_prefs(library)) {
BLI_assert_unreachable();
return;
}
BKE_asset_library_custom_name_set(&U.asset_libraries, library, value);
}
static void rna_CustomAssetLibraryDefinition_path_set(PointerRNA *ptr, const char *value)
{
CustomAssetLibraryDefinition *library = (CustomAssetLibraryDefinition *)ptr->data;
if (!rna_CustomAssetLibraryDefinition_is_from_prefs(library)) {
BLI_assert_unreachable();
return;
}
BKE_asset_library_custom_path_set(library, value);
}
void rna_AssetLibrary_settings_update(Main *UNUSED(bmain),
Scene *UNUSED(scene),
PointerRNA *UNUSED(ptr))
{
WM_main_add_notifier(NC_ASSET | ND_ASSET_LIBRARY, NULL);
}
static PointerRNA rna_AssetHandle_file_data_get(PointerRNA *ptr)
{
AssetHandle *asset_handle = ptr->data;
@ -479,6 +518,30 @@ static void rna_def_asset_library_reference(BlenderRNA *brna)
srna, "Asset Library Reference", "Identifier to refer to the asset library");
}
static void rna_def_asset_library_reference_custom(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "CustomAssetLibraryDefinition", NULL);
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
RNA_def_struct_ui_text(
srna, "Asset Library", "Settings to define a reusable library for Asset Browsers to use");
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(
prop, "Name", "Identifier (not necessarily unique) for the asset library");
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_CustomAssetLibraryDefinition_name_set");
RNA_def_struct_name_property(srna, prop);
RNA_def_property_update(prop, 0, "rna_AssetLibrary_settings_update");
prop = RNA_def_property(srna, "path", PROP_STRING, PROP_DIRPATH);
RNA_def_property_ui_text(
prop, "Path", "Path to a directory with .blend files to use as an asset library");
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_CustomAssetLibraryDefinition_path_set");
RNA_def_property_update(prop, 0, "rna_AssetLibrary_settings_update");
}
PropertyRNA *rna_def_asset_library_reference_common(struct StructRNA *srna,
const char *get,
const char *set)
@ -497,6 +560,7 @@ void RNA_def_asset(BlenderRNA *brna)
rna_def_asset_tag(brna);
rna_def_asset_data(brna);
rna_def_asset_library_reference(brna);
rna_def_asset_library_reference_custom(brna);
rna_def_asset_handle(brna);
RNA_define_animate_sdna(true);

View File

@ -556,7 +556,6 @@ const EnumPropertyItem rna_enum_project_settings_section_items[] = {
# include "BKE_layer.h"
# include "BKE_nla.h"
# include "BKE_paint.h"
# include "BKE_preferences.h"
# include "BKE_scene.h"
# include "BKE_screen.h"
# include "BKE_workspace.h"

View File

@ -154,7 +154,6 @@ static const EnumPropertyItem rna_enum_userdef_viewport_aa_items[] = {
# include "BKE_object.h"
# include "BKE_paint.h"
# include "BKE_pbvh.h"
# include "BKE_preferences.h"
# include "BKE_screen.h"
# include "DEG_depsgraph.h"
@ -308,18 +307,6 @@ static void rna_userdef_language_update(Main *UNUSED(bmain),
USERDEF_TAG_DIRTY;
}
static void rna_userdef_asset_library_name_set(PointerRNA *ptr, const char *value)
{
bUserAssetLibrary *library = (bUserAssetLibrary *)ptr->data;
BKE_preferences_asset_library_name_set(&U, library, value);
}
static void rna_userdef_asset_library_path_set(PointerRNA *ptr, const char *value)
{
bUserAssetLibrary *library = (bUserAssetLibrary *)ptr->data;
BKE_preferences_asset_library_path_set(library, value);
}
static void rna_userdef_script_autoexec_update(Main *UNUSED(bmain),
Scene *UNUSED(scene),
PointerRNA *ptr)
@ -6067,31 +6054,6 @@ static void rna_def_userdef_keymap(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Key Config", "The name of the active key configuration");
}
static void rna_def_userdef_filepaths_asset_library(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "UserAssetLibrary", NULL);
RNA_def_struct_sdna(srna, "bUserAssetLibrary");
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
RNA_def_struct_ui_text(
srna, "Asset Library", "Settings to define a reusable library for Asset Browsers to use");
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(
prop, "Name", "Identifier (not necessarily unique) for the asset library");
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_userdef_asset_library_name_set");
RNA_def_struct_name_property(srna, prop);
RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "path", PROP_STRING, PROP_DIRPATH);
RNA_def_property_ui_text(
prop, "Path", "Path to a directory with .blend files to use as an asset library");
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_userdef_asset_library_path_set");
RNA_def_property_update(prop, 0, "rna_userdef_update");
}
static void rna_def_userdef_filepaths(BlenderRNA *brna)
{
PropertyRNA *prop;
@ -6272,10 +6234,8 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna)
RNA_def_property_enum_items(prop, preview_type_items);
RNA_def_property_ui_text(prop, "File Preview Type", "What type of blend preview to create");
rna_def_userdef_filepaths_asset_library(brna);
prop = RNA_def_property(srna, "asset_libraries", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "UserAssetLibrary");
RNA_def_property_struct_type(prop, "CustomAssetLibraryDefinition");
RNA_def_property_ui_text(prop, "Asset Libraries", "");
}

View File

@ -498,6 +498,9 @@ typedef struct wmNotifier {
* reloading of asset libraries & their catalogs should happen. That only happens on explicit user
* action. */
#define ND_ASSET_CATALOGS (4 << 16)
/* Some settings of an asset library were changed, and UIs showing asset library information should
* redraw. */
#define ND_ASSET_LIBRARY (5 << 16)
/* subtype, 256 entries too */
#define NOTE_SUBTYPE 0x0000FF00