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
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-07-21 20:30:31 +0300
committerJulian Eisel <julian@blender.org>2021-07-21 20:35:39 +0300
commite850c2b06d18e4292110d3fe9cdf5ebc7c281daa (patch)
tree6a29c978067573d2e99049f9056a6cf310650d67 /source/blender/editors/asset/asset_edit.cc
parent10e28bd27017664064b1fb93f1ed347d6b404ae6 (diff)
Cleanup: Centralize/unify asset library reference from/to enum code
This was an open TODO, I wanted to have code for translating asset library references from and to enum values in a central place, and access that in the same way from both the Asset Browser and the Workspace RNA code. * Adds own file for the related functions. * Adds doxygen comments. * Updates RNA callbacks to properly use these functions. * Let these functions call each other, avoid duplicating logic.
Diffstat (limited to 'source/blender/editors/asset/asset_edit.cc')
-rw-r--r--source/blender/editors/asset/asset_edit.cc53
1 files changed, 0 insertions, 53 deletions
diff --git a/source/blender/editors/asset/asset_edit.cc b/source/blender/editors/asset/asset_edit.cc
index 16fd71b4340..c55e7a95120 100644
--- a/source/blender/editors/asset/asset_edit.cc
+++ b/source/blender/editors/asset/asset_edit.cc
@@ -80,56 +80,3 @@ 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` callback? */
-#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 repository, 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 repository, 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;
-}