Blender
V3.3
|
#include <BKE_asset_catalog.hh>
Static Public Attributes | |
static const CatalogFilePath | DEFAULT_CATALOG_FILENAME = "blender_assets.cats.txt" |
Static Protected Member Functions | |
static CatalogFilePath | find_suitable_cdf_path_for_writing (const CatalogFilePath &blend_file_path) |
Protected Attributes | |
std::unique_ptr< AssetCatalogCollection > | catalog_collection_ |
std::unique_ptr< AssetCatalogTree > | catalog_tree_ = std::make_unique<AssetCatalogTree>() |
CatalogFilePath | asset_library_root_ |
Vector< std::unique_ptr< AssetCatalogCollection > > | undo_snapshots_ |
Vector< std::unique_ptr< AssetCatalogCollection > > | redo_snapshots_ |
Definition at line 44 of file BKE_asset_catalog.hh.
blender::bke::AssetCatalogService::AssetCatalogService | ( | ) |
Definition at line 39 of file blenkernel/intern/asset_catalog.cc.
|
explicit |
Definition at line 44 of file blenkernel/intern/asset_catalog.cc.
|
protected |
Construct an in-memory catalog definition file (CDF) from the currently known catalogs. This object can then be processed further before saving to disk.
Definition at line 532 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by write_to_disk_ex().
AssetCatalog * blender::bke::AssetCatalogService::create_catalog | ( | const AssetCatalogPath & | catalog_path | ) |
Create a catalog with some sensible auto-generated catalog ID. The catalog will be saved to the default catalog file.
Definition at line 258 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert_msg, catalog_collection_, catalog_tree_, and blender::bke::AssetCatalog::from_path().
Referenced by create_missing_catalogs(), ED_asset_catalog_add(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), and blender::bke::tests::TEST_F().
AssetCatalogFilter blender::bke::AssetCatalogService::create_catalog_filter | ( | CatalogID | active_catalog_id | ) | const |
Create a filter object that can be used to determine whether an asset belongs to the given catalog, or any of the catalogs in the sub-tree rooted at the given catalog.
Definition at line 151 of file blenkernel/intern/asset_catalog.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), catalog_collection_, find_catalog(), blender::bke::AssetCatalogPath::is_contained_in(), and blender::bke::AssetCatalog::path.
Referenced by file_ensure_updated_catalog_filter_data(), and blender::bke::tests::TEST_F().
|
protected |
For every catalog, ensure that its parent path also has a known catalog.
Definition at line 568 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, create_catalog(), blender::bke::AssetCatalog::flags, blender::bke::AssetCatalog::Flags::has_unsaved_changes, and blender::bke::AssetCatalogPath::parent().
Referenced by blender::bke::tests::TestableAssetCatalogService::create_missing_catalogs(), and rebuild_tree().
Hard delete a catalog. This simply removes the catalog from existence. The deletion will not be remembered, and reloading the CDF will bring it back.
Definition at line 196 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by purge_catalogs_not_listed().
Delete a catalog, without deleting any of its children and without rebuilding the catalog tree. The deletion in "Soft", in the sense that the catalog pointer is moved from catalogs_
to deleted_catalogs_
; the AssetCatalog instance itself is kept in memory. As a result, it will be removed from a CDF when saved to disk.
This is a lower-level function than prune_catalogs_by_path.
Definition at line 175 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, blender::bke::AssetCatalog::flags, and blender::bke::AssetCatalog::Flags::is_deleted.
Referenced by blender::bke::tests::TestableAssetCatalogService::delete_catalog_by_id_soft(), and prune_catalogs_by_path().
AssetCatalog * blender::bke::AssetCatalogService::find_catalog | ( | CatalogID | catalog_id | ) | const |
Return catalog with the given ID. Return nullptr if not found.
Definition at line 114 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by create_catalog_filter(), ED_asset_catalog_move(), ED_asset_catalog_rename(), blender::ed::asset_browser::AssetCatalogDropController::get_drag_catalog(), prune_catalogs_by_id(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::bke::tests::TEST_F(), and update_catalog_path().
AssetCatalog * blender::bke::AssetCatalogService::find_catalog_by_path | ( | const AssetCatalogPath & | path | ) | const |
Return first catalog with the given path. Return nullptr if not found. This is not an efficient call as it's just a linear search over the catalogs.
If there are multiple catalogs with the same path, return the first-loaded one. If there is none marked as "first loaded", return the one with the lowest UUID.
Definition at line 124 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by catalog_name_exists_fn(), and blender::bke::tests::TEST_F().
|
staticprotected |
Find a suitable path to write a CDF to.
This depends on the location of the blend file, and on whether a CDF already exists next to it or whether the blend file is saved inside an asset library.
Definition at line 503 of file blenkernel/intern/asset_catalog.cc.
References blender::bke::asset_definition_default_file_path_from_dir(), BKE_asset_library_find_suitable_root_path_from_path(), BLI_assert_msg, BLI_path_join(), BLI_split_dir_part(), DEFAULT_CATALOG_FILENAME, NULL, and PATH_MAX.
Referenced by write_to_disk_ex().
|
protected |
Definition at line 109 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by blender::bke::tests::TestableAssetCatalogService::get_catalog_definition_file().
AssetCatalogTree * blender::bke::AssetCatalogService::get_catalog_tree | ( | ) |
Definition at line 545 of file blenkernel/intern/asset_catalog.cc.
References catalog_tree_.
Referenced by BKE_asset_library_get_catalog_tree(), and blender::bke::tests::TEST_F().
|
protected |
Definition at line 100 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by blender::bke::tests::TestableAssetCatalogService::count_catalogs_with_path().
|
protected |
Definition at line 104 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by blender::bke::tests::TestableAssetCatalogService::get_deleted_catalogs().
bool blender::bke::AssetCatalogService::has_unsaved_changes | ( | ) | const |
Definition at line 80 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert, and catalog_collection_.
Referenced by is_catalog_known_with_unsaved_changes().
Return true only if this catalog is known. This treats deleted catalogs as "unknown".
Definition at line 145 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert, and catalog_collection_.
|
protected |
Definition at line 434 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, and has_unsaved_changes().
Referenced by purge_catalogs_not_listed(), and reload_catalogs().
bool blender::bke::AssetCatalogService::is_empty | ( | ) | const |
Return true only if there are no catalogs known.
Definition at line 94 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert, and catalog_collection_.
Referenced by blender::bke::tests::TEST_F().
bool blender::bke::AssetCatalogService::is_redo_possbile | ( | ) | const |
Definition at line 613 of file blenkernel/intern/asset_catalog.cc.
References redo_snapshots_.
Referenced by asset_catalog_redo_poll(), redo(), and blender::bke::tests::TEST_F().
bool blender::bke::AssetCatalogService::is_undo_possbile | ( | ) | const |
Definition at line 608 of file blenkernel/intern/asset_catalog.cc.
References undo_snapshots_.
Referenced by asset_catalog_undo_poll(), blender::bke::tests::TEST_F(), and undo().
|
protected |
Definition at line 324 of file blenkernel/intern/asset_catalog.cc.
References blender::bke::asset_definition_default_file_path_from_dir(), BLI_exists(), CLOG_INFO, load_single_file(), and LOG.
Referenced by load_from_disk().
void blender::bke::AssetCatalogService::load_from_disk | ( | ) |
Load asset catalog definitions from the files found in the asset library.
Definition at line 295 of file blenkernel/intern/asset_catalog.cc.
References asset_library_root_.
Referenced by blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), and blender::bke::tests::TEST_F().
void blender::bke::AssetCatalogService::load_from_disk | ( | const CatalogFilePath & | file_or_directory_path | ) |
Load asset catalog definitions from the given file or directory.
Definition at line 300 of file blenkernel/intern/asset_catalog.cc.
References BLI_stat(), CLOG_WARN, load_directory_recursive(), load_single_file(), LOG, rebuild_tree(), S_ISDIR, and S_ISREG.
|
protected |
Definition at line 339 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert_msg, catalog_collection_, and parse_catalog_file().
Referenced by load_directory_recursive(), and load_from_disk().
|
protected |
Definition at line 351 of file blenkernel/intern/asset_catalog.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), and catalog_collection_.
Referenced by load_single_file().
void blender::bke::AssetCatalogService::prepare_to_merge_on_write | ( | ) |
Ensure that the next call to #on_blend_save_post() will choose a new location for the CDF suitable for the location of the blend file (regardless of where the current catalogs come from), and that catalogs will be merged with already-existing ones in that location.
Use this for a "Save as..." that has to write the catalogs to the new blend file location, instead of updating the previously read CDF.
Definition at line 485 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, and tag_all_catalogs_as_unsaved_changes().
Referenced by asset_bundle_install_exec().
Delete all catalogs with the same path as the identified catalog, and their children. This call is the same as calling prune_catalogs_by_path(find_catalog(catalog_id)->path)
.
Definition at line 224 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert_msg, find_catalog(), blender::bke::AssetCatalog::path, and prune_catalogs_by_path().
Referenced by ED_asset_catalog_remove(), and blender::bke::tests::TEST_F().
void blender::bke::AssetCatalogService::prune_catalogs_by_path | ( | const AssetCatalogPath & | path | ) |
Delete all catalogs with the given path, and their children.
Definition at line 205 of file blenkernel/intern/asset_catalog.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), catalog_collection_, blender::bke::AssetCatalog::catalog_id, delete_catalog_by_id_soft(), blender::bke::AssetCatalogPath::is_contained_in(), blender::bke::AssetCatalog::path, and rebuild_tree().
Referenced by prune_catalogs_by_id(), and blender::bke::tests::TEST_F().
|
protected |
Delete catalogs, only keeping them when they are either listed in catalogs_to_keep or have unsaved changes.
Definition at line 415 of file blenkernel/intern/asset_catalog.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), catalog_collection_, blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), delete_catalog_by_id_hard(), and is_catalog_known_with_unsaved_changes().
Referenced by reload_catalogs().
|
protected |
Definition at line 550 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, and tree.
Referenced by rebuild_tree().
|
protected |
Definition at line 562 of file blenkernel/intern/asset_catalog.cc.
References catalog_tree_, create_missing_catalogs(), and read_into_tree().
Referenced by load_from_disk(), prune_catalogs_by_path(), redo(), reload_catalogs(), undo(), update_catalog_path(), and write_to_disk().
void blender::bke::AssetCatalogService::redo | ( | ) |
Restore the last-saved redo snapshot, pushing the current state onto the undo stack. The caller is responsible for first checking that undoing is possible.
Definition at line 627 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert_msg, catalog_collection_, is_redo_possbile(), rebuild_tree(), redo_snapshots_, and undo_snapshots_.
Referenced by asset_catalog_redo_exec(), and blender::bke::tests::TEST_F().
void blender::bke::AssetCatalogService::reload_catalogs | ( | ) |
Merge on-disk changes into the in-memory asset catalogs. This should be called before writing the asset catalogs to disk.
Definition at line 382 of file blenkernel/intern/asset_catalog.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), BLI_is_file(), catalog_collection_, blender::bke::AssetCatalogDefinitionFile::file_path, is_catalog_known_with_unsaved_changes(), blender::bke::AssetCatalogDefinitionFile::parse_catalog_file(), purge_catalogs_not_listed(), and rebuild_tree().
Referenced by blender::bke::tests::TEST_F(), and write_to_disk_ex().
|
protected |
For every catalog, mark it as "dirty".
Definition at line 86 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_.
Referenced by prepare_to_merge_on_write().
void blender::bke::AssetCatalogService::tag_has_unsaved_changes | ( | AssetCatalog * | edited_catalog | ) |
Set tag indicating that some catalog modifications are unsaved, which could get lost on exit. This tag is not set by internal catalog code, the catalog service user is responsible for it. It is cleared by write_to_disk().
This "dirty" state is tracked per catalog, so that it's possible to gracefully load changes from disk. Any catalog with unsaved changes will not be overwritten by on-disk changes.
Definition at line 50 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert, catalog_collection_, blender::bke::AssetCatalog::flags, and blender::bke::AssetCatalog::Flags::has_unsaved_changes.
Referenced by ED_asset_catalog_add(), ED_asset_catalog_move(), ED_asset_catalog_remove(), ED_asset_catalog_rename(), blender::bke::tests::TEST_F(), and update_catalog_path().
void blender::bke::AssetCatalogService::undo | ( | ) |
Restore the last-saved undo snapshot, pushing the current state onto the redo stack. The caller is responsible for first checking that undoing is possible.
Definition at line 618 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert_msg, catalog_collection_, is_undo_possbile(), rebuild_tree(), redo_snapshots_, and undo_snapshots_.
Referenced by asset_bundle_install_exec(), asset_catalog_undo_exec(), and blender::bke::tests::TEST_F().
void blender::bke::AssetCatalogService::undo_push | ( | ) |
Store the current catalogs in the undo stack. This snapshots everything in the #AssetCatalogCollection.
Definition at line 636 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, redo_snapshots_, and undo_snapshots_.
Referenced by asset_bundle_install_exec(), asset_catalog_undo_push_exec(), ED_asset_catalog_add(), ED_asset_catalog_move(), ED_asset_catalog_remove(), ED_asset_catalog_rename(), ED_asset_catalogs_save_from_main_path(), and blender::bke::tests::TEST_F().
|
protected |
Definition at line 59 of file blenkernel/intern/asset_catalog.cc.
References BLI_assert, and catalog_collection_.
Referenced by write_to_disk().
void blender::bke::AssetCatalogService::update_catalog_path | ( | CatalogID | catalog_id, |
const AssetCatalogPath & | new_catalog_path | ||
) |
Update the catalog path, also updating the catalog path of all sub-catalogs.
Definition at line 234 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, find_catalog(), blender::bke::AssetCatalog::path, blender::bke::AssetCatalogPath::rebase(), rebuild_tree(), blender::bke::AssetCatalog::simple_name_refresh(), and tag_has_unsaved_changes().
Referenced by ED_asset_catalog_move(), ED_asset_catalog_rename(), and blender::bke::tests::TEST_F().
bool blender::bke::AssetCatalogService::write_to_disk | ( | const CatalogFilePath & | blend_file_path | ) |
Write the catalog definitions to disk.
The location where the catalogs are saved is variable, and depends on the location of the blend file. The first matching rule wins:
Return true on success, which either means there were no in-memory categories to save, or the save was successful.
Definition at line 452 of file blenkernel/intern/asset_catalog.cc.
References rebuild_tree(), untag_has_unsaved_changes(), and write_to_disk_ex().
Referenced by ED_asset_catalogs_save_from_main_path(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), and blender::bke::tests::TEST_F().
|
protected |
Implementation of write_to_disk() that doesn't clear the "has unsaved changes" tag.
Definition at line 463 of file blenkernel/intern/asset_catalog.cc.
References catalog_collection_, construct_cdf_in_memory(), find_suitable_cdf_path_for_writing(), and reload_catalogs().
Referenced by write_to_disk().
|
protected |
Definition at line 173 of file BKE_asset_catalog.hh.
Referenced by load_from_disk().
|
protected |
Definition at line 171 of file BKE_asset_catalog.hh.
Referenced by construct_cdf_in_memory(), create_catalog(), create_catalog_filter(), create_missing_catalogs(), delete_catalog_by_id_hard(), delete_catalog_by_id_soft(), find_catalog(), find_catalog_by_path(), get_catalog_definition_file(), get_catalogs(), get_deleted_catalogs(), has_unsaved_changes(), is_catalog_known(), is_catalog_known_with_unsaved_changes(), is_empty(), load_single_file(), parse_catalog_file(), prepare_to_merge_on_write(), prune_catalogs_by_path(), purge_catalogs_not_listed(), read_into_tree(), redo(), reload_catalogs(), tag_all_catalogs_as_unsaved_changes(), tag_has_unsaved_changes(), undo(), undo_push(), untag_has_unsaved_changes(), update_catalog_path(), and write_to_disk_ex().
|
protected |
Definition at line 172 of file BKE_asset_catalog.hh.
Referenced by create_catalog(), get_catalog_tree(), and rebuild_tree().
|
static |
|
protected |
Definition at line 176 of file BKE_asset_catalog.hh.
Referenced by is_redo_possbile(), redo(), undo(), and undo_push().
|
protected |
Definition at line 175 of file BKE_asset_catalog.hh.
Referenced by is_undo_possbile(), redo(), undo(), and undo_push().