diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_asset_catalog.hh | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/asset_catalog.cc | 26 |
2 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh index 766a3f34a66..bdb77571711 100644 --- a/source/blender/blenkernel/BKE_asset_catalog.hh +++ b/source/blender/blenkernel/BKE_asset_catalog.hh @@ -98,6 +98,15 @@ class AssetCatalogService { bool write_to_disk(const CatalogFilePath &blend_file_path); /** + * 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. */ + void prepare_to_merge_on_write(); + + /** * Merge on-disk changes into the in-memory asset catalogs. * This should be called before writing the asset catalogs to disk. * @@ -238,6 +247,11 @@ class AssetCatalogService { */ void create_missing_catalogs(); + /** + * For every catalog, mark it as "dirty". + */ + void tag_all_catalogs_as_unsaved_changes(); + /* For access by subclasses, as those will not be marked as friend by #AssetCatalogCollection. */ AssetCatalogDefinitionFile *get_catalog_definition_file(); OwningAssetCatalogMap &get_catalogs(); diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc index 13f66445c46..33405c9aeae 100644 --- a/source/blender/blenkernel/intern/asset_catalog.cc +++ b/source/blender/blenkernel/intern/asset_catalog.cc @@ -103,6 +103,14 @@ bool AssetCatalogService::has_unsaved_changes() const return catalog_collection_->has_unsaved_changes_; } +void AssetCatalogService::tag_all_catalogs_as_unsaved_changes() +{ + for (auto &catalog : catalog_collection_->catalogs_.values()) { + catalog->flags.has_unsaved_changes = true; + } + catalog_collection_->has_unsaved_changes_ = true; +} + bool AssetCatalogService::is_empty() const { BLI_assert(catalog_collection_); @@ -491,6 +499,24 @@ bool AssetCatalogService::write_to_disk_ex(const CatalogFilePath &blend_file_pat return catalog_collection_->catalog_definition_file_->write_to_disk(); } +void AssetCatalogService::prepare_to_merge_on_write() +{ + /* TODO(Sybren): expand to support multiple CDFs. */ + + if (!catalog_collection_->catalog_definition_file_) { + /* There is no CDF connected, so it's a no-op. */ + return; + } + + /* Remove any association with the CDF, so that a new location will be chosen + * when the blend file is saved. */ + catalog_collection_->catalog_definition_file_.reset(); + + /* Mark all in-memory catalogs as "dirty", to force them to be kept around on + * the next "load-merge-write" cycle. */ + tag_all_catalogs_as_unsaved_changes(); +} + CatalogFilePath AssetCatalogService::find_suitable_cdf_path_for_writing( const CatalogFilePath &blend_file_path) { |