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
path: root/source
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-12 15:45:11 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-12 15:45:11 +0300
commit74ea21ec9dfdff4c5b1c00092427c49044343ca9 (patch)
tree6a13d30217fea12867fad68c21a82b21ec1afde3 /source
parentf1d97a308d4a588694cdd41db57197576f1432c0 (diff)
Asset Catalogs: expose undo/redo operators to UI
Ensure that catalog operations create an undo snapshot, and show undo/redo operators in the asset browser. A hidden operator `ASSET_OT_catalog_undo_push` is also added such that add-ons can also set undo snapshots if they need.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/asset_catalog.cc2
-rw-r--r--source/blender/editors/asset/intern/asset_catalog.cc2
-rw-r--r--source/blender/editors/asset/intern/asset_ops.cc101
-rw-r--r--source/blender/editors/space_file/asset_catalog_tree_view.cc2
4 files changed, 107 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index 2d4956e7e25..2e01d3cdcea 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -485,6 +485,7 @@ void AssetCatalogService::undo()
redo_snapshots_.append(std::move(catalog_collection_));
catalog_collection_ = std::move(undo_snapshots_.pop_last());
+ rebuild_tree();
}
void AssetCatalogService::redo()
@@ -493,6 +494,7 @@ void AssetCatalogService::redo()
undo_snapshots_.append(std::move(catalog_collection_));
catalog_collection_ = std::move(redo_snapshots_.pop_last());
+ rebuild_tree();
}
void AssetCatalogService::undo_push()
diff --git a/source/blender/editors/asset/intern/asset_catalog.cc b/source/blender/editors/asset/intern/asset_catalog.cc
index eb1865ee9cc..056fda63bd7 100644
--- a/source/blender/editors/asset/intern/asset_catalog.cc
+++ b/source/blender/editors/asset/intern/asset_catalog.cc
@@ -66,6 +66,7 @@ AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library,
std::string unique_name = catalog_name_ensure_unique(*catalog_service, name, parent_path);
AssetCatalogPath fullpath = AssetCatalogPath(parent_path) / unique_name;
+ catalog_service->undo_push();
return catalog_service->create_catalog(fullpath);
}
@@ -77,5 +78,6 @@ void ED_asset_catalog_remove(::AssetLibrary *library, const CatalogID &catalog_i
return;
}
+ catalog_service->undo_push();
catalog_service->prune_catalogs_by_id(catalog_id);
}
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc
index 5424bae77b4..28cc16a9376 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -19,6 +19,7 @@
*/
#include "BKE_asset_catalog.hh"
+#include "BKE_asset_library.hh"
#include "BKE_context.h"
#include "BKE_lib_id.h"
#include "BKE_report.h"
@@ -455,6 +456,103 @@ static void ASSET_OT_catalog_delete(struct wmOperatorType *ot)
RNA_def_string(ot->srna, "catalog_id", nullptr, 0, "Catalog ID", "ID of the catalog to delete");
}
+static bke::AssetCatalogService *get_catalog_service(bContext *C)
+{
+ const SpaceFile *sfile = CTX_wm_space_file(C);
+ if (!asset_operation_poll(C) || !sfile) {
+ return nullptr;
+ }
+
+ AssetLibrary *asset_lib = ED_fileselect_active_asset_library_get(sfile);
+ return BKE_asset_library_get_catalog_service(asset_lib);
+}
+
+static int asset_catalog_undo_exec(bContext *C, wmOperator * /*op*/)
+{
+ bke::AssetCatalogService *catalog_service = get_catalog_service(C);
+ if (!catalog_service) {
+ return OPERATOR_CANCELLED;
+ }
+
+ catalog_service->undo();
+ return OPERATOR_FINISHED;
+}
+
+static bool asset_catalog_undo_poll(bContext *C)
+{
+ const bke::AssetCatalogService *catalog_service = get_catalog_service(C);
+ return catalog_service && catalog_service->is_undo_possbile();
+}
+
+static void ASSET_OT_catalog_undo(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Undo Catalog Edits";
+ ot->description = "Undo the last edit to the asset catalogs";
+ ot->idname = "ASSET_OT_catalog_undo";
+
+ /* api callbacks */
+ ot->exec = asset_catalog_undo_exec;
+ ot->poll = asset_catalog_undo_poll;
+}
+
+static int asset_catalog_redo_exec(bContext *C, wmOperator * /*op*/)
+{
+ bke::AssetCatalogService *catalog_service = get_catalog_service(C);
+ if (!catalog_service) {
+ return OPERATOR_CANCELLED;
+ }
+
+ catalog_service->redo();
+ return OPERATOR_FINISHED;
+}
+
+static bool asset_catalog_redo_poll(bContext *C)
+{
+ const bke::AssetCatalogService *catalog_service = get_catalog_service(C);
+ return catalog_service && catalog_service->is_redo_possbile();
+}
+
+static void ASSET_OT_catalog_redo(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "redo Catalog Edits";
+ ot->description = "Redo the last undone edit to the asset catalogs";
+ ot->idname = "ASSET_OT_catalog_redo";
+
+ /* api callbacks */
+ ot->exec = asset_catalog_redo_exec;
+ ot->poll = asset_catalog_redo_poll;
+}
+
+static int asset_catalog_undo_push_exec(bContext *C, wmOperator * /*op*/)
+{
+ bke::AssetCatalogService *catalog_service = get_catalog_service(C);
+ if (!catalog_service) {
+ return OPERATOR_CANCELLED;
+ }
+
+ catalog_service->undo_push();
+ return OPERATOR_FINISHED;
+}
+
+static bool asset_catalog_undo_push_poll(bContext *C)
+{
+ return get_catalog_service(C) != nullptr;
+}
+
+static void ASSET_OT_catalog_undo_push(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Store undo snapshot for asset catalog edits";
+ ot->description = "Store the current state of the asset catalogs in the undo buffer";
+ ot->idname = "ASSET_OT_catalog_undo_push";
+
+ /* api callbacks */
+ ot->exec = asset_catalog_undo_push_exec;
+ ot->poll = asset_catalog_undo_push_poll;
+}
+
/* -------------------------------------------------------------------- */
void ED_operatortypes_asset(void)
@@ -464,6 +562,9 @@ void ED_operatortypes_asset(void)
WM_operatortype_append(ASSET_OT_catalog_new);
WM_operatortype_append(ASSET_OT_catalog_delete);
+ WM_operatortype_append(ASSET_OT_catalog_undo);
+ WM_operatortype_append(ASSET_OT_catalog_redo);
+ WM_operatortype_append(ASSET_OT_catalog_undo_push);
WM_operatortype_append(ASSET_OT_list_refresh);
}
diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc
index 3407be9d8cd..8906cf34288 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -356,6 +356,8 @@ bool AssetCatalogTreeViewItem::rename(StringRefNull new_name)
AssetCatalogPath new_path = catalog_item_.catalog_path().parent();
new_path = new_path / StringRef(new_name);
+
+ tree_view.catalog_service_->undo_push();
tree_view.catalog_service_->update_catalog_path(catalog_item_.get_catalog_id(), new_path);
return true;
}