Add option to link assets on drag & drop
Note: Linking in this case as in link vs. append. Easily confused with linking a data-block to multiple usages (e.g. single material used by multiple objects). Adds a drop-down to the Asset Browser header to choose between Link and Append. This is probably gonna be a temporary place, T54642 shows where this could be placed eventually. Linking support is crucial for usage of the asset browser in production environments. It just wasn't enabled yet because a) the asset project currently focuses on single user, not production assets, and b) because there were many unkowns still for the workflow that have big impact on production use as well. With the recently held asset workshop I'm more confident with enabling linking, as design ideas relevant to production use were confirmed. Differential Revision: https://developer.blender.org/D11536 Reviewed by: Bastien Montagne
This commit is contained in:
@@ -205,6 +205,13 @@ void WM_autosave_init(struct wmWindowManager *wm);
|
||||
bool WM_recover_last_session(struct bContext *C, struct ReportList *reports);
|
||||
void WM_file_tag_modified(void);
|
||||
|
||||
struct ID *WM_file_link_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);
|
||||
struct ID *WM_file_append_datablock(struct Main *bmain,
|
||||
struct Scene *scene,
|
||||
struct ViewLayer *view_layer,
|
||||
|
||||
@@ -920,6 +920,7 @@ typedef struct wmDragAsset {
|
||||
/* Always freed. */
|
||||
const char *path;
|
||||
int id_type;
|
||||
int import_type; /* eFileAssetImportType */
|
||||
} wmDragAsset;
|
||||
|
||||
typedef struct wmDrag {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_windowmanager_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
@@ -377,9 +378,17 @@ wmDragAsset *WM_drag_get_asset_data(const wmDrag *drag, int idcode)
|
||||
|
||||
static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag)
|
||||
{
|
||||
/* Append only for now, wmDragAsset could have a `link` bool. */
|
||||
return WM_file_append_datablock(
|
||||
G_MAIN, NULL, NULL, NULL, asset_drag->path, asset_drag->id_type, asset_drag->name);
|
||||
switch ((eFileAssetImportType)asset_drag->import_type) {
|
||||
case FILE_ASSET_IMPORT_LINK:
|
||||
return WM_file_link_datablock(
|
||||
G_MAIN, NULL, NULL, NULL, asset_drag->path, asset_drag->id_type, asset_drag->name);
|
||||
case FILE_ASSET_IMPORT_APPEND:
|
||||
return WM_file_append_datablock(
|
||||
G_MAIN, NULL, NULL, NULL, asset_drag->path, asset_drag->id_type, asset_drag->name);
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -642,23 +642,23 @@ void WM_OT_append(wmOperatorType *ot)
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Append Single Data-Block & Return it
|
||||
/** \name Link/Append Single Data-Block & Return it
|
||||
*
|
||||
* Used for appending workspace from startup files.
|
||||
* \{ */
|
||||
|
||||
ID *WM_file_append_datablock(Main *bmain,
|
||||
Scene *scene,
|
||||
ViewLayer *view_layer,
|
||||
View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name)
|
||||
static ID *wm_file_link_datablock_ex(Main *bmain,
|
||||
Scene *scene,
|
||||
ViewLayer *view_layer,
|
||||
View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name,
|
||||
bool clear_pre_existing_flag)
|
||||
{
|
||||
/* 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 append. */
|
||||
/* Define working data, with just the one item we want to link. */
|
||||
WMLinkAppendData *lapp_data = wm_link_append_data_new(0);
|
||||
|
||||
wm_link_append_data_library_add(lapp_data, filepath);
|
||||
@@ -672,6 +672,36 @@ ID *WM_file_append_datablock(Main *bmain,
|
||||
ID *id = item->new_id;
|
||||
wm_link_append_data_free(lapp_data);
|
||||
|
||||
if (clear_pre_existing_flag) {
|
||||
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
ID *WM_file_link_datablock(Main *bmain,
|
||||
Scene *scene,
|
||||
ViewLayer *view_layer,
|
||||
View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name)
|
||||
{
|
||||
return wm_file_link_datablock_ex(
|
||||
bmain, scene, view_layer, v3d, filepath, id_code, id_name, true);
|
||||
}
|
||||
|
||||
ID *WM_file_append_datablock(Main *bmain,
|
||||
Scene *scene,
|
||||
ViewLayer *view_layer,
|
||||
View3D *v3d,
|
||||
const char *filepath,
|
||||
const short id_code,
|
||||
const char *id_name)
|
||||
{
|
||||
ID *id = wm_file_link_datablock_ex(
|
||||
bmain, scene, view_layer, v3d, filepath, id_code, id_name, false);
|
||||
|
||||
/* Make datablock local. */
|
||||
BKE_library_make_local(bmain, NULL, NULL, true, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user