[Bf-blender-cvs] [8f79fa9c678] blender-v3.2-release: Fix further issues when mixing link & append for asset drag & drop

Julian Eisel noreply at git.blender.org
Mon May 23 21:00:11 CEST 2022


Commit: 8f79fa9c6780dd5526dccce039c49bc7f69f47df
Author: Julian Eisel
Date:   Mon May 23 20:54:15 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB8f79fa9c6780dd5526dccce039c49bc7f69f47df

Fix further issues when mixing link & append for asset drag & drop

917c096be6b9 applied to objects only, this also applies the same fix for
the general 3D View drop operations, e.g. used for dragging materials,
images, worlds, etc.

This is needed to fix T95706, but apparently something else is still
going on. Needs further investigation.

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

M	source/blender/editors/object/object_relations.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_operator_props.c

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

diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 76dcfbd8d36..0a85a60eda8 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -2629,11 +2629,9 @@ static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent
   Object *ob = ED_view3d_give_material_slot_under_cursor(C, event->mval, &mat_slot);
   mat_slot = max_ii(mat_slot, 1);
 
-  Material *ma;
-  char name[MAX_ID_NAME - 2];
+  Material *ma = (Material *)WM_operator_properties_id_lookup_from_name_or_session_uuid(
+      bmain, op, ID_MA);
 
-  RNA_string_get(op->ptr, "name", name);
-  ma = (Material *)BKE_libblock_find_name(bmain, ID_MA, name);
   if (ob == NULL || ma == NULL) {
     return OPERATOR_CANCELLED;
   }
@@ -2663,7 +2661,7 @@ void OBJECT_OT_drop_named_material(wmOperatorType *ot)
   ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
 
   /* properties */
-  RNA_def_string(ot->srna, "name", "Material", MAX_ID_NAME - 2, "Name", "Material name to assign");
+  WM_operator_properties_id_lookup(ot, true);
 }
 
 /** \} */
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 5ddfc4fe3cc..e7732f07ed9 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -823,15 +823,15 @@ static void view3d_id_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *dr
 {
   ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
 
-  RNA_string_set(drop->ptr, "name", id->name + 2);
+  WM_operator_properties_id_lookup_set_from_id(drop->ptr, id);
 }
 
 static void view3d_id_drop_copy_with_type(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
 {
   ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
 
-  RNA_string_set(drop->ptr, "name", id->name + 2);
   RNA_enum_set(drop->ptr, "type", GS(id->name));
+  WM_operator_properties_id_lookup_set_from_id(drop->ptr, id);
 }
 
 static void view3d_id_path_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
@@ -839,7 +839,7 @@ static void view3d_id_path_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBo
   ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
 
   if (id) {
-    RNA_string_set(drop->ptr, "name", id->name + 2);
+    WM_operator_properties_id_lookup_set_from_id(drop->ptr, id);
     RNA_struct_property_unset(drop->ptr, "filepath");
   }
   else if (drag->path[0]) {
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 67dc8797607..48ade798364 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -771,6 +771,15 @@ void WM_operator_properties_filesel(struct wmOperatorType *ot,
                                     short display,
                                     short sort);
 
+/**
+ * Tries to pass \a id to an operator via either a "session_uuid" or a "name" property defined in
+ * the properties of \a ptr. The former is preferred, since it works properly with linking and
+ * library overrides (which may both result in multiple IDs with the same name and type).
+ *
+ * Also see #WM_operator_properties_id_lookup() and
+ * #WM_operator_properties_id_lookup_from_name_or_session_uuid()
+ */
+void WM_operator_properties_id_lookup_set_from_id(PointerRNA *ptr, const ID *id);
 /**
  * Tries to find an ID in \a bmain. There needs to be either a "name" string or "session_uuid" int
  * property defined and set. The former has priority. See #WM_operator_properties_id_lookup() for a
diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c
index b58121794b3..55544e9906d 100644
--- a/source/blender/windowmanager/intern/wm_operator_props.c
+++ b/source/blender/windowmanager/intern/wm_operator_props.c
@@ -226,6 +226,22 @@ void WM_operator_properties_filesel(wmOperatorType *ot,
   RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
 }
 
+void WM_operator_properties_id_lookup_set_from_id(PointerRNA *ptr, const ID *id)
+{
+  PropertyRNA *prop_session_uuid = RNA_struct_find_property(ptr, "session_uuid");
+  PropertyRNA *prop_name = RNA_struct_find_property(ptr, "name");
+
+  if (prop_session_uuid) {
+    RNA_int_set(ptr, "session_uuid", (int)id->session_uuid);
+  }
+  else if (prop_name) {
+    RNA_string_set(ptr, "name", id->name + 2);
+  }
+  else {
+    BLI_assert_unreachable();
+  }
+}
+
 ID *WM_operator_properties_id_lookup_from_name_or_session_uuid(Main *bmain,
                                                                const wmOperator *op,
                                                                const ID_Type type)



More information about the Bf-blender-cvs mailing list