[Bf-blender-cvs] [4d2ca33a8a7] master: LibLink: Modify WM API to link/append one ID to take flag parameter.

Bastien Montagne noreply at git.blender.org
Thu Sep 23 13:48:46 CEST 2021


Commit: 4d2ca33a8a7d08897a273031099da9b7bcaa11ff
Author: Bastien Montagne
Date:   Thu Sep 23 13:46:55 2021 +0200
Branches: master
https://developer.blender.org/rB4d2ca33a8a7d08897a273031099da9b7bcaa11ff

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.

===================================================================

M	source/blender/editors/screen/workspace_edit.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_dragdrop.c
M	source/blender/windowmanager/intern/wm_files_link.c

===================================================================

diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index b99cb831bee..4b81e713080 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -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. */
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 6794b1f4091..c5482a729c3 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -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 */
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 6585349c83c..f3a57b72095 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -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();
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index 2f34ee3db3c..92335f28d94 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -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;
 }



More information about the Bf-blender-cvs mailing list