Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-09-27 16:53:05 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-27 19:10:47 +0300
commit90aa0a52568c629e466b6ccc513afadd0144ee1e (patch)
treebd1c2ef7b281e758720ad7e81d249ba36ae72e98 /source
parentaafbe111fc90876d801135f0dc5e01e9742f647a (diff)
BKE Preferences: find asset library containing a path
Add `BKE_preferences_asset_library_containing_path(&U, some_path)` that finds the asset library that contains the given path. This is a simple linear search, returning the first asset library that matches. There is no smartness when it comes to nested asset libraries (like returning the library with the best-matching path), although this could be a useful feature to add later.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_preferences.h12
-rw-r--r--source/blender/blenkernel/intern/preferences.c11
2 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_preferences.h b/source/blender/blenkernel/BKE_preferences.h
index acba2048614..bd887c1ea0d 100644
--- a/source/blender/blenkernel/BKE_preferences.h
+++ b/source/blender/blenkernel/BKE_preferences.h
@@ -43,6 +43,18 @@ 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;
diff --git a/source/blender/blenkernel/intern/preferences.c b/source/blender/blenkernel/intern/preferences.c
index c666dd4342a..0b8e8d7c311 100644
--- a/source/blender/blenkernel/intern/preferences.c
+++ b/source/blender/blenkernel/intern/preferences.c
@@ -94,6 +94,17 @@ bUserAssetLibrary *BKE_preferences_asset_library_find_from_name(const UserDef *u
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)
{