Refactor: UI: Remove uiLayout::op id properties parameter

This was an alternative way to write properties for layout operator buttons,
for the most cases are more than enough to use the returned pointer.

There were just 2 cases where this was useful, the quick access menu
that reuses operator property values, this now overrides the id property group
data pointer generated for the operator, also for `uiItemsFullEnumO_items`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139242
This commit is contained in:
Guillermo Venegas
2025-05-22 20:19:18 +02:00
committed by Hans Goudey
parent 85dcfe70bc
commit b3eb84f624
5 changed files with 50 additions and 99 deletions

View File

@@ -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<blender::StringRef> 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.

View File

@@ -1360,11 +1360,10 @@ PointerRNA uiLayout::op(wmOperatorType *ot,
std::optional<StringRef> 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<IDProperty *>(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<IDProperty *>(tptr.data));
}
tptr.data = IDP_CopyProperty(properties);
IDP_CopyPropertyContent(tptr.data_as<IDProperty>(), 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<IDProperty *>(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<IDProperty *>(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<IDProperty *>(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<IDProperty *>(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<IDProperty *>(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<IDProperty *>(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<IDProperty *>(ptr.data));
}
void uiLayout::op(const StringRefNull opname, const std::optional<StringRef> name, int icon)

View File

@@ -43,16 +43,13 @@ static blender::Vector<blender::bke::FileHandlerType *> 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<std::string> paths)
static void file_handler_import_operator_write_ptr(
const blender::bke::FileHandlerType *file_handler,
PointerRNA &props,
const blender::Span<std::string> 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<IDProperty *>(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);

View File

@@ -2334,17 +2334,14 @@ static void move_to_collection_menu_create(bContext *C, uiLayout *layout, void *
MoveToCollectionData *menu = static_cast<MoveToCollectionData *>(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<IDProperty *>(menu->ptr.data));
layout->separator();
Scene *scene = CTX_data_scene(C);

View File

@@ -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<IDProperty>(), umi_op->prop);
}
}
else {
/* umi_op->prop could be used to set other properties but it's currently unsupported.