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-21 17:06:14 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-21 17:06:14 +0300
commit4b48b1079d9175a5b86b2299c902cac0fbe27f09 (patch)
tree89f4d53d2a715d1aa7aa57733c30189d003a1f85 /source
parent5ccec8ec6bed3e0eda1cffaae565fdfaccd2a6ac (diff)
Asset Catalogs: refresh simple name when renaming catalog
When renaming an asset catalog, also update its simple name. Catalogs will most likely be created from within Blender, so via the catalog tree in the asset browser. Here catalogs are always named "Catalog" until the user renames them, which was reflected in all simple names being "Catalog".
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_asset_catalog.hh3
-rw-r--r--source/blender/blenkernel/intern/asset_catalog.cc9
-rw-r--r--source/blender/blenkernel/intern/asset_catalog_test.cc16
3 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh
index 5de74efe2cf..cbb15780a68 100644
--- a/source/blender/blenkernel/BKE_asset_catalog.hh
+++ b/source/blender/blenkernel/BKE_asset_catalog.hh
@@ -415,6 +415,9 @@ class AssetCatalog {
*/
static std::unique_ptr<AssetCatalog> from_path(const AssetCatalogPath &path);
+ /** Make a new simple name for the catalog, based on its path. */
+ void simple_name_refresh();
+
protected:
/** Generate a sensible catalog ID for the given path. */
static std::string sensible_simple_name_for_path(const AssetCatalogPath &path);
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index 51f8457ebd9..9dd5ccdf3cf 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -219,6 +219,10 @@ void AssetCatalogService::update_catalog_path(const CatalogID catalog_id,
continue;
}
cat->path = new_path;
+ cat->simple_name_refresh();
+
+ /* TODO(Sybren): go over all assets that are assigned to this catalog, defined in the current
+ * blend file, and update the catalog simple name stored there. */
}
this->rebuild_tree();
@@ -953,6 +957,11 @@ std::unique_ptr<AssetCatalog> AssetCatalog::from_path(const AssetCatalogPath &pa
return catalog;
}
+void AssetCatalog::simple_name_refresh()
+{
+ this->simple_name = sensible_simple_name_for_path(this->path);
+}
+
std::string AssetCatalog::sensible_simple_name_for_path(const AssetCatalogPath &path)
{
std::string name = path.str();
diff --git a/source/blender/blenkernel/intern/asset_catalog_test.cc b/source/blender/blenkernel/intern/asset_catalog_test.cc
index 7691658bc57..ebb282a7371 100644
--- a/source/blender/blenkernel/intern/asset_catalog_test.cc
+++ b/source/blender/blenkernel/intern/asset_catalog_test.cc
@@ -882,6 +882,22 @@ TEST_F(AssetCatalogTest, update_catalog_path)
<< "Changing the path should update children.";
}
+TEST_F(AssetCatalogTest, update_catalog_path_simple_name)
+{
+ AssetCatalogService service(asset_library_root_);
+ service.load_from_disk(asset_library_root_ + "/" +
+ AssetCatalogService::DEFAULT_CATALOG_FILENAME);
+ service.update_catalog_path(UUID_POSES_RUZENA, "charlib/Ružena");
+
+ /* This may not be valid forever; maybe at some point we'll expose the simple name to users & let
+ * them change it from the UI. Until then, automatically updating it is better, because otherwise
+ * all simple names would be "Catalog". */
+ EXPECT_EQ("charlib-Ružena", service.find_catalog(UUID_POSES_RUZENA)->simple_name)
+ << "Changing the path should update the simplename.";
+ EXPECT_EQ("charlib-Ružena-face", service.find_catalog(UUID_POSES_RUZENA_FACE)->simple_name)
+ << "Changing the path should update the simplename of children.";
+}
+
TEST_F(AssetCatalogTest, merge_catalog_files)
{
const CatalogFilePath cdf_dir = create_temp_path();