[Bf-blender-cvs] [d2fc31f178a] temp-bundled-assets: use append-and-reuse for bundled assets
Jacques Lucke
noreply at git.blender.org
Tue Jan 24 19:29:57 CET 2023
Commit: d2fc31f178a1b18e3f4ddaf23f5a8c59efd504ed
Author: Jacques Lucke
Date: Tue Jan 24 19:23:46 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rBd2fc31f178a1b18e3f4ddaf23f5a8c59efd504ed
use append-and-reuse for bundled assets
===================================================================
A source/blender/asset_system/AS_asset_bundled.h
M source/blender/asset_system/AS_asset_bundled.hh
M source/blender/asset_system/intern/asset_bundled.cc
M source/blender/editors/space_file/file_draw.c
===================================================================
diff --git a/source/blender/asset_system/AS_asset_bundled.h b/source/blender/asset_system/AS_asset_bundled.h
new file mode 100644
index 00000000000..e4b03842742
--- /dev/null
+++ b/source/blender/asset_system/AS_asset_bundled.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup asset_system
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool ED_asset_bundle_contains_path(const char *path);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/asset_system/AS_asset_bundled.hh b/source/blender/asset_system/AS_asset_bundled.hh
index 8031e39a144..5f2d4a14780 100644
--- a/source/blender/asset_system/AS_asset_bundled.hh
+++ b/source/blender/asset_system/AS_asset_bundled.hh
@@ -8,6 +8,8 @@
#include "BLI_string_ref.hh"
+#include "AS_asset_bundled.h"
+
namespace blender::asset_system {
StringRefNull bundled_assets_directory_path();
diff --git a/source/blender/asset_system/intern/asset_bundled.cc b/source/blender/asset_system/intern/asset_bundled.cc
index 7e1d4dda009..85db409777b 100644
--- a/source/blender/asset_system/intern/asset_bundled.cc
+++ b/source/blender/asset_system/intern/asset_bundled.cc
@@ -4,6 +4,8 @@
* \ingroup asset_system
*/
+#include "BLI_string.h"
+
#include "BKE_appdir.h"
#include "AS_asset_bundled.hh"
@@ -20,3 +22,10 @@ StringRefNull bundled_assets_directory_path()
}
} // namespace blender::asset_system
+
+bool ED_asset_bundle_contains_path(const char *path)
+{
+ const blender::StringRefNull bundled_path =
+ blender::asset_system::bundled_assets_directory_path();
+ return BLI_str_startswith(path, bundled_path.c_str());
+}
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index e85a6cbc0d4..62779692fcf 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -55,6 +55,8 @@
#include "GPU_immediate_util.h"
#include "GPU_state.h"
+#include "AS_asset_bundled.h"
+
#include "filelist.h"
#include "file_intern.h" /* own include */
@@ -126,6 +128,16 @@ static void draw_tile_background(const rcti *draw_rect, int colorid, int shade)
UI_draw_roundbox_aa(&draw_rect_fl, true, 5.0f, color);
}
+static eFileAssetImportType get_asset_import_type(const SpaceFile *sfile, const char *blend_path)
+{
+ if (ED_asset_bundle_contains_path(blend_path)) {
+ return FILE_ASSET_IMPORT_APPEND_REUSE;
+ }
+ const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
+ BLI_assert(asset_params != NULL);
+ return asset_params->import_type;
+}
+
static void file_draw_icon(const SpaceFile *sfile,
uiBlock *block,
const FileDirEntry *file,
@@ -165,13 +177,10 @@ static void file_draw_icon(const SpaceFile *sfile,
ImBuf *preview_image = filelist_file_getimage(file);
char blend_path[FILE_MAX_LIBEXTRA];
if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
- const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
- BLI_assert(asset_params != NULL);
-
UI_but_drag_set_asset(but,
&(AssetHandle){.file_data = file},
BLI_strdup(blend_path),
- asset_params->import_type,
+ get_asset_import_type(sfile, blend_path),
icon,
preview_image,
UI_DPI_FAC);
@@ -558,13 +567,10 @@ static void file_draw_preview(const SpaceFile *sfile,
char blend_path[FILE_MAX_LIBEXTRA];
if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
- const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
- BLI_assert(asset_params != NULL);
-
UI_but_drag_set_asset(but,
&(AssetHandle){.file_data = file},
BLI_strdup(blend_path),
- asset_params->import_type,
+ get_asset_import_type(sfile, blend_path),
icon,
imb,
scale);
More information about the Bf-blender-cvs
mailing list