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/editors/asset/intern | |
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/editors/asset/intern')
-rw-r--r-- | source/blender/editors/asset/intern/asset_catalog.cc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source/blender/editors/asset/intern/asset_catalog.cc b/source/blender/editors/asset/intern/asset_catalog.cc index 98f017db20c..af8128ffb8a 100644 --- a/source/blender/editors/asset/intern/asset_catalog.cc +++ b/source/blender/editors/asset/intern/asset_catalog.cc @@ -71,11 +71,11 @@ AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library, AssetCatalogPath fullpath = AssetCatalogPath(parent_path) / unique_name; catalog_service->undo_push(); - catalog_service->tag_has_unsaved_changes(); bke::AssetCatalog *new_catalog = catalog_service->create_catalog(fullpath); if (!new_catalog) { return nullptr; } + catalog_service->tag_has_unsaved_changes(new_catalog); return new_catalog; } @@ -89,7 +89,7 @@ void ED_asset_catalog_remove(::AssetLibrary *library, const CatalogID &catalog_i } catalog_service->undo_push(); - catalog_service->tag_has_unsaved_changes(); + catalog_service->tag_has_unsaved_changes(nullptr); catalog_service->prune_catalogs_by_id(catalog_id); } @@ -103,13 +103,18 @@ void ED_asset_catalog_rename(::AssetLibrary *library, return; } - const AssetCatalog *catalog = catalog_service->find_catalog(catalog_id); + AssetCatalog *catalog = catalog_service->find_catalog(catalog_id); AssetCatalogPath new_path = catalog->path.parent(); new_path = new_path / StringRef(new_name); + if (new_path == catalog->path) { + /* Nothing changed, so don't bother renaming for nothing. */ + return; + } + catalog_service->undo_push(); - catalog_service->tag_has_unsaved_changes(); + catalog_service->tag_has_unsaved_changes(catalog); catalog_service->update_catalog_path(catalog_id, new_path); } |