Move asset catalog filtering to editors/assets

Such general asset-view functionality can go to the general editors
level, I think that makes the most sense.
This commit is contained in:
Julian Eisel 2022-02-07 18:57:39 +01:00
parent ee013f44b5
commit eab2a8479a
16 changed files with 231 additions and 241 deletions

View File

@ -44,6 +44,7 @@ set(SRC
intern/asset_ops.cc
intern/asset_temp_id_consumer.cc
intern/asset_type.cc
intern/asset_view_catalog_filter.cc
ED_asset_catalog.h
ED_asset_catalog.hh
@ -56,6 +57,7 @@ set(SRC
ED_asset_mark_clear.h
ED_asset_temp_id_consumer.h
ED_asset_type.h
ED_asset_view_catalog_filter.h
intern/asset_library_reference.hh
)

View File

@ -24,6 +24,7 @@
extern "C" {
#endif
struct AssetCatalogFilterSettings;
struct AssetFilterSettings;
struct AssetHandle;
struct AssetLibrary;
@ -40,8 +41,11 @@ void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_refe
const struct bContext *C);
void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference,
const struct bContext *C);
void ED_assetlist_catalog_filter_set(const struct AssetLibraryReference *,
const struct AssetCatalogFilterSettings *catalog_filter);
void ED_assetlist_clear(const struct AssetLibraryReference *library_reference, struct bContext *C);
bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference);
/**
* Tag all asset lists in the storage that show main data as needing an update (re-fetch).
*

View File

@ -0,0 +1,51 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup edasset
*/
#pragma once
#include "DNA_space_types.h"
struct AssetLibrary;
struct AssetMetaData;
struct bUUID;
#ifdef __cplusplus
extern "C" {
#endif
typedef struct AssetViewCatalogFilterSettingsHandle AssetViewCatalogFilterSettingsHandle;
AssetViewCatalogFilterSettingsHandle *asset_view_create_catalog_filter_settings(void);
void asset_view_delete_catalog_filter_settings(
AssetViewCatalogFilterSettingsHandle **filter_settings_handle);
bool asset_view_set_catalog_filter_settings(
AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
AssetCatalogFilterMode catalog_visibility,
bUUID catalog_id);
void asset_view_ensure_updated_catalog_filter_data(
AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
const AssetLibrary *asset_library);
bool asset_view_is_asset_visible_in_catalog_filter_settings(
const AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
const AssetMetaData *asset_data);
#ifdef __cplusplus
}
#endif

View File

