Cleanup: Store asset-handle in drag data
Would previously pass a few properties that are available via the asset-handle now. This asset-handle is also required for some of the asset API, e.g. the temporary ID loading. This will probably be needed before too long.
This commit is contained in:
@@ -35,9 +35,11 @@ extern "C" {
|
|||||||
/* Struct Declarations */
|
/* Struct Declarations */
|
||||||
|
|
||||||
struct ARegion;
|
struct ARegion;
|
||||||
|
struct AssetHandle;
|
||||||
struct AssetFilterSettings;
|
struct AssetFilterSettings;
|
||||||
struct AutoComplete;
|
struct AutoComplete;
|
||||||
struct EnumPropertyItem;
|
struct EnumPropertyItem;
|
||||||
|
struct FileDirEntry;
|
||||||
struct FileSelectParams;
|
struct FileSelectParams;
|
||||||
struct ID;
|
struct ID;
|
||||||
struct IDProperty;
|
struct IDProperty;
|
||||||
@@ -769,9 +771,8 @@ int UI_but_return_value_get(uiBut *but);
|
|||||||
|
|
||||||
void UI_but_drag_set_id(uiBut *but, struct ID *id);
|
void UI_but_drag_set_id(uiBut *but, struct ID *id);
|
||||||
void UI_but_drag_set_asset(uiBut *but,
|
void UI_but_drag_set_asset(uiBut *but,
|
||||||
const char *name,
|
const struct AssetHandle *asset,
|
||||||
const char *path,
|
const char *path,
|
||||||
int id_type,
|
|
||||||
int import_type, /* eFileAssetImportType */
|
int import_type, /* eFileAssetImportType */
|
||||||
int icon,
|
int icon,
|
||||||
struct ImBuf *imb,
|
struct ImBuf *imb,
|
||||||
|
|||||||
@@ -6176,10 +6176,12 @@ void UI_but_drag_set_id(uiBut *but, ID *id)
|
|||||||
but->dragpoin = (void *)id;
|
but->dragpoin = (void *)id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \param asset: May be passed from a temporary variable, drag data only stores a copy of this.
|
||||||
|
*/
|
||||||
void UI_but_drag_set_asset(uiBut *but,
|
void UI_but_drag_set_asset(uiBut *but,
|
||||||
const char *name,
|
const AssetHandle *asset,
|
||||||
const char *path,
|
const char *path,
|
||||||
int id_type,
|
|
||||||
int import_type,
|
int import_type,
|
||||||
int icon,
|
int icon,
|
||||||
struct ImBuf *imb,
|
struct ImBuf *imb,
|
||||||
@@ -6187,9 +6189,10 @@ void UI_but_drag_set_asset(uiBut *but,
|
|||||||
{
|
{
|
||||||
wmDragAsset *asset_drag = MEM_mallocN(sizeof(*asset_drag), "wmDragAsset");
|
wmDragAsset *asset_drag = MEM_mallocN(sizeof(*asset_drag), "wmDragAsset");
|
||||||
|
|
||||||
BLI_strncpy(asset_drag->name, name, sizeof(asset_drag->name));
|
asset_drag->asset_handle = MEM_mallocN(sizeof(asset_drag->asset_handle),
|
||||||
|
"wmDragAsset asset handle");
|
||||||
|
*asset_drag->asset_handle = *asset;
|
||||||
asset_drag->path = path;
|
asset_drag->path = path;
|
||||||
asset_drag->id_type = id_type;
|
|
||||||
asset_drag->import_type = import_type;
|
asset_drag->import_type = import_type;
|
||||||
|
|
||||||
but->dragtype = WM_DRAG_ASSET;
|
but->dragtype = WM_DRAG_ASSET;
|
||||||
|
|||||||
@@ -59,14 +59,15 @@ static void asset_view_item_but_drag_set(uiBut *but,
|
|||||||
}
|
}
|
||||||
|
|
||||||
char blend_path[FILE_MAX_LIBEXTRA];
|
char blend_path[FILE_MAX_LIBEXTRA];
|
||||||
|
/* Context can be NULL here, it's only needed for a File Browser specific hack that should go
|
||||||
|
* away before too long. */
|
||||||
ED_asset_handle_get_full_library_path(NULL, &list_data->asset_library, asset_handle, blend_path);
|
ED_asset_handle_get_full_library_path(NULL, &list_data->asset_library, asset_handle, blend_path);
|
||||||
|
|
||||||
if (blend_path[0]) {
|
if (blend_path[0]) {
|
||||||
ImBuf *imbuf = ED_assetlist_asset_image_get(asset_handle);
|
ImBuf *imbuf = ED_assetlist_asset_image_get(asset_handle);
|
||||||
UI_but_drag_set_asset(but,
|
UI_but_drag_set_asset(but,
|
||||||
asset_handle->file_data->name,
|
asset_handle,
|
||||||
BLI_strdup(blend_path),
|
BLI_strdup(blend_path),
|
||||||
asset_handle->file_data->blentype,
|
|
||||||
FILE_ASSET_IMPORT_APPEND,
|
FILE_ASSET_IMPORT_APPEND,
|
||||||
ED_asset_handle_get_preview_icon_id(asset_handle),
|
ED_asset_handle_get_preview_icon_id(asset_handle),
|
||||||
imbuf,
|
imbuf,
|
||||||
|
|||||||
@@ -185,9 +185,8 @@ static void file_draw_icon(const SpaceFile *sfile,
|
|||||||
BLI_assert(asset_params != NULL);
|
BLI_assert(asset_params != NULL);
|
||||||
|
|
||||||
UI_but_drag_set_asset(but,
|
UI_but_drag_set_asset(but,
|
||||||
file->name,
|
&(AssetHandle){.file_data = file},
|
||||||
BLI_strdup(blend_path),
|
BLI_strdup(blend_path),
|
||||||
file->blentype,
|
|
||||||
asset_params->import_type,
|
asset_params->import_type,
|
||||||
icon,
|
icon,
|
||||||
preview_image,
|
preview_image,
|
||||||
@@ -500,9 +499,8 @@ static void file_draw_preview(const SpaceFile *sfile,
|
|||||||
BLI_assert(asset_params != NULL);
|
BLI_assert(asset_params != NULL);
|
||||||
|
|
||||||
UI_but_drag_set_asset(but,
|
UI_but_drag_set_asset(but,
|
||||||
file->name,
|
&(AssetHandle){.file_data = file},
|
||||||
BLI_strdup(blend_path),
|
BLI_strdup(blend_path),
|
||||||
file->blentype,
|
|
||||||
asset_params->import_type,
|
asset_params->import_type,
|
||||||
icon,
|
icon,
|
||||||
imb,
|
imb,
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
#include "BKE_screen.h"
|
#include "BKE_screen.h"
|
||||||
#include "BKE_workspace.h"
|
#include "BKE_workspace.h"
|
||||||
|
|
||||||
|
#include "ED_asset.h"
|
||||||
#include "ED_render.h"
|
#include "ED_render.h"
|
||||||
#include "ED_screen.h"
|
#include "ED_screen.h"
|
||||||
#include "ED_space_api.h"
|
#include "ED_space_api.h"
|
||||||
@@ -495,7 +496,7 @@ static ID_Type view3d_drop_id_in_main_region_poll_get_id_type(bContext *C,
|
|||||||
|
|
||||||
wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
|
wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
|
||||||
if (asset_drag) {
|
if (asset_drag) {
|
||||||
return asset_drag->id_type;
|
return ED_asset_handle_get_id_type(asset_drag->asset_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -924,10 +924,10 @@ typedef struct wmDragID {
|
|||||||
} wmDragID;
|
} wmDragID;
|
||||||
|
|
||||||
typedef struct wmDragAsset {
|
typedef struct wmDragAsset {
|
||||||
char name[64]; /* MAX_NAME */
|
/* Owning pointer. Contains the file with all the asset data (name, local ID, etc.) */
|
||||||
|
struct AssetHandle *asset_handle;
|
||||||
/* Always freed. */
|
/* Always freed. */
|
||||||
const char *path;
|
const char *path;
|
||||||
int id_type;
|
|
||||||
int import_type; /* eFileAssetImportType */
|
int import_type; /* eFileAssetImportType */
|
||||||
} wmDragAsset;
|
} wmDragAsset;
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,8 @@
|
|||||||
#include "BKE_idtype.h"
|
#include "BKE_idtype.h"
|
||||||
#include "BKE_lib_id.h"
|
#include "BKE_lib_id.h"
|
||||||
|
|
||||||
|
#include "ED_asset.h"
|
||||||
|
|
||||||
#include "GPU_shader.h"
|
#include "GPU_shader.h"
|
||||||
#include "GPU_state.h"
|
#include "GPU_state.h"
|
||||||
#include "GPU_viewport.h"
|
#include "GPU_viewport.h"
|
||||||
@@ -196,6 +198,7 @@ void WM_drag_data_free(int dragtype, void *poin)
|
|||||||
/* Not too nice, could become a callback. */
|
/* Not too nice, could become a callback. */
|
||||||
if (dragtype == WM_DRAG_ASSET) {
|
if (dragtype == WM_DRAG_ASSET) {
|
||||||
wmDragAsset *asset_drag = poin;
|
wmDragAsset *asset_drag = poin;
|
||||||
|
MEM_SAFE_FREE(asset_drag->asset_handle);
|
||||||
MEM_freeN((void *)asset_drag->path);
|
MEM_freeN((void *)asset_drag->path);
|
||||||
}
|
}
|
||||||
MEM_freeN(poin);
|
MEM_freeN(poin);
|
||||||
@@ -373,18 +376,20 @@ wmDragAsset *WM_drag_get_asset_data(const wmDrag *drag, int idcode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
wmDragAsset *asset_drag = drag->poin;
|
wmDragAsset *asset_drag = drag->poin;
|
||||||
return (ELEM(idcode, 0, asset_drag->id_type)) ? asset_drag : NULL;
|
ID_Type idtype = ED_asset_handle_get_id_type(asset_drag->asset_handle);
|
||||||
|
return (ELEM(idcode, 0, (int)idtype)) ? asset_drag : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag)
|
static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag)
|
||||||
{
|
{
|
||||||
|
const char *name = ED_asset_handle_get_name(asset_drag->asset_handle);
|
||||||
|
ID_Type idtype = ED_asset_handle_get_id_type(asset_drag->asset_handle);
|
||||||
|
|
||||||
switch ((eFileAssetImportType)asset_drag->import_type) {
|
switch ((eFileAssetImportType)asset_drag->import_type) {
|
||||||
case FILE_ASSET_IMPORT_LINK:
|
case FILE_ASSET_IMPORT_LINK:
|
||||||
return WM_file_link_datablock(
|
return WM_file_link_datablock(G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name);
|
||||||
G_MAIN, NULL, NULL, NULL, asset_drag->path, asset_drag->id_type, asset_drag->name);
|
|
||||||
case FILE_ASSET_IMPORT_APPEND:
|
case FILE_ASSET_IMPORT_APPEND:
|
||||||
return WM_file_append_datablock(
|
return WM_file_append_datablock(G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name);
|
||||||
G_MAIN, NULL, NULL, NULL, asset_drag->path, asset_drag->id_type, asset_drag->name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BLI_assert_unreachable();
|
BLI_assert_unreachable();
|
||||||
@@ -444,7 +449,8 @@ void WM_drag_free_imported_drag_ID(struct Main *bmain, wmDrag *drag, wmDropBox *
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ID *id = BKE_libblock_find_name(bmain, asset_drag->id_type, name);
|
ID_Type idtype = ED_asset_handle_get_id_type(asset_drag->asset_handle);
|
||||||
|
ID *id = BKE_libblock_find_name(bmain, idtype, name);
|
||||||
if (id) {
|
if (id) {
|
||||||
BKE_id_delete(bmain, id);
|
BKE_id_delete(bmain, id);
|
||||||
}
|
}
|
||||||
@@ -478,7 +484,7 @@ static const char *wm_drag_name(wmDrag *drag)
|
|||||||
}
|
}
|
||||||
case WM_DRAG_ASSET: {
|
case WM_DRAG_ASSET: {
|
||||||
const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
|
const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
|
||||||
return asset_drag->name;
|
return ED_asset_handle_get_name(asset_drag->asset_handle);
|
||||||
}
|
}
|
||||||
case WM_DRAG_PATH:
|
case WM_DRAG_PATH:
|
||||||
case WM_DRAG_NAME:
|
case WM_DRAG_NAME:
|
||||||
|
|||||||
Reference in New Issue
Block a user