From 10e28bd27017664064b1fb93f1ed347d6b404ae6 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 21 Jul 2021 19:22:44 +0200 Subject: Assets: Replace duplicated asset library reference type from DNA Since recently it's possible to access assets from outside the File/Asset Browser, via the asset view template. So we are slowly moving away from file space specific code to dedicated asset system code. I introduced `AssetLibraryReference` as a duplicate of `FileSelectAssetLibraryUID`, with a plan to delete the latter in a separate cleanup commit. That's exactly what this commit is. This will cause Asset Browsers to open with the default "Current File" Asset Library. We could avoid that, but it's a minor issue really. --- source/blender/blenloader/intern/versioning_300.c | 17 +++++++++++++++++ source/blender/editors/asset/asset_list.cc | 7 +------ source/blender/editors/space_file/filelist.c | 8 ++++---- source/blender/editors/space_file/filelist.h | 4 ++-- source/blender/editors/space_file/filesel.c | 2 +- source/blender/editors/space_file/space_file.c | 7 ------- source/blender/makesdna/DNA_asset_types.h | 1 - source/blender/makesdna/DNA_space_types.h | 21 ++------------------- 8 files changed, 27 insertions(+), 40 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 2bb64717615..bc73dbac589 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -580,5 +580,22 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) BKE_asset_library_reference_init_default(&workspace->asset_library); } } + + if (!DNA_struct_elem_find( + fd->filesdna, "FileAssetSelectParams", "AssetLibraryReference", "asset_library")) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) { + if (space->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)space; + if (sfile->browse_mode != FILE_BROWSE_MODE_ASSETS) { + continue; + } + BKE_asset_library_reference_init_default(&sfile->asset_params->asset_library); + } + } + } + } + } } } diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc index e610a1dfbcd..9e611edd715 100644 --- a/source/blender/editors/asset/asset_list.cc +++ b/source/blender/editors/asset/asset_list.cc @@ -143,11 +143,6 @@ void AssetList::setup(const AssetFilterSettings *filter_settings) { FileList *files = filelist_; - /* TODO there should only be one (FileSelectAssetLibraryUID vs. AssetLibraryReference). */ - FileSelectAssetLibraryUID file_asset_lib_ref; - file_asset_lib_ref.type = library_ref_.type; - file_asset_lib_ref.custom_library_index = library_ref_.custom_library_index; - bUserAssetLibrary *user_library = nullptr; /* Ensure valid repository, or fall-back to local one. */ @@ -162,7 +157,7 @@ void AssetList::setup(const AssetFilterSettings *filter_settings) /* TODO pass options properly. */ filelist_setrecursion(files, 1); filelist_setsorting(files, FILE_SORT_ALPHA, false); - filelist_setlibrary(files, &file_asset_lib_ref); + filelist_setlibrary(files, &library_ref_); /* TODO different filtering settings require the list to be reread. That's a no-go for when we * want to allow showing the same asset library with different filter settings (as in, * different ID types). The filelist needs to be made smarter somehow, maybe goes together with diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 492a189fc81..6ac67a126cd 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -382,7 +382,7 @@ typedef struct FileList { eFileSelectType type; /* The library this list was created for. Stored here so we know when to re-read. */ - FileSelectAssetLibraryUID *asset_library; + AssetLibraryReference *asset_library; short flags; @@ -1045,8 +1045,8 @@ void filelist_setfilter_options(FileList *filelist, * Checks two libraries for equality. * \return True if the libraries match. */ -static bool filelist_compare_asset_libraries(const FileSelectAssetLibraryUID *library_a, - const FileSelectAssetLibraryUID *library_b) +static bool filelist_compare_asset_libraries(const AssetLibraryReference *library_a, + const AssetLibraryReference *library_b) { if (library_a->type != library_b->type) { return false; @@ -1065,7 +1065,7 @@ static bool filelist_compare_asset_libraries(const FileSelectAssetLibraryUID *li /** * \param asset_library: May be NULL to unset the library. */ -void filelist_setlibrary(FileList *filelist, const FileSelectAssetLibraryUID *asset_library) +void filelist_setlibrary(FileList *filelist, const AssetLibraryReference *asset_library) { /* Unset if needed. */ if (!asset_library) { diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index cb98cf6e74a..6915e853681 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -29,7 +29,7 @@ extern "C" { struct BlendHandle; struct FileList; -struct FileSelectAssetLibraryUID; +struct AssetLibraryReference; struct FileSelection; struct wmWindowManager; @@ -73,7 +73,7 @@ void filelist_setfilter_options(struct FileList *filelist, const char *filter_search); void filelist_filter(struct FileList *filelist); void filelist_setlibrary(struct FileList *filelist, - const struct FileSelectAssetLibraryUID *asset_library); + const struct AssetLibraryReference *asset_library); void filelist_init_icons(void); void filelist_free_icons(void); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 7bc83e8fc79..68dd1e28f99 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -415,7 +415,7 @@ FileAssetSelectParams *ED_fileselect_get_asset_params(const SpaceFile *sfile) static void fileselect_refresh_asset_params(FileAssetSelectParams *asset_params) { - FileSelectAssetLibraryUID *library = &asset_params->asset_library; + AssetLibraryReference *library = &asset_params->asset_library; FileSelectParams *base_params = &asset_params->base_params; bUserAssetLibrary *user_library = NULL; diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 31c7dee294b..274b21f7043 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -910,13 +910,6 @@ static int /*eContextResult*/ file_context(const bContext *C, return CTX_RESULT_NO_DATA; } - BLI_STATIC_ASSERT(offsetof(FileSelectAssetLibraryUID, type) == - offsetof(AssetLibraryReference, type), - "Expected FileSelectAssetLibraryUID to match AssetLibraryReference"); - BLI_STATIC_ASSERT(offsetof(FileSelectAssetLibraryUID, custom_library_index) == - offsetof(AssetLibraryReference, custom_library_index), - "Expected FileSelectAssetLibraryUID to match AssetLibraryReference"); - CTX_data_pointer_set( result, &screen->id, &RNA_AssetLibraryReference, &asset_params->asset_library); return CTX_RESULT_OK; diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h index 8677ec4a50b..316f8631ece 100644 --- a/source/blender/makesdna/DNA_asset_types.h +++ b/source/blender/makesdna/DNA_asset_types.h @@ -89,7 +89,6 @@ typedef enum eAssetLibraryType { ASSET_LIBRARY_CUSTOM = 100, } eAssetLibraryType; -/* TODO copy of FileSelectAssetLibraryUID */ /** * Information to identify a asset library. May be either one of the predefined types (current * 'Main', builtin library, project library), or a custom type as defined in the Preferences. diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index b990de29ff3..04c9eab33f1 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -24,6 +24,7 @@ #pragma once +#include "DNA_asset_types.h" #include "DNA_color_types.h" /* for Histogram */ #include "DNA_defs.h" #include "DNA_image_types.h" /* ImageUser */ @@ -696,24 +697,6 @@ typedef enum eSpaceSeq_OverlayType { /** \name File Selector * \{ */ -/** - * Information to identify a asset library. May be either one of the predefined types (current - * 'Main', builtin library, project library), or a custom type as defined in the Preferences. - * - * If the type is set to #ASSET_LIBRARY_CUSTOM, idname must have the name to identify the - * custom library. Otherwise idname is not used. - */ -typedef struct FileSelectAssetLibraryUID { - short type; /* eFileAssetLibrary_Type */ - char _pad[2]; - /** - * If showing a custom asset library (#ASSET_LIBRARY_CUSTOM), this is the index of the - * #bUserAssetLibrary within #UserDef.asset_libraries. - * Should be ignored otherwise (but better set to -1 then, for sanity and debugging). - */ - int custom_library_index; -} FileSelectAssetLibraryUID; - /* Config and Input for File Selector */ typedef struct FileSelectParams { /** Title, also used for the text of the execute button. */ @@ -785,7 +768,7 @@ typedef struct FileSelectParams { typedef struct FileAssetSelectParams { FileSelectParams base_params; - FileSelectAssetLibraryUID asset_library; + AssetLibraryReference asset_library; short import_type; /* eFileAssetImportType */ char _pad[6]; -- cgit v1.2.3