diff --git a/source/blender/editors/include/UI_interface_layout.hh b/source/blender/editors/include/UI_interface_layout.hh index 94481d58ac2..7d4da93367c 100644 --- a/source/blender/editors/include/UI_interface_layout.hh +++ b/source/blender/editors/include/UI_interface_layout.hh @@ -279,16 +279,13 @@ struct uiLayout : uiItem { * \param ot: Operator to add. * \param name: Text to show in the layout. * \param context: Operator call context for #WM_operator_name_call. - * \param properties: Operator properties to set as button operator data, pointer ownership is - * transferred to the button. * \returns Operator pointer to write properties. */ PointerRNA op(wmOperatorType *ot, std::optional name, int icon, wmOperatorCallContext context, - eUI_Item_Flag flag, - IDProperty *properties = nullptr); + eUI_Item_Flag flag); /** * Adds a operator item, places a button in the layout to call the operator. * \param opname: Operator id name. diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index e31f2ab5adb..74de0af2537 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -1360,11 +1360,10 @@ PointerRNA uiLayout::op(wmOperatorType *ot, std::optional name, const int icon, const wmOperatorCallContext context, - const eUI_Item_Flag flag, - IDProperty *properties) + const eUI_Item_Flag flag) { PointerRNA ptr; - uiItemFullO_ptr_ex(this, ot, name, icon, properties, context, flag, &ptr); + uiItemFullO_ptr_ex(this, ot, name, icon, nullptr, context, flag, &ptr); return ptr; } @@ -1434,13 +1433,10 @@ void uiItemEnumO_ptr(uiLayout *layout, RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname.c_str()); return; } - - RNA_property_enum_set(&ptr, prop, value); - name = name.value_or(ui_menu_enumpropname(layout, &ptr, prop, value)); - layout->op( - ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE, static_cast(ptr.data)); + ptr = layout->op(ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE); + RNA_property_enum_set(&ptr, prop, value); } void uiItemEnumO(uiLayout *layout, const StringRefNull opname, @@ -1543,23 +1539,13 @@ void uiItemsFullEnumO_items(uiLayout *layout, } if (item->identifier[0]) { - PointerRNA tptr; - WM_operator_properties_create_ptr(&tptr, ot); + PointerRNA tptr = target->op( + ot, (flag & UI_ITEM_R_ICON_ONLY) ? nullptr : item->name, item->icon, context, flag); if (properties) { - if (tptr.data) { - IDP_FreeProperty(static_cast(tptr.data)); - } - tptr.data = IDP_CopyProperty(properties); + IDP_CopyPropertyContent(tptr.data_as(), properties); } RNA_property_enum_set(&tptr, prop, item->value); - target->op(ot, - (flag & UI_ITEM_R_ICON_ONLY) ? nullptr : item->name, - item->icon, - context, - flag, - static_cast(tptr.data)); - uiBut *but = block->buttons.last().get(); if (active == (i - 1)) { @@ -1709,11 +1695,8 @@ void uiItemEnumO_value(uiLayout *layout, RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname.c_str()); return; } - + ptr = layout->op(ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE); RNA_property_enum_set(&ptr, prop, value); - - layout->op( - ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE, static_cast(ptr.data)); } void uiItemEnumO_string(uiLayout *layout, @@ -1755,11 +1738,8 @@ void uiItemEnumO_string(uiLayout *layout, if (free) { MEM_freeN(item); } - + ptr = layout->op(ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE); RNA_property_enum_set(&ptr, prop, value); - - layout->op( - ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE, static_cast(ptr.data)); } void uiItemBooleanO(uiLayout *layout, @@ -1769,15 +1749,11 @@ void uiItemBooleanO(uiLayout *layout, const StringRefNull propname, int value) { - wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false); /* print error next */ - UI_OPERATOR_ERROR_RET(ot, opname.c_str(), return); - - PointerRNA ptr; - WM_operator_properties_create_ptr(&ptr, ot); + PointerRNA ptr = layout->op(opname, name, icon, layout->root_->opcontext, UI_ITEM_NONE); + if (RNA_pointer_is_null(&ptr)) { + return; + } RNA_boolean_set(&ptr, propname.c_str(), value); - - layout->op( - ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE, static_cast(ptr.data)); } void uiItemIntO(uiLayout *layout, @@ -1787,15 +1763,11 @@ void uiItemIntO(uiLayout *layout, const StringRefNull propname, int value) { - wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false); /* print error next */ - UI_OPERATOR_ERROR_RET(ot, opname.c_str(), return); - - PointerRNA ptr; - WM_operator_properties_create_ptr(&ptr, ot); + PointerRNA ptr = layout->op(opname, name, icon, layout->root_->opcontext, UI_ITEM_NONE); + if (RNA_pointer_is_null(&ptr)) { + return; + } RNA_int_set(&ptr, propname.c_str(), value); - - layout->op( - ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE, static_cast(ptr.data)); } void uiItemFloatO(uiLayout *layout, @@ -1805,16 +1777,11 @@ void uiItemFloatO(uiLayout *layout, const StringRefNull propname, float value) { - wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false); /* print error next */ - - UI_OPERATOR_ERROR_RET(ot, opname.c_str(), return); - - PointerRNA ptr; - WM_operator_properties_create_ptr(&ptr, ot); + PointerRNA ptr = layout->op(opname, name, icon, layout->root_->opcontext, UI_ITEM_NONE); + if (RNA_pointer_is_null(&ptr)) { + return; + } RNA_float_set(&ptr, propname.c_str(), value); - - layout->op( - ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE, static_cast(ptr.data)); } void uiItemStringO(uiLayout *layout, @@ -1824,16 +1791,11 @@ void uiItemStringO(uiLayout *layout, const StringRefNull propname, const char *value) { - wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false); /* print error next */ - - UI_OPERATOR_ERROR_RET(ot, opname.c_str(), return); - - PointerRNA ptr; - WM_operator_properties_create_ptr(&ptr, ot); + PointerRNA ptr = layout->op(opname, name, icon, layout->root_->opcontext, UI_ITEM_NONE); + if (RNA_pointer_is_null(&ptr)) { + return; + } RNA_string_set(&ptr, propname.c_str(), value); - - layout->op( - ot, name, icon, layout->root_->opcontext, UI_ITEM_NONE, static_cast(ptr.data)); } void uiLayout::op(const StringRefNull opname, const std::optional name, int icon) diff --git a/source/blender/editors/io/io_drop_import_file.cc b/source/blender/editors/io/io_drop_import_file.cc index b5250af3ffd..e2fe270d21d 100644 --- a/source/blender/editors/io/io_drop_import_file.cc +++ b/source/blender/editors/io/io_drop_import_file.cc @@ -43,16 +43,13 @@ static blender::Vector drop_import_file_poll_fi } /** - * Creates a RNA pointer for the `FileHandlerType.import_operator` and sets on it all supported - * file paths from `paths`. + * Sets in the RNA pointer all file paths supported by the file handler. */ -static PointerRNA file_handler_import_operator_create_ptr( - const blender::bke::FileHandlerType *file_handler, const blender::Span paths) +static void file_handler_import_operator_write_ptr( + const blender::bke::FileHandlerType *file_handler, + PointerRNA &props, + const blender::Span paths) { - wmOperatorType *ot = WM_operatortype_find(file_handler->import_operator, false); - BLI_assert(ot != nullptr); - PointerRNA props; - WM_operator_properties_create_ptr(&props, ot); const auto supported_paths = file_handler->filter_supported_paths(paths); @@ -94,7 +91,6 @@ static PointerRNA file_handler_import_operator_create_ptr( "FileHandler documentation for details."; CLOG_WARN(&LOG, "%s", message); } - return props; } static wmOperatorStatus wm_drop_import_file_exec(bContext *C, wmOperator *op) @@ -110,7 +106,9 @@ static wmOperatorStatus wm_drop_import_file_exec(bContext *C, wmOperator *op) } wmOperatorType *ot = WM_operatortype_find(file_handlers[0]->import_operator, false); - PointerRNA file_props = file_handler_import_operator_create_ptr(file_handlers[0], paths); + PointerRNA file_props; + WM_operator_properties_create_ptr(&file_props, ot); + file_handler_import_operator_write_ptr(file_handlers[0], file_props, paths); WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &file_props, nullptr); WM_operator_properties_free(&file_props); @@ -140,14 +138,13 @@ static wmOperatorStatus wm_drop_import_file_invoke(bContext *C, uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); for (auto *file_handler : file_handlers) { - const PointerRNA file_props = file_handler_import_operator_create_ptr(file_handler, paths); wmOperatorType *ot = WM_operatortype_find(file_handler->import_operator, false); - layout->op(ot, - CTX_TIP_(ot->translation_context, ot->name), - ICON_NONE, - WM_OP_INVOKE_DEFAULT, - UI_ITEM_NONE, - static_cast(file_props.data)); + PointerRNA file_props = layout->op(ot, + CTX_TIP_(ot->translation_context, ot->name), + ICON_NONE, + WM_OP_INVOKE_DEFAULT, + UI_ITEM_NONE); + file_handler_import_operator_write_ptr(file_handler, file_props, paths); } UI_popup_menu_end(C, pup); diff --git a/source/blender/editors/object/object_edit.cc b/source/blender/editors/object/object_edit.cc index 582da0bb4ab..a057c9d215b 100644 --- a/source/blender/editors/object/object_edit.cc +++ b/source/blender/editors/object/object_edit.cc @@ -2334,17 +2334,14 @@ static void move_to_collection_menu_create(bContext *C, uiLayout *layout, void * MoveToCollectionData *menu = static_cast(menu_v); const char *name = BKE_collection_ui_name_get(menu->collection); - WM_operator_properties_create_ptr(&menu->ptr, menu->ot); + menu->ptr = layout->op(menu->ot, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "New Collection"), + ICON_ADD, + WM_OP_INVOKE_DEFAULT, + UI_ITEM_NONE); RNA_int_set(&menu->ptr, "collection_index", menu->index); RNA_boolean_set(&menu->ptr, "is_new", true); - layout->op(menu->ot, - CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "New Collection"), - ICON_ADD, - WM_OP_INVOKE_DEFAULT, - UI_ITEM_NONE, - static_cast(menu->ptr.data)); - layout->separator(); Scene *scene = CTX_data_scene(C); diff --git a/source/blender/editors/screen/screen_user_menu.cc b/source/blender/editors/screen/screen_user_menu.cc index 77232a168d9..348a306881c 100644 --- a/source/blender/editors/screen/screen_user_menu.cc +++ b/source/blender/editors/screen/screen_user_menu.cc @@ -226,13 +226,11 @@ static void screen_user_menu_draw(const bContext *C, Menu *menu) ui_name = CTX_IFACE_(ot->translation_context, ui_name->c_str()); } if (umi_op->op_prop_enum[0] == '\0') { - IDProperty *prop = umi_op->prop ? IDP_CopyProperty(umi_op->prop) : nullptr; - menu->layout->op(ot, - ui_name, - ICON_NONE, - wmOperatorCallContext(umi_op->opcontext), - UI_ITEM_NONE, - prop); + PointerRNA ptr = menu->layout->op( + ot, ui_name, ICON_NONE, wmOperatorCallContext(umi_op->opcontext), UI_ITEM_NONE); + if (umi_op->prop) { + IDP_CopyPropertyContent(ptr.data_as(), umi_op->prop); + } } else { /* umi_op->prop could be used to set other properties but it's currently unsupported.