LibLink: Modify WM API to link/append one ID to take flag parameter.
There is no reason to lock behavior into a specific configuration in those calls, make them properly configurable like the rest of the link/append code. This also enable users of those functions to activate 'ID reuse' behavior.
This commit is contained in:
parent
aadb7ef071
commit
4d2ca33a8a
|
@ -310,7 +310,14 @@ static int workspace_append_activate_exec(bContext *C, wmOperator *op)
|
|||
RNA_string_get(op->ptr, "filepath", filepath);
|
||||
|
||||
WorkSpace *appended_workspace = (WorkSpace *)WM_file_append_datablock(
|
||||
bmain, CTX_data_scene(C), CTX_data_view_layer(C), CTX_wm_view3d(C), filepath, ID_WS, idname);
|
||||
bmain,
|
||||
CTX_data_scene(C),
|
||||
CTX_data_view_layer(C),
|
||||
CTX_wm_view3d(C),
|
||||
filepath,
|
||||
ID_WS,
|
||||
idname,
|
||||
BLO_LIBLINK_APPEND_RECURSIVE);
|
||||
|
||||
if (appended_workspace) {
|
||||
/* Set defaults. */
|
||||
|
|
|
@ -212,14 +212,16 @@ struct ID *WM_file_link_datablock(struct Main *bmain,
|
|||
struct View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name);
|
||||
const char *id_name,
|
||||
int flag);
|
||||
struct ID *WM_file_append_datablock(struct Main *bmain,
|
||||
struct Scene *scene,
|
||||
struct ViewLayer *view_layer,
|
||||
struct View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name);
|
||||
const char *id_name,
|
||||
int flag);
|
||||
void WM_lib_reload(struct Library *lib, struct bContext *C, struct ReportList *reports);
|
||||
|
||||
/* mouse cursors */
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#include "BKE_idtype.h"
|
||||
#include "BKE_lib_id.h"
|
||||
|
||||
#include "BLO_readfile.h"
|
||||
|
||||
#include "GPU_shader.h"
|
||||
#include "GPU_state.h"
|
||||
#include "GPU_viewport.h"
|
||||
|
@ -392,9 +394,10 @@ static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag)
|
|||
|
||||
switch ((eFileAssetImportType)asset_drag->import_type) {
|
||||
case FILE_ASSET_IMPORT_LINK:
|
||||
return WM_file_link_datablock(G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name);
|
||||
return WM_file_link_datablock(G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name, 0);
|
||||
case FILE_ASSET_IMPORT_APPEND:
|
||||
return WM_file_append_datablock(G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name);
|
||||
return WM_file_append_datablock(
|
||||
G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name, BLO_LIBLINK_APPEND_RECURSIVE);
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
|
|
|
@ -1331,14 +1331,14 @@ static ID *wm_file_link_append_datablock_ex(Main *bmain,
|
|||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name,
|
||||
const bool do_append)
|
||||
const int flag)
|
||||
{
|
||||
const bool do_append = (flag & FILE_LINK) == 0;
|
||||
/* Tag everything so we can make local only the new datablock. */
|
||||
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
||||
|
||||
/* Define working data, with just the one item we want to link. */
|
||||
WMLinkAppendData *lapp_data = wm_link_append_data_new(do_append ? BLO_LIBLINK_APPEND_RECURSIVE :
|
||||
0);
|
||||
WMLinkAppendData *lapp_data = wm_link_append_data_new(flag);
|
||||
|
||||
wm_link_append_data_library_add(lapp_data, filepath);
|
||||
WMLinkAppendDataItem *item = wm_link_append_data_item_add(lapp_data, id_name, id_code, NULL);
|
||||
|
@ -1371,10 +1371,12 @@ ID *WM_file_link_datablock(Main *bmain,
|
|||
View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name)
|
||||
const char *id_name,
|
||||
int flag)
|
||||
{
|
||||
flag |= FILE_LINK;
|
||||
return wm_file_link_append_datablock_ex(
|
||||
bmain, scene, view_layer, v3d, filepath, id_code, id_name, false);
|
||||
bmain, scene, view_layer, v3d, filepath, id_code, id_name, flag);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1387,10 +1389,12 @@ ID *WM_file_append_datablock(Main *bmain,
|
|||
View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name)
|
||||
const char *id_name,
|
||||
int flag)
|
||||
{
|
||||
BLI_assert((flag & FILE_LINK) == 0);
|
||||
ID *id = wm_file_link_append_datablock_ex(
|
||||
bmain, scene, view_layer, v3d, filepath, id_code, id_name, true);
|
||||
bmain, scene, view_layer, v3d, filepath, id_code, id_name, flag);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue