diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-10-22 17:29:31 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-10-22 17:31:32 +0300 |
commit | 70aad5f498fcd7ed52f3422edda3021e5d4f9538 (patch) | |
tree | bbd80c11425cd55ef01ad67e3a3e57768d1271b5 /source/blender/blenkernel/intern/asset_library_service_test.cc | |
parent | 16ffa7bb6e519edd039683fe83031542d7059d96 (diff) |
Asset Catalogs: support reloading without losing local changes
Keep track of unsaved asset catalog changes, in a more granular way than
just one boolean per asset library. Individual catalogs can now be
marked with a flag `has_unsaved_changes`. This is taken into account
when reloading data from the catalog definition file (CDF):
- New catalog in CDF: gets loaded
- Already-known catalog in CDF:
- local unsaved changes: on-disk catalog is ignored
- otherwise: on-disk catalog replaces in-memory one
- Already-known catalog that does not exist in CDF:
- local unsaved changes: catalog is kept around
- otherwise: catalog is deleted.
Because this saving-is-also-loading behaviour, the "has unsaved changes"
flags are all stored in the undo buffer; undoing after saving will not
change the CDF, but at least it'll undo the loading from disk, and it'll
re-mark any changes as "not saved".
Reviewed By: Severin
Differential Revision: https://developer.blender.org/D12967
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library_service_test.cc')
-rw-r--r-- | source/blender/blenkernel/intern/asset_library_service_test.cc | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/asset_library_service_test.cc b/source/blender/blenkernel/intern/asset_library_service_test.cc index ed132d7a8d8..80504bbdc05 100644 --- a/source/blender/blenkernel/intern/asset_library_service_test.cc +++ b/source/blender/blenkernel/intern/asset_library_service_test.cc @@ -30,6 +30,8 @@ namespace blender::bke::tests { +const bUUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78"); + class AssetLibraryServiceTest : public testing::Test { public: CatalogFilePath asset_library_root_; @@ -162,12 +164,18 @@ TEST_F(AssetLibraryServiceTest, has_any_unsaved_catalogs) const bUUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78"); cat_service->prune_catalogs_by_id(UUID_POSES_ELLIE); EXPECT_FALSE(service->has_any_unsaved_catalogs()) - << "Deletion of catalogs via AssetCatalogService should not tag as 'unsaved changes'."; + << "Deletion of catalogs via AssetCatalogService should not automatically tag as 'unsaved " + "changes'."; + + const bUUID UUID_POSES_RUZENA("79a4f887-ab60-4bd4-94da-d572e27d6aed"); + AssetCatalog *cat = cat_service->find_catalog(UUID_POSES_RUZENA); + ASSERT_NE(nullptr, cat) << "Catalog " << UUID_POSES_RUZENA << " should be known"; - cat_service->tag_has_unsaved_changes(); + cat_service->tag_has_unsaved_changes(cat); EXPECT_TRUE(service->has_any_unsaved_catalogs()) << "Tagging as having unsaved changes of a single catalog service should result in unsaved " "changes being reported."; + EXPECT_TRUE(cat->flags.has_unsaved_changes); } TEST_F(AssetLibraryServiceTest, has_any_unsaved_catalogs_after_write) @@ -185,15 +193,19 @@ TEST_F(AssetLibraryServiceTest, has_any_unsaved_catalogs_after_write) << "Unchanged AssetLibrary should have no unsaved catalogs"; AssetCatalogService *const cat_service = lib->catalog_service.get(); - cat_service->tag_has_unsaved_changes(); + AssetCatalog *cat = cat_service->find_catalog(UUID_POSES_ELLIE); + + cat_service->tag_has_unsaved_changes(cat); EXPECT_TRUE(service->has_any_unsaved_catalogs()) << "Tagging as having unsaved changes of a single catalog service should result in unsaved " "changes being reported."; + EXPECT_TRUE(cat->flags.has_unsaved_changes); cat_service->write_to_disk(writable_dir + "dummy_path.blend"); EXPECT_FALSE(service->has_any_unsaved_catalogs()) << "Written AssetCatalogService should have no unsaved catalogs"; + EXPECT_FALSE(cat->flags.has_unsaved_changes); } } // namespace blender::bke::tests |