From 0d6dda4555bcae82cf581bdb23d639e9733057b5 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 23 May 2022 20:32:36 +0200 Subject: Cleanup: Move new utilities for ID lookup operator properties Move them to a more accessible place, so that other operators in different files can use them. The following commit needs this. --- .../windowmanager/intern/wm_operator_props.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'source/blender/windowmanager/intern') diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c index 6e44246f3ef..b58121794b3 100644 --- a/source/blender/windowmanager/intern/wm_operator_props.c +++ b/source/blender/windowmanager/intern/wm_operator_props.c @@ -8,8 +8,12 @@ * (`WM_operator_properties_*` functions). */ +#include "DNA_ID_enums.h" #include "DNA_space_types.h" +#include "BKE_lib_id.h" +#include "BKE_main.h" + #include "BLI_math_base.h" #include "BLI_rect.h" @@ -222,6 +226,53 @@ void WM_operator_properties_filesel(wmOperatorType *ot, RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } +ID *WM_operator_properties_id_lookup_from_name_or_session_uuid(Main *bmain, + const wmOperator *op, + const ID_Type type) +{ + PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name"); + PropertyRNA *prop_session_uuid = RNA_struct_find_property(op->ptr, "session_uuid"); + + if (prop_name && RNA_property_is_set(op->ptr, prop_name)) { + char name[MAX_ID_NAME - 2]; + RNA_property_string_get(op->ptr, prop_name, name); + return BKE_libblock_find_name(bmain, type, name); + } + + if (prop_session_uuid && RNA_property_is_set(op->ptr, prop_session_uuid)) { + const uint32_t session_uuid = (uint32_t)RNA_property_int_get(op->ptr, prop_session_uuid); + return BKE_libblock_find_session_uuid(bmain, type, session_uuid); + } + + return NULL; +} + +void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop) +{ + PropertyRNA *prop; + + if (add_name_prop) { + prop = RNA_def_string(ot->srna, + "name", + NULL, + MAX_ID_NAME - 2, + "Name", + "Name of the data-block to use by the operator"); + RNA_def_property_flag(prop, (PropertyFlag)(PROP_SKIP_SAVE | PROP_HIDDEN)); + } + + prop = RNA_def_int(ot->srna, + "session_uuid", + 0, + INT32_MIN, + INT32_MAX, + "Session UUID", + "Session UUID of the data-block to use by the operator", + INT32_MIN, + INT32_MAX); + RNA_def_property_flag(prop, (PropertyFlag)(PROP_SKIP_SAVE | PROP_HIDDEN)); +} + static void wm_operator_properties_select_action_ex(wmOperatorType *ot, int default_action, const EnumPropertyItem *select_actions, -- cgit v1.2.3 From 8f79fa9c6780dd5526dccce039c49bc7f69f47df Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 23 May 2022 20:54:15 +0200 Subject: 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. --- source/blender/windowmanager/intern/wm_operator_props.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source/blender/windowmanager/intern') 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) -- cgit v1.2.3