Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-12 13:39:24 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-12 13:42:44 +0300
commita06435e43a6516207c617c2b4ad9961f865b66d8 (patch)
treed21e378f4c33f1d203cefeeca03dbefa81691158 /source/blender/blenkernel/BKE_asset_catalog.hh
parentb67a9373945d07700b378aaa8be06aa2fd6d2cb9 (diff)
Asset Catalogs: undo stack for catalog edits
Add an undo stack for catalog edits. This only implements the backend, no operators or UI yet. A bunch of `this->xxx` has been replaced by `catalog_collection_->xxx`. Things are getting a bit long, and the class is turning into a god object; refactoring the class is tracked in T92114. Reviewed By: Severin Maniphest Tasks: T92047 Differential Revision: https://developer.blender.org/D12825
Diffstat (limited to 'source/blender/blenkernel/BKE_asset_catalog.hh')
-rw-r--r--source/blender/blenkernel/BKE_asset_catalog.hh64
1 files changed, 59 insertions, 5 deletions
diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh
index 4ea6abd65e0..b677adefb46 100644
--- a/source/blender/blenkernel/BKE_asset_catalog.hh
+++ b/source/blender/blenkernel/BKE_asset_catalog.hh
@@ -60,7 +60,7 @@ class AssetCatalogService {
static const CatalogFilePath DEFAULT_CATALOG_FILENAME;
public:
- AssetCatalogService() = default;
+ AssetCatalogService();
explicit AssetCatalogService(const CatalogFilePath &asset_library_root);
/** Load asset catalog definitions from the files found in the asset library. */
@@ -143,14 +143,30 @@ class AssetCatalogService {
/** Return true only if there are no catalogs known. */
bool is_empty() const;
+ /**
+ * Store the current catalogs in the undo stack.
+ * This snapshots everything in the #AssetCatalogCollection. */
+ void store_undo_snapshot();
+ /**
+ * 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.
+ */
+ void undo();
+ bool is_undo_possbile() const;
+ /**
+ * 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. */
+ void redo();
+ bool is_redo_possbile() const;
+
protected:
- /* These pointers are owned by this AssetCatalogService. */
- OwningAssetCatalogMap catalogs_;
- OwningAssetCatalogMap deleted_catalogs_;
- std::unique_ptr<AssetCatalogDefinitionFile> catalog_definition_file_;
+ 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_;
+
void load_directory_recursive(const CatalogFilePath &directory_path);
void load_single_file(const CatalogFilePath &catalog_definition_file_path);
@@ -179,6 +195,41 @@ class AssetCatalogService {
* For every catalog, ensure that its parent path also has a known catalog.
*/
void create_missing_catalogs();
+
+ /* For access by subclasses, as those will not be marked as friend by #AssetCatalogCollection. */
+ AssetCatalogDefinitionFile *get_catalog_definition_file();
+ OwningAssetCatalogMap &get_catalogs();
+};
+
+/**
+ * All catalogs that are owned by a single asset library, and managed by a single instance of
+ * #AssetCatalogService. The undo system for asset catalog edits contains historical copies of this
+ * struct.
+ */
+class AssetCatalogCollection {
+ friend AssetCatalogService;
+
+ public:
+ AssetCatalogCollection() = default;
+ AssetCatalogCollection(const AssetCatalogCollection &other) = delete;
+ AssetCatalogCollection(AssetCatalogCollection &&other) noexcept = default;
+
+ std::unique_ptr<AssetCatalogCollection> deep_copy() const;
+
+ protected:
+ /** All catalogs known, except the known-but-deleted ones. */
+ OwningAssetCatalogMap catalogs_;
+
+ /** Catalogs that have been deleted. They are kept around so that the load-merge-save of catalog
+ * definition files can actually delete them if they already existed on disk (instead of the
+ * merge operation resurrecting them). */
+ OwningAssetCatalogMap deleted_catalogs_;
+
+ /* For now only a single catalog definition file is supported.
+ * The aim is to support an arbitrary number of such files per asset library in the future. */
+ std::unique_ptr<AssetCatalogDefinitionFile> catalog_definition_file_;
+
+ static OwningAssetCatalogMap copy_catalog_map(const OwningAssetCatalogMap &orig);
};
/**
@@ -292,6 +343,9 @@ class AssetCatalogDefinitionFile {
void parse_catalog_file(const CatalogFilePath &catalog_definition_file_path,
AssetCatalogParsedFn callback);
+ std::unique_ptr<AssetCatalogDefinitionFile> copy_and_remap(
+ const OwningAssetCatalogMap &catalogs, const OwningAssetCatalogMap &deleted_catalogs) const;
+
protected:
/* Catalogs stored in this file. They are mapped by ID to make it possible to query whether a
* catalog is already known, without having to find the corresponding `AssetCatalog*`. */