@ -124,6 +124,7 @@ class AssetList : NonCopyable {
void setup();
void fetch(const bContext &C);
void setCatalogFilterSettings(const AssetCatalogFilterSettings &settings);
void ensurePreviewsJob(const bContext *C);
void clear(bContext *C);
@ -163,7 +164,7 @@ void AssetList::setup()
filelist_setlibrary(files, &library_ref_);
filelist_setfilter_options(
files,
false,
true,
true,
true, /* Just always hide parent, prefer to not add an extra user option for this. */
FILE_TYPE_BLENDERLIB,
@ -203,6 +204,14 @@ void AssetList::fetch(const bContext &C)
filelist_filter(files);
}
void AssetList::setCatalogFilterSettings(const AssetCatalogFilterSettings &settings)
{
filelist_set_asset_catalog_filter_options(
filelist_,
(AssetCatalogFilterMode)settings.filter_mode,
&settings.active_catalog_id);
}
bool AssetList::needsRefetch() const
{
return filelist_needs_force_reset(filelist_) || filelist_needs_reading(filelist_);
@ -452,6 +461,15 @@ void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_refer
}
}
void ED_assetlist_catalog_filter_set(const struct AssetLibraryReference *library_reference,
const struct AssetCatalogFilterSettings *settings)
{
AssetList *list = AssetListStorage::lookup_list(*library_reference);
if (list) {
list->setCatalogFilterSettings(*settings);
}
}
void ED_assetlist_clear(const AssetLibraryReference *library_reference, bContext *C)
{
AssetList *list = AssetListStorage::lookup_list(*library_reference);

View File

@ -0,0 +1,110 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup edasset
*/
#include <memory>
#include "DNA_space_types.h"
#include "BKE_asset_catalog.hh"
#include "BKE_asset_library.hh"
#include "ED_asset_view_catalog_filter.h"
namespace bke = blender::bke;
struct AssetViewCatalogFilter {
AssetCatalogFilterSettings filter_settings;
std::unique_ptr<bke::AssetCatalogFilter> catalog_filter;
};
AssetViewCatalogFilterSettingsHandle *asset_view_create_catalog_filter_settings()
{
AssetViewCatalogFilter *filter_settings = MEM_new<AssetViewCatalogFilter>(__func__);
return reinterpret_cast<AssetViewCatalogFilterSettingsHandle *>(filter_settings);
}
void asset_view_delete_catalog_filter_settings(
AssetViewCatalogFilterSettingsHandle **filter_settings_handle)
{
AssetViewCatalogFilter **filter_settings = reinterpret_cast<AssetViewCatalogFilter **>(
filter_settings_handle);
MEM_delete(*filter_settings);
*filter_settings = nullptr;
}
bool asset_view_set_catalog_filter_settings(
AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
AssetCatalogFilterMode catalog_visibility,
::bUUID catalog_id)
{
AssetViewCatalogFilter *filter_settings = reinterpret_cast<AssetViewCatalogFilter *>(
filter_settings_handle);
bool needs_update = false;
if (filter_settings->filter_settings.filter_mode != catalog_visibility) {
filter_settings->filter_settings.filter_mode = catalog_visibility;
needs_update = true;
}
if (filter_settings->filter_settings.filter_mode == ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG &&
!BLI_uuid_equal(filter_settings->filter_settings.active_catalog_id, catalog_id)) {
filter_settings->filter_settings.active_catalog_id = catalog_id;
needs_update = true;
}
return needs_update;
}
void asset_view_ensure_updated_catalog_filter_data(
AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
const ::AssetLibrary *asset_library)
{
AssetViewCatalogFilter *filter_settings = reinterpret_cast<AssetViewCatalogFilter *>(
filter_settings_handle);
const bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(
asset_library);
if (filter_settings->filter_settings.filter_mode != ASSET_CATALOG_SHOW_ALL_ASSETS) {
filter_settings->catalog_filter = std::make_unique<bke::AssetCatalogFilter>(
catalog_service->create_catalog_filter(
filter_settings->filter_settings.active_catalog_id));
}
}
bool asset_view_is_asset_visible_in_catalog_filter_settings(
const AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
const AssetMetaData *asset_data)
{
const AssetViewCatalogFilter *filter_settings = reinterpret_cast<const AssetViewCatalogFilter *>(
filter_settings_handle);
switch (filter_settings->filter_settings.filter_mode) {
case ASSET_CATALOG_SHOW_ASSETS_WITHOUT_CATALOG:
return !filter_settings->catalog_filter->is_known(asset_data->catalog_id);
case ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG:
return filter_settings->catalog_filter->contains(asset_data->catalog_id);
case ASSET_CATALOG_SHOW_ALL_ASSETS:
/* All asset files should be visible. */
return true;
}
BLI_assert_unreachable();
return false;
}

View File

@ -50,7 +50,8 @@ void asset_browser_main_region_draw(const bContext *C, ARegion *region)
uiLayout *layout = UI_block_layout(
block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, style->panelspace, 0, region->winx, 1, 0, style);
asset_view_create_in_layout(*C, asset_space->asset_library_ref, *layout);
asset_view_create_in_layout(
*C, asset_space->asset_library_ref, asset_space->catalog_filter, *layout);
/* Update main region View2d dimensions. */
int layout_width, layout_height;

View File

@ -224,12 +224,12 @@ AssetCatalogTreeViewAllItem &AssetCatalogTreeView::add_all_item()
{
AssetCatalogTreeViewAllItem &item = add_tree_item<AssetCatalogTreeViewAllItem>(IFACE_("All"));
item.set_on_activate_fn([this](ui::BasicTreeViewItem & /*item*/) {
catalog_filter_.filter_mode = FILE_SHOW_ASSETS_ALL_CATALOGS;
catalog_filter_.filter_mode = ASSET_CATALOG_SHOW_ALL_ASSETS;
/* TODO */
// WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
});
item.set_is_active_fn(
[this]() { return catalog_filter_.filter_mode == FILE_SHOW_ASSETS_ALL_CATALOGS; });
[this]() { return catalog_filter_.filter_mode == ASSET_CATALOG_SHOW_ALL_ASSETS; });
return item;
}
@ -239,17 +239,17 @@ void AssetCatalogTreeView::add_unassigned_item()
IFACE_("Unassigned"), ICON_FILE_HIDDEN);
item.set_on_activate_fn([this](ui::BasicTreeViewItem & /*item*/) {
catalog_filter_.filter_mode = FILE_SHOW_ASSETS_WITHOUT_CATALOG;
catalog_filter_.filter_mode = ASSET_CATALOG_SHOW_ASSETS_WITHOUT_CATALOG;
/* TODO */
// WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
});
item.set_is_active_fn(
[this]() { return catalog_filter_.filter_mode == FILE_SHOW_ASSETS_WITHOUT_CATALOG; });
[this]() { return catalog_filter_.filter_mode == ASSET_CATALOG_SHOW_ASSETS_WITHOUT_CATALOG; });
}
void AssetCatalogTreeView::activate_catalog_by_id(CatalogID catalog_id)
{
catalog_filter_.filter_mode = FILE_SHOW_ASSETS_FROM_CATALOG;
catalog_filter_.filter_mode = ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG;
catalog_filter_.active_catalog_id = catalog_id;
/* TODO */
// WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
@ -257,7 +257,7 @@ void AssetCatalogTreeView::activate_catalog_by_id(CatalogID catalog_id)
bool AssetCatalogTreeView::is_active_catalog(CatalogID catalog_id) const
{
return (catalog_filter_.filter_mode == FILE_SHOW_ASSETS_FROM_CATALOG) &&
return (catalog_filter_.filter_mode == ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG) &&
(catalog_filter_.active_catalog_id == catalog_id);
}
@ -661,99 +661,6 @@ bool AssetCatalogTreeViewUnassignedItem::DropController::on_drop(struct bContext
/* ---------------------------------------------------------------------- */
#if 0
namespace blender::ed::asset_browser {
class AssetCatalogFilterSettings {
public:
eFileSel_Params_AssetCatalogVisibility asset_catalog_visibility;
bUUID asset_catalog_id;
std::unique_ptr<AssetCatalogFilter> catalog_filter;
};
} // namespace blender::ed::asset_browser
using namespace blender::ed::asset_browser;
FileAssetCatalogFilterSettingsHandle *file_create_asset_catalog_filter_settings()
{
AssetCatalogFilterSettings *filter_settings = MEM_new<AssetCatalogFilterSettings>(__func__);
return reinterpret_cast<FileAssetCatalogFilterSettingsHandle *>(filter_settings);
}
void file_delete_asset_catalog_filter_settings(
FileAssetCatalogFilterSettingsHandle **filter_settings_handle)
{
AssetCatalogFilterSettings **filter_settings = reinterpret_cast<AssetCatalogFilterSettings **>(
filter_settings_handle);
MEM_delete(*filter_settings);
*filter_settings = nullptr;
}
bool file_set_asset_catalog_filter_settings(
FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
eFileSel_Params_AssetCatalogVisibility catalog_visibility,
::bUUID catalog_id)
{
AssetCatalogFilterSettings *filter_settings = reinterpret_cast<AssetCatalogFilterSettings *>(
filter_settings_handle);
bool needs_update = false;
if (filter_settings->asset_catalog_visibility != catalog_visibility) {
filter_settings->asset_catalog_visibility = catalog_visibility;
needs_update = true;
}
if (filter_settings->asset_catalog_visibility == FILE_SHOW_ASSETS_FROM_CATALOG &&
!BLI_uuid_equal(filter_settings->asset_catalog_id, catalog_id)) {
filter_settings->asset_catalog_id = catalog_id;
needs_update = true;
}
return needs_update;
}
void file_ensure_updated_catalog_filter_data(
FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
const ::AssetLibrary *asset_library)
{
AssetCatalogFilterSettings *filter_settings = reinterpret_cast<AssetCatalogFilterSettings *>(
filter_settings_handle);
const AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(
asset_library);
if (filter_settings->asset_catalog_visibility != FILE_SHOW_ASSETS_ALL_CATALOGS) {
filter_settings->catalog_filter = std::make_unique<AssetCatalogFilter>(
catalog_service->create_catalog_filter(filter_settings->asset_catalog_id));
}
}
bool file_is_asset_visible_in_catalog_filter_settings(
const FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
const AssetMetaData *asset_data)
{
const AssetCatalogFilterSettings *filter_settings =
reinterpret_cast<const AssetCatalogFilterSettings *>(filter_settings_handle);
switch (filter_settings->asset_catalog_visibility) {
case FILE_SHOW_ASSETS_WITHOUT_CATALOG:
return !filter_settings->catalog_filter->is_known(asset_data->catalog_id);
case FILE_SHOW_ASSETS_FROM_CATALOG:
return filter_settings->catalog_filter->contains(asset_data->catalog_id);
case FILE_SHOW_ASSETS_ALL_CATALOGS:
/* All asset files should be visible. */
return true;
}
BLI_assert_unreachable();
return false;
}
#endif
/* ---------------------------------------------------------------------- */
void asset_brower_create_catalog_tree_view_in_layout(::AssetLibrary *asset_library,
uiLayout *layout,
SpaceAssets *assets_space)

View File

@ -54,6 +54,7 @@ bool AssetGridView::listen(const wmNotifier &notifier) const
void asset_view_create_in_layout(const bContext &C,
const AssetLibraryReference &asset_library_ref,
const AssetCatalogFilterSettings &catalog_filter_settings,
uiLayout &layout)
{
uiBlock *block = uiLayoutGetBlock(&layout);
@ -61,6 +62,7 @@ void asset_view_create_in_layout(const bContext &C,
ED_assetlist_storage_fetch(&asset_library_ref, &C);
ED_assetlist_ensure_previews_job(&asset_library_ref, &C);
ED_assetlist_catalog_filter_set(&asset_library_ref, &catalog_filter_settings);
ui::AbstractGridView *grid_view = UI_block_add_view(
*block, "asset grid view", std::make_unique<AssetGridView>(asset_library_ref, layout));

View File

@ -20,10 +20,12 @@
#pragma once
#include "DNA_asset_types.h"
#include "UI_grid_view.hh"
struct AssetCatalogFilterSettings;
struct bContext;
struct AssetLibraryReference;
struct uiLayout;
namespace blender::ed::asset_browser {
@ -43,6 +45,7 @@ class AssetGridView : public blender::ui::AbstractGridView {
void asset_view_create_in_layout(const bContext &C,
const AssetLibraryReference &asset_library_ref,
const struct AssetCatalogFilterSettings &catalog_filter_settings,
uiLayout &layout);
} // namespace blender::ed::asset_browser

View File

@ -185,7 +185,7 @@ void ED_spacetype_assets(void)
art->draw = ED_region_header_draw;
BLI_addhead(&st->regiontypes, art);
/* regions: navigation window */
/* Navigation region */
art = MEM_cnew<ARegionType>("spacetype asset browser navigation region");
art->regionid = RGN_TYPE_NAV_BAR;
art->prefsizex = UI_COMPACT_PANEL_WIDTH;

View File

@ -230,11 +230,11 @@ AssetCatalogTreeViewAllItem &AssetCatalogTreeView::add_all_item()
AssetCatalogTreeViewAllItem &item = add_tree_item<AssetCatalogTreeViewAllItem>(IFACE_("All"));
item.set_on_activate_fn([params](ui::BasicTreeViewItem & /*item*/) {
params->asset_catalog_visibility = FILE_SHOW_ASSETS_ALL_CATALOGS;
params->asset_catalog_visibility = ASSET_CATALOG_SHOW_ALL_ASSETS;
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
});
item.set_is_active_fn(
[params]() { return params->asset_catalog_visibility == FILE_SHOW_ASSETS_ALL_CATALOGS; });
[params]() { return params->asset_catalog_visibility == ASSET_CATALOG_SHOW_ALL_ASSETS; });
return item;
}
@ -246,23 +246,23 @@ void AssetCatalogTreeView::add_unassigned_item()
IFACE_("Unassigned"), ICON_FILE_HIDDEN);
item.set_on_activate_fn([params](ui::BasicTreeViewItem & /*item*/) {
params->asset_catalog_visibility = FILE_SHOW_ASSETS_WITHOUT_CATALOG;
params->asset_catalog_visibility = ASSET_CATALOG_SHOW_ASSETS_WITHOUT_CATALOG;
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
});
item.set_is_active_fn(
[params]() { return params->asset_catalog_visibility == FILE_SHOW_ASSETS_WITHOUT_CATALOG; });
[params]() { return params->asset_catalog_visibility == ASSET_CATALOG_SHOW_ASSETS_WITHOUT_CATALOG; });
}
void AssetCatalogTreeView::activate_catalog_by_id(CatalogID catalog_id)
{
params_->asset_catalog_visibility = FILE_SHOW_ASSETS_FROM_CATALOG;
params_->asset_catalog_visibility = ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG;
params_->catalog_id = catalog_id;
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
}
bool AssetCatalogTreeView::is_active_catalog(CatalogID catalog_id) const
{
return (params_->asset_catalog_visibility == FILE_SHOW_ASSETS_FROM_CATALOG) &&
return (params_->asset_catalog_visibility == ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG) &&
(params_->catalog_id == catalog_id);
}
@ -663,95 +663,7 @@ bool AssetCatalogTreeViewUnassignedItem::DropController::on_drop(struct bContext
/* ---------------------------------------------------------------------- */
namespace blender::ed::space_file::asset_browser {
class AssetCatalogViewFilter {
public:
eFileSel_Params_AssetCatalogVisibility asset_catalog_visibility;
bUUID asset_catalog_id;
std::unique_ptr<AssetCatalogFilter> catalog_filter;
};
} // namespace blender::ed::space_file::asset_browser
using namespace blender::ed::space_file::asset_browser;
FileAssetCatalogFilterSettingsHandle *file_create_asset_catalog_filter_settings()
{
AssetCatalogViewFilter *filter_settings = MEM_new<AssetCatalogViewFilter>(__func__);
return reinterpret_cast<FileAssetCatalogFilterSettingsHandle *>(filter_settings);
}
void file_delete_asset_catalog_filter_settings(
FileAssetCatalogFilterSettingsHandle **filter_settings_handle)
{
AssetCatalogViewFilter **filter_settings = reinterpret_cast<AssetCatalogViewFilter **>(
filter_settings_handle);
MEM_delete(*filter_settings);
*filter_settings = nullptr;
}
bool file_set_asset_catalog_filter_settings(
FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
eFileSel_Params_AssetCatalogVisibility catalog_visibility,
::bUUID catalog_id)
{
AssetCatalogViewFilter *filter_settings = reinterpret_cast<AssetCatalogViewFilter *>(
filter_settings_handle);
bool needs_update = false;
if (filter_settings->asset_catalog_visibility != catalog_visibility) {
filter_settings->asset_catalog_visibility = catalog_visibility;
needs_update = true;
}
if (filter_settings->asset_catalog_visibility == FILE_SHOW_ASSETS_FROM_CATALOG &&
!BLI_uuid_equal(filter_settings->asset_catalog_id, catalog_id)) {
filter_settings->asset_catalog_id = catalog_id;
needs_update = true;
}
return needs_update;
}
void file_ensure_updated_catalog_filter_data(
FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
const ::AssetLibrary *asset_library)
{
AssetCatalogViewFilter *filter_settings = reinterpret_cast<AssetCatalogViewFilter *>(
filter_settings_handle);
const AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(
asset_library);
if (filter_settings->asset_catalog_visibility != FILE_SHOW_ASSETS_ALL_CATALOGS) {
filter_settings->catalog_filter = std::make_unique<AssetCatalogFilter>(
catalog_service->create_catalog_filter(filter_settings->asset_catalog_id));
}
}
bool file_is_asset_visible_in_catalog_filter_settings(
const FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
const AssetMetaData *asset_data)
{
const AssetCatalogViewFilter *filter_settings = reinterpret_cast<const AssetCatalogViewFilter *>(
filter_settings_handle);
switch (filter_settings->asset_catalog_visibility) {
case FILE_SHOW_ASSETS_WITHOUT_CATALOG:
return !filter_settings->catalog_filter->is_known(asset_data->catalog_id);
case FILE_SHOW_ASSETS_FROM_CATALOG:
return filter_settings->catalog_filter->contains(asset_data->catalog_id);
case FILE_SHOW_ASSETS_ALL_CATALOGS:
/* All asset files should be visible. */
return true;
}
BLI_assert_unreachable();
return false;
}
/* ---------------------------------------------------------------------- */
namespace asset_browser = blender::ed::space_file::asset_browser;
void file_create_asset_catalog_tree_view_in_layout(::AssetLibrary *asset_library,
uiLayout *layout,
@ -765,7 +677,7 @@ void file_create_asset_catalog_tree_view_in_layout(::AssetLibrary *asset_library
ui::AbstractTreeView *tree_view = UI_block_add_view(
*block,
"asset catalog tree view",
std::make_unique<AssetCatalogTreeView>(asset_library, params, *space_file));
std::make_unique<asset_browser::AssetCatalogTreeView>(asset_library, params, *space_file));
ui::TreeViewBuilder builder(*block);
builder.build_tree_view(*tree_view);

View File

@ -213,27 +213,6 @@ void file_path_to_ui_path(const char *path, char *r_pathi, int max_size);
/* asset_catalog_tree_view.cc */
/* C-handle for #ed::asset_browser::AssetCatalogFilterSettings. */
typedef struct FileAssetCatalogFilterSettingsHandle FileAssetCatalogFilterSettingsHandle;
FileAssetCatalogFilterSettingsHandle *file_create_asset_catalog_filter_settings(void);
void file_delete_asset_catalog_filter_settings(
FileAssetCatalogFilterSettingsHandle **filter_settings_handle);
/**
* \return True if the file list should update its filtered results
* (e.g. because filtering parameters changed).
*/
bool file_set_asset_catalog_filter_settings(
FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
eFileSel_Params_AssetCatalogVisibility catalog_visibility,
bUUID catalog_id);
void file_ensure_updated_catalog_filter_data(
FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
const struct AssetLibrary *asset_library);
bool file_is_asset_visible_in_catalog_filter_settings(
const FileAssetCatalogFilterSettingsHandle *filter_settings_handle,
const AssetMetaData *asset_data);
void file_create_asset_catalog_tree_view_in_layout(struct AssetLibrary *asset_library,
struct uiLayout *layout,
struct SpaceFile *space_file,

View File

@ -71,6 +71,7 @@
#include "DNA_asset_types.h"
#include "DNA_space_types.h"
#include "ED_asset_view_catalog_filter.h"
#include "ED_datafiles.h"
#include "ED_fileselect.h"
#include "ED_screen.h"
@ -372,7 +373,7 @@ typedef struct FileListFilter {
char filter_search[66]; /* + 2 for heading/trailing implicit '*' wildcards. */
short flags;
FileAssetCatalogFilterSettingsHandle *asset_catalog_filter;
AssetViewCatalogFilterSettingsHandle *asset_catalog_filter;
} FileListFilter;
/* FileListFilter.flags */
@ -955,7 +956,8 @@ static void prepare_filter_asset_library(const FileList *filelist, FileListFilte
"prepare_filter_asset_library() should only be called when the file browser is "
"in asset browser mode");
file_ensure_updated_catalog_filter_data(filter->asset_catalog_filter, filelist->asset_library);
asset_view_ensure_updated_catalog_filter_data(filter->asset_catalog_filter,
filelist->asset_library);
}
/**
@ -985,7 +987,7 @@ static bool is_filtered_asset(FileListInternEntry *file, FileListFilter *filter)
const AssetMetaData *asset_data = filelist_file_internal_get_asset_data(file);
/* Not used yet for the asset view template. */
if (filter->asset_catalog_filter && !file_is_asset_visible_in_catalog_filter_settings(
if (filter->asset_catalog_filter && !asset_view_is_asset_visible_in_catalog_filter_settings(
filter->asset_catalog_filter, asset_data)) {
return false;
}
@ -1175,15 +1177,15 @@ void filelist_setindexer(FileList *filelist, const FileIndexerType *indexer)
void filelist_set_asset_catalog_filter_options(
FileList *filelist,
eFileSel_Params_AssetCatalogVisibility catalog_visibility,
AssetCatalogFilterMode catalog_visibility,
const bUUID *catalog_id)
{
if (!filelist->filter_data.asset_catalog_filter) {
/* There's no filter data yet. */
filelist->filter_data.asset_catalog_filter = file_create_asset_catalog_filter_settings();
filelist->filter_data.asset_catalog_filter = asset_view_create_catalog_filter_settings();
}
const bool needs_update = file_set_asset_catalog_filter_settings(
const bool needs_update = asset_view_set_catalog_filter_settings(
filelist->filter_data.asset_catalog_filter, catalog_visibility, *catalog_id);
if (needs_update) {
@ -1934,7 +1936,7 @@ static void filelist_clear_asset_library(FileList *filelist)
{
/* The AssetLibraryService owns the AssetLibrary pointer, so no need for us to free it. */
filelist->asset_library = NULL;
file_delete_asset_catalog_filter_settings(&filelist->filter_data.asset_catalog_filter);
asset_view_delete_catalog_filter_settings(&filelist->filter_data.asset_catalog_filter);
}
void filelist_clear_ex(struct FileList *filelist,

View File

@ -82,11 +82,11 @@ void filelist_setfilter_options(struct FileList *filelist,
void filelist_setindexer(struct FileList *filelist, const struct FileIndexerType *indexer);
/**
* \param catalog_id: The catalog that should be filtered by if \a catalog_visibility is
* #FILE_SHOW_ASSETS_FROM_CATALOG. May be NULL otherwise.
* #ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG. May be NULL otherwise.
*/
void filelist_set_asset_catalog_filter_options(
struct FileList *filelist,
eFileSel_Params_AssetCatalogVisibility catalog_visibility,
AssetCatalogFilterMode catalog_visibility,
const struct bUUID *catalog_id);
void filelist_tag_needs_filtering(struct FileList *filelist);
void filelist_filter(struct FileList *filelist);

View File

@ -500,7 +500,7 @@ void ED_fileselect_activate_asset_catalog(const SpaceFile *sfile, const bUUID ca
}
FileAssetSelectParams *params = ED_fileselect_get_asset_params(sfile);
params->asset_catalog_visibility = FILE_SHOW_ASSETS_FROM_CATALOG;
params->asset_catalog_visibility = ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG;
params->catalog_id = catalog_id;
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, NULL);
}

View File

@ -826,9 +826,9 @@ typedef struct FileAssetSelectParams {
FileSelectParams base_params;
AssetLibraryReference asset_library_ref;
short asset_catalog_visibility; /* eFileSel_Params_AssetCatalogVisibility */
short asset_catalog_visibility; /* AssetCatalogFilterMode */
char _pad[6];
/** If #asset_catalog_visibility is #FILE_SHOW_ASSETS_FROM_CATALOG, this sets the ID of the
/** If #asset_catalog_visibility is #ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG, this sets the ID of the
* catalog to show. */
bUUID catalog_id;
@ -1038,13 +1038,6 @@ typedef enum eFileSel_Params_Flag {
FILE_FILTER_ASSET_CATALOG = (1 << 15),
} eFileSel_Params_Flag;
/* TODO rename */
typedef enum eFileSel_Params_AssetCatalogVisibility {
FILE_SHOW_ASSETS_ALL_CATALOGS,
FILE_SHOW_ASSETS_FROM_CATALOG,
FILE_SHOW_ASSETS_WITHOUT_CATALOG,
} eFileSel_Params_AssetCatalogVisibility;
/**
* #FileSelectParams.rename_flag / `sfile->params->rename_flag`.
* \note short flag. Defined as bit-flags, but currently only used as exclusive status markers.
@ -2040,10 +2033,16 @@ typedef enum eSpreadsheetColumnValueType {
/** \name Asset Browser
* \{ */
typedef enum AssetCatalogFilterMode {
ASSET_CATALOG_SHOW_ALL_ASSETS,
ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG,
ASSET_CATALOG_SHOW_ASSETS_WITHOUT_CATALOG,
} AssetCatalogFilterMode;
typedef struct AssetCatalogFilterSettings {
short filter_mode; /* eFileSel_Params_AssetCatalogVisibility */
short filter_mode; /* AssetCatalogFilterMode */
char _pad[6];
/** If #visibility_mode is #FILE_SHOW_ASSETS_FROM_CATALOG, this sets the ID of the
/** If #visibility_mode is #ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG, this sets the ID of the
* catalog to show. */
bUUID active_catalog_id;
} AssetCatalogFilterSettings;