1
1

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".
This commit is contained in:
2021-10-21 16:06:14 +02:00
parent 5ccec8ec6b
commit 4b48b1079d
3 changed files with 28 additions and 0 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();