UI: Asset Shelf (Experimental Feature) #104831
|
@ -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->group_component.is_empty());
|
||||||
BLI_assert(!exploded->name_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()) {
|
if (!exploded->dir_component.is_empty()) {
|
||||||
r_path_buffer[exploded->dir_component.size()] = '\0';
|
r_path_buffer[exploded->dir_component.size()] = '\0';
|
||||||
|
|
|
@ -316,10 +316,10 @@ std::optional<AssetLibraryService::ExplodedPath> AssetLibraryService::
|
||||||
std::string path_in_file = utils::normalize_path(asset_reference.relative_asset_identifier);
|
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));
|
const int64_t group_len = int64_t(path_in_file.find(SEP));
|
||||||
|
|
||||||
ExplodedPath exploded{};
|
ExplodedPath exploded;
|
||||||
exploded.full_path = path_in_file;
|
exploded.full_path = std::make_unique<std::string>(path_in_file);
|
||||||
exploded.group_component = StringRef(exploded.full_path).substr(0, group_len);
|
exploded.group_component = StringRef(*exploded.full_path).substr(0, group_len);
|
||||||
exploded.name_component = StringRef(exploded.full_path).substr(group_len + 1);
|
exploded.name_component = StringRef(*exploded.full_path).substr(group_len + 1);
|
||||||
|
|
||||||
return exploded;
|
return exploded;
|
||||||
}
|
}
|
||||||
|
@ -351,9 +351,9 @@ std::optional<AssetLibraryService::ExplodedPath> AssetLibraryService::
|
||||||
const int64_t dir_len = int64_t(group_pos);
|
const int64_t dir_len = int64_t(group_pos);
|
||||||
const int64_t group_len = int64_t(name_pos - group_pos - 1);
|
const int64_t group_len = int64_t(name_pos - group_pos - 1);
|
||||||
|
|
||||||
ExplodedPath exploded{};
|
ExplodedPath exploded;
|
||||||
exploded.full_path = full_path;
|
exploded.full_path = std::make_unique<std::string>(full_path);
|
||||||
StringRef full_path_ref = exploded.full_path;
|
StringRef full_path_ref = *exploded.full_path;
|
||||||
exploded.dir_component = full_path_ref.substr(0, dir_len);
|
exploded.dir_component = full_path_ref.substr(0, dir_len);
|
||||||
exploded.group_component = full_path_ref.substr(dir_len + 1, group_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);
|
exploded.name_component = full_path_ref.substr(dir_len + 1 + group_len + 1);
|
||||||
|
|
|
@ -88,13 +88,14 @@ class AssetLibraryService {
|
||||||
/** Struct to hold results from path explosion functions
|
/** Struct to hold results from path explosion functions
|
||||||
* (#resolve_asset_weak_reference_to_exploded_path()). */
|
* (#resolve_asset_weak_reference_to_exploded_path()). */
|
||||||
struct ExplodedPath {
|
struct ExplodedPath {
|
||||||
/** The string buffer containing the fully resolved path, if resolving was successful. */
|
/** The string buffer containing the fully resolved path, if resolving was successful. Pointer
|
||||||
std::string full_path = "";
|
* 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
|
/** 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). */
|
* with the library .blend file ("directory" is misleading). */
|
||||||
StringRef dir_component = "";
|
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 = "";
|
StringRef group_component = "";
|
||||||
/** Reference into the part of #full_path that is the ID name. */
|
/** Reference into the part of #full_path that is the ID name. */
|
||||||
StringRef name_component = "";
|
StringRef name_component = "";
|
||||||
|
|
|
@ -109,7 +109,7 @@ TEST_F(AssetRepresentationTest, weak_reference__resolve_to_exploded_path__curren
|
||||||
|
|
||||||
std::optional<AssetLibraryService::ExplodedPath> resolved_path =
|
std::optional<AssetLibraryService::ExplodedPath> resolved_path =
|
||||||
service->resolve_asset_weak_reference_to_exploded_path(*weak_ref);
|
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->dir_component, "");
|
||||||
EXPECT_EQ(resolved_path->group_component, "path");
|
EXPECT_EQ(resolved_path->group_component, "path");
|
||||||
/* ID names may contain slashes. */
|
/* 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 =
|
std::optional<AssetLibraryService::ExplodedPath> resolved_path =
|
||||||
service->resolve_asset_weak_reference_to_exploded_path(*weak_ref);
|
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);
|
0);
|
||||||
EXPECT_EQ(BLI_path_cmp_normalized(std::string(resolved_path->dir_component).c_str(),
|
EXPECT_EQ(BLI_path_cmp_normalized(std::string(resolved_path->dir_component).c_str(),
|
||||||
std::string(asset_library_root_ + "/some.blend").c_str()),
|
std::string(asset_library_root_ + "/some.blend").c_str()),
|
||||||
|
|
Loading…
Reference in New Issue