UI: Asset Shelf (Experimental Feature) #104831

Closed
Julian Eisel wants to merge 399 commits from asset-shelf into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 15 additions and 14 deletions
Showing only changes of commit 4710dc0337 - Show all commits

View File

@ -154,7 +154,7 @@ void AS_asset_full_path_explode_from_weak_ref(const AssetWeakReference *asset_re
BLI_assert(!exploded->group_component.is_empty());
BLI_assert(!exploded->name_component.is_empty());
BLI_strncpy(r_path_buffer, exploded->full_path.c_str(), 1090 /* FILE_MAX_LIBEXTRA */);
BLI_strncpy(r_path_buffer, exploded->full_path->c_str(), 1090 /* FILE_MAX_LIBEXTRA */);
if (!exploded->dir_component.is_empty()) {
r_path_buffer[exploded->dir_component.size()] = '\0';

View File

@ -316,10 +316,10 @@ std::optional<AssetLibraryService::ExplodedPath> AssetLibraryService::
std::string path_in_file = utils::normalize_path(asset_reference.relative_asset_identifier);
const int64_t group_len = int64_t(path_in_file.find(SEP));
ExplodedPath exploded{};
exploded.full_path = path_in_file;
exploded.group_component = StringRef(exploded.full_path).substr(0, group_len);
exploded.name_component = StringRef(exploded.full_path).substr(group_len + 1);
ExplodedPath exploded;
exploded.full_path = std::make_unique<std::string>(path_in_file);
exploded.group_component = StringRef(*exploded.full_path).substr(0, group_len);
exploded.name_component = StringRef(*exploded.full_path).substr(group_len + 1);
return exploded;
}
@ -351,9 +351,9 @@ std::optional<AssetLibraryService::ExplodedPath> AssetLibraryService::
const int64_t dir_len = int64_t(group_pos);
const int64_t group_len = int64_t(name_pos - group_pos - 1);
ExplodedPath exploded{};
exploded.full_path = full_path;
StringRef full_path_ref = exploded.full_path;
ExplodedPath exploded;
exploded.full_path = std::make_unique<std::string>(full_path);
StringRef full_path_ref = *exploded.full_path;
exploded.dir_component = full_path_ref.substr(0, dir_len);
exploded.group_component = full_path_ref.substr(dir_len + 1, group_len);
exploded.name_component = full_path_ref.substr(dir_len + 1 + group_len + 1);

View File

@ -88,13 +88,14 @@ class AssetLibraryService {
/** Struct to hold results from path explosion functions
* (#resolve_asset_weak_reference_to_exploded_path()). */
struct ExplodedPath {
/** The string buffer containing the fully resolved path, if resolving was successful. */
std::string full_path = "";
/** The string buffer containing the fully resolved path, if resolving was successful. Pointer
* so that the contained string address doesn't change when moving this object. */
std::unique_ptr<std::string> full_path;
/** Reference into the part of #full_path that is the library directory path. That is, it ends
* with the library .blend file ("directory" is misleading). */
StringRef dir_component = "";
/** Reference into the part of #full_path that is the ID group name ("Object", "Brush", ...).
*/
/** Reference into the part of #full_path that is the ID group name ("Object", "Material",
* "Brush", ...). */
StringRef group_component = "";
/** Reference into the part of #full_path that is the ID name. */
StringRef name_component = "";

View File

@ -109,7 +109,7 @@ TEST_F(AssetRepresentationTest, weak_reference__resolve_to_exploded_path__curren
std::optional<AssetLibraryService::ExplodedPath> resolved_path =
service->resolve_asset_weak_reference_to_exploded_path(*weak_ref);
EXPECT_EQ(resolved_path->full_path, "path/to/an/asset");
EXPECT_EQ(*resolved_path->full_path, "path/to/an/asset");
EXPECT_EQ(resolved_path->dir_component, "");
EXPECT_EQ(resolved_path->group_component, "path");
/* ID names may contain slashes. */
@ -130,7 +130,7 @@ TEST_F(AssetRepresentationTest, weak_reference__resolve_to_exploded_path__custom
std::optional<AssetLibraryService::ExplodedPath> resolved_path =
service->resolve_asset_weak_reference_to_exploded_path(*weak_ref);
EXPECT_EQ(BLI_path_cmp_normalized(resolved_path->full_path.c_str(), expected_full_path.c_str()),
EXPECT_EQ(BLI_path_cmp_normalized(resolved_path->full_path->c_str(), expected_full_path.c_str()),
0);
EXPECT_EQ(BLI_path_cmp_normalized(std::string(resolved_path->dir_component).c_str(),
std::string(asset_library_root_ + "/some.blend").c_str()),