Asset Browser: Add pre+post handlers to asset drag & drop #113658

Open
Greg Zaal wants to merge 2 commits from GregZaal/blender:asset-drop-handlers into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 24 additions and 15 deletions

View File

@ -85,6 +85,8 @@ enum eCbEvent {
BKE_CB_EVT_SAVE_PRE,
BKE_CB_EVT_SAVE_POST,
BKE_CB_EVT_SAVE_POST_FAIL,
BKE_CB_EVT_ASSET_DROP_PRE,
BKE_CB_EVT_ASSET_DROP_POST,
BKE_CB_EVT_UNDO_PRE,
BKE_CB_EVT_UNDO_POST,
BKE_CB_EVT_REDO_PRE,

View File

@ -68,6 +68,9 @@ static PyStructSequence_Field app_cb_info_fields[] = {
{"save_post", "on saving a blend file (after). " FILEPATH_SAVE_ARG},
{"save_post_fail", "on failure to save a blend file (after). " FILEPATH_SAVE_ARG},
{"asset_drop_pre", "on dropping an asset from the asset browser (before). " FILEPATH_LOAD_ARG},
{"asset_drop_post", "on dropping an asset from the asset browser (after). "},
{"undo_pre", "on loading an undo step (before)"},
{"undo_post", "on loading an undo step (after)"},
{"redo_pre", "on loading a redo step (before)"},

View File

@ -27,6 +27,7 @@
#include "BIF_glutil.hh"
#include "BKE_callbacks.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_idprop.hh"
@ -705,28 +706,31 @@ ID *WM_drag_asset_id_import(const bContext *C, wmDragAsset *asset_drag, const in
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *view3d = CTX_wm_view3d(C);
BKE_callback_exec_string(bmain, BKE_CB_EVT_ASSET_DROP_PRE, blend_path.c_str());
ID *id = nullptr;
switch (eAssetImportMethod(asset_drag->import_method)) {
case ASSET_IMPORT_LINK:
return WM_file_link_datablock(bmain,
id = WM_file_link_datablock(bmain,
scene,
view_layer,
view3d,
blend_path.c_str(),
idtype,
name,
flag | (use_relative_path ? FILE_RELPATH : 0));
case ASSET_IMPORT_APPEND:
id = WM_file_append_datablock(bmain,
scene,
view_layer,
view3d,
blend_path.c_str(),
idtype,
name,
flag | (use_relative_path ? FILE_RELPATH : 0));
case ASSET_IMPORT_APPEND:
return WM_file_append_datablock(bmain,
scene,
view_layer,
view3d,
blend_path.c_str(),
idtype,
name,
flag | BLO_LIBLINK_APPEND_RECURSIVE |
BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR);
flag | BLO_LIBLINK_APPEND_RECURSIVE |
BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR);
case ASSET_IMPORT_APPEND_REUSE:
return WM_file_append_datablock(
id = WM_file_append_datablock(
G_MAIN,
scene,
view_layer,
@ -738,8 +742,8 @@ ID *WM_drag_asset_id_import(const bContext *C, wmDragAsset *asset_drag, const in
BLO_LIBLINK_APPEND_LOCAL_ID_REUSE | (use_relative_path ? FILE_RELPATH : 0));
}
BLI_assert_unreachable();
return nullptr;
BKE_callback_exec_id(bmain, id, BKE_CB_EVT_ASSET_DROP_POST);
return id;
}
bool WM_drag_asset_will_import_linked(const wmDrag *drag)