WIP: Brush assets project #106303

Draft
Julian Eisel wants to merge 351 commits from brush-assets-project into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 53 additions and 1 deletions
Showing only changes of commit 91bc69f069 - Show all commits

View File

@ -144,7 +144,7 @@ void AssetList::setup()
/* Relevant bits from file_refresh(). */
/* TODO pass options properly. */
filelist_setrecursion(files, FILE_SELECT_MAX_RECURSIONS);
filelist_setsorting(files, FILE_SORT_ALPHA, false);
filelist_setsorting(files, FILE_SORT_ASSET_CATALOG, false);
filelist_setlibrary(files, &library_ref_);
filelist_setfilter_options(
files,

View File

@ -571,6 +571,53 @@ static int compare_extension(void *user_data, const void *a1, const void *a2)
return compare_apply_inverted(compare_tiebreaker(entry1, entry2), sort_data);
}
static int compare_asset_catalog(void *user_data, const void *a1, const void *a2)
{
const FileListInternEntry *entry1 = static_cast<const FileListInternEntry *>(a1);
const FileListInternEntry *entry2 = static_cast<const FileListInternEntry *>(a2);
const FileSortData *sort_data = static_cast<const FileSortData *>(user_data);
if (entry1->asset && !entry2->asset) {
return 1;
}
if (!entry1->asset && entry2->asset) {
return -1;
}
if (!entry1->asset && !entry2->asset) {
if (int ret = compare_direntry_generic(entry1, entry2); ret) {
return ret;
}
return compare_apply_inverted(compare_tiebreaker(entry1, entry2), sort_data);
}
const asset_system::AssetLibrary &asset_library1 = entry1->asset->owner_asset_library();
const asset_system::AssetLibrary &asset_library2 = entry2->asset->owner_asset_library();
const asset_system::AssetCatalog *catalog1 = asset_library1.catalog_service->find_catalog(
entry1->asset->get_metadata().catalog_id);
const asset_system::AssetCatalog *catalog2 = asset_library2.catalog_service->find_catalog(
entry2->asset->get_metadata().catalog_id);
/* Always keep assets without catalog last. */
if (catalog1 && !catalog2) {
return 1;
}
if (!catalog1 && catalog2) {
return -1;
}
if (catalog1 && catalog2) {
const int order = BLI_strcasecmp_natural(catalog1->path.name().c_str(),
catalog2->path.name().c_str());
if (order) {
return compare_apply_inverted(order, sort_data);
}
}
return compare_apply_inverted(compare_tiebreaker(entry1, entry2), sort_data);
}
void filelist_sort(FileList *filelist)
{
if (filelist->flags & FL_NEED_SORTING) {
@ -589,6 +636,9 @@ void filelist_sort(FileList *filelist)
case FILE_SORT_EXTENSION:
sort_cb = compare_extension;
break;
case FILE_SORT_ASSET_CATALOG:
sort_cb = compare_asset_catalog;
break;
case FILE_SORT_DEFAULT:
default:
BLI_assert(0);

View File

@ -983,6 +983,8 @@ enum eFileSortType {
FILE_SORT_EXTENSION = 2,
FILE_SORT_TIME = 3,
FILE_SORT_SIZE = 4,
/* Assets: Sort by catalog. Within each catalog, assets will be sorted by name. */
FILE_SORT_ASSET_CATALOG = 5,
};
/** #SpaceFile.tags */