Refactor: UI: Replace uiItemMenuEnumFullO* with class methods
This converts the public uiItemMenuEnumFullO* functions to an object-oriented API (as uiLayout::op_menu_enum overloads), matching recent changes in the API. Part of: #117604 Pull Request: https://projects.blender.org/blender/blender/pulls/141797
This commit is contained in:
committed by
Hans Goudey
parent
8f198a85b4
commit
c97195cd63
@@ -480,6 +480,26 @@ struct uiLayout : uiItem, blender::NonCopyable, blender::NonMovable {
|
||||
int totitem,
|
||||
int active = -1);
|
||||
|
||||
/**
|
||||
* Adds a #op_enum menu.
|
||||
* \returns Operator pointer to write extra properties to set when menu buttons are
|
||||
* displayed, might be #PointerRNA_NULL if operator does not exist.
|
||||
*/
|
||||
PointerRNA op_menu_enum(const bContext *C,
|
||||
wmOperatorType *ot,
|
||||
blender::StringRefNull propname,
|
||||
std::optional<blender::StringRefNull> name,
|
||||
int icon);
|
||||
/**
|
||||
* Adds a #op_enum menu.
|
||||
* \returns Operator pointer to write extra properties to set when menu buttons are
|
||||
* displayed, might be #PointerRNA_NULL if operator does not exist.
|
||||
*/
|
||||
PointerRNA op_menu_enum(const bContext *C,
|
||||
blender::StringRefNull opname,
|
||||
blender::StringRefNull propname,
|
||||
blender::StringRefNull name,
|
||||
int icon);
|
||||
/**
|
||||
* Adds a operator item, places a button in the layout to call the operator, if the button is
|
||||
* held down, a menu will be displayed instead.
|
||||
@@ -906,30 +926,6 @@ uiLayout *uiItemL_respect_property_split(uiLayout *layout, blender::StringRef te
|
||||
*/
|
||||
void uiItemLDrag(uiLayout *layout, PointerRNA *ptr, blender::StringRef name, int icon);
|
||||
|
||||
/**
|
||||
* Level items.
|
||||
*/
|
||||
void uiItemMenuEnumFullO_ptr(uiLayout *layout,
|
||||
const bContext *C,
|
||||
wmOperatorType *ot,
|
||||
blender::StringRefNull propname,
|
||||
std::optional<blender::StringRefNull> name,
|
||||
int icon,
|
||||
PointerRNA *r_opptr);
|
||||
void uiItemMenuEnumFullO(uiLayout *layout,
|
||||
const bContext *C,
|
||||
blender::StringRefNull opname,
|
||||
blender::StringRefNull propname,
|
||||
blender::StringRefNull name,
|
||||
int icon,
|
||||
PointerRNA *r_opptr);
|
||||
void uiItemMenuEnumO(uiLayout *layout,
|
||||
const bContext *C,
|
||||
blender::StringRefNull opname,
|
||||
blender::StringRefNull propname,
|
||||
blender::StringRefNull name,
|
||||
int icon);
|
||||
|
||||
/* Only for testing, inspecting layouts. */
|
||||
/**
|
||||
* Evaluate layout items as a Python dictionary.
|
||||
|
||||
@@ -62,11 +62,11 @@ using blender::StringRefNull;
|
||||
/** \name Structs and Defines
|
||||
* \{ */
|
||||
|
||||
#define UI_OPERATOR_ERROR_RET(_ot, _opname, return_statement) \
|
||||
#define UI_OPERATOR_ERROR_RET(_ot, _opname) \
|
||||
if (ot == nullptr) { \
|
||||
ui_item_disabled(layout, _opname); \
|
||||
ui_item_disabled(this, _opname); \
|
||||
RNA_warning("'%s' unknown operator", _opname); \
|
||||
return_statement; \
|
||||
return PointerRNA_NULL; \
|
||||
} \
|
||||
(void)0
|
||||
|
||||
@@ -1388,8 +1388,7 @@ PointerRNA uiLayout::op(const blender::StringRefNull opname,
|
||||
const eUI_Item_Flag flag)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false); /* print error next */
|
||||
uiLayout *layout = this;
|
||||
UI_OPERATOR_ERROR_RET(ot, opname.c_str(), { return PointerRNA_NULL; });
|
||||
UI_OPERATOR_ERROR_RET(ot, opname.c_str());
|
||||
return this->op(ot, name, icon, context, flag);
|
||||
}
|
||||
|
||||
@@ -3272,10 +3271,11 @@ static void menu_item_enum_opname_menu(bContext *C, uiLayout *layout, void *arg)
|
||||
uiBut *but = static_cast<uiBut *>(arg);
|
||||
MenuItemLevel *lvl = static_cast<MenuItemLevel *>(but->func_argN);
|
||||
/* Use the operator properties from the button owning the menu. */
|
||||
IDProperty *op_props = but->opptr ? static_cast<IDProperty *>(but->opptr->data) : nullptr;
|
||||
BLI_assert(but->opptr);
|
||||
IDProperty *op_props = but->opptr->data_as<IDProperty>();
|
||||
|
||||
/* The calling but's str _probably_ contains the active
|
||||
* menu item name, set in uiItemMenuEnumFullO_ptr. */
|
||||
* menu item name, set in #uiLayout::op_menu_enum. */
|
||||
const int active = menu_item_enum_opname_menu_active(C, but, lvl);
|
||||
|
||||
layout->operator_context_set(lvl->opcontext);
|
||||
@@ -3285,13 +3285,11 @@ static void menu_item_enum_opname_menu(bContext *C, uiLayout *layout, void *arg)
|
||||
UI_block_direction_set(layout->block(), UI_DIR_DOWN);
|
||||
}
|
||||
|
||||
void uiItemMenuEnumFullO_ptr(uiLayout *layout,
|
||||
const bContext *C,
|
||||
wmOperatorType *ot,
|
||||
const StringRefNull propname,
|
||||
std::optional<StringRefNull> name,
|
||||
int icon,
|
||||
PointerRNA *r_opptr)
|
||||
PointerRNA uiLayout::op_menu_enum(const bContext *C,
|
||||
wmOperatorType *ot,
|
||||
const StringRefNull propname,
|
||||
std::optional<StringRefNull> name,
|
||||
int icon)
|
||||
{
|
||||
/* Caller must check */
|
||||
BLI_assert(ot->srna != nullptr);
|
||||
@@ -3302,16 +3300,16 @@ void uiItemMenuEnumFullO_ptr(uiLayout *layout,
|
||||
name = operator_name.c_str();
|
||||
}
|
||||
|
||||
if (layout->root_->type == blender::ui::LayoutType::Menu && !icon) {
|
||||
if (root_->type == blender::ui::LayoutType::Menu && !icon) {
|
||||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
MenuItemLevel *lvl = MEM_new<MenuItemLevel>("MenuItemLevel");
|
||||
STRNCPY(lvl->opname, ot->idname);
|
||||
STRNCPY(lvl->propname, propname.c_str());
|
||||
lvl->opcontext = layout->root_->opcontext;
|
||||
lvl->opcontext = root_->opcontext;
|
||||
|
||||
uiBut *but = ui_item_menu(layout,
|
||||
uiBut *but = ui_item_menu(this,
|
||||
*name,
|
||||
icon,
|
||||
menu_item_enum_opname_menu,
|
||||
@@ -3323,53 +3321,39 @@ void uiItemMenuEnumFullO_ptr(uiLayout *layout,
|
||||
but_func_argN_copy<MenuItemLevel>);
|
||||
/* Use the menu button as owner for the operator properties, which will then be passed to the
|
||||
* individual menu items. */
|
||||
if (r_opptr) {
|
||||
but->opptr = MEM_new<PointerRNA>("uiButOpPtr");
|
||||
WM_operator_properties_create_ptr(but->opptr, ot);
|
||||
BLI_assert(but->opptr->data == nullptr);
|
||||
WM_operator_properties_alloc(&but->opptr, (IDProperty **)&but->opptr->data, ot->idname);
|
||||
*r_opptr = *but->opptr;
|
||||
}
|
||||
but->opptr = MEM_new<PointerRNA>("uiButOpPtr");
|
||||
WM_operator_properties_create_ptr(but->opptr, ot);
|
||||
BLI_assert(but->opptr->data == nullptr);
|
||||
WM_operator_properties_alloc(&but->opptr, (IDProperty **)&but->opptr->data, ot->idname);
|
||||
|
||||
/* add hotkey here, lower UI code can't detect it */
|
||||
if ((layout->block()->flag & UI_BLOCK_LOOP) && (ot->prop && ot->invoke)) {
|
||||
if ((this->block()->flag & UI_BLOCK_LOOP) && (ot->prop && ot->invoke)) {
|
||||
if (std::optional<std::string> shortcut_str = WM_key_event_operator_string(
|
||||
C, ot->idname, layout->root_->opcontext, nullptr, false))
|
||||
C, ot->idname, root_->opcontext, nullptr, false))
|
||||
{
|
||||
ui_but_add_shortcut(but, shortcut_str->c_str(), false);
|
||||
}
|
||||
}
|
||||
return *but->opptr;
|
||||
}
|
||||
|
||||
void uiItemMenuEnumFullO(uiLayout *layout,
|
||||
const bContext *C,
|
||||
const StringRefNull opname,
|
||||
const StringRefNull propname,
|
||||
StringRefNull name,
|
||||
int icon,
|
||||
PointerRNA *r_opptr)
|
||||
PointerRNA uiLayout::op_menu_enum(const bContext *C,
|
||||
const StringRefNull opname,
|
||||
const StringRefNull propname,
|
||||
StringRefNull name,
|
||||
int icon)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false); /* print error next */
|
||||
|
||||
UI_OPERATOR_ERROR_RET(ot, opname.c_str(), return);
|
||||
UI_OPERATOR_ERROR_RET(ot, opname.c_str());
|
||||
|
||||
if (!ot->srna) {
|
||||
ui_item_disabled(layout, opname.c_str());
|
||||
ui_item_disabled(this, opname.c_str());
|
||||
RNA_warning("operator missing srna '%s'", opname.c_str());
|
||||
return;
|
||||
return PointerRNA_NULL;
|
||||
}
|
||||
|
||||
uiItemMenuEnumFullO_ptr(layout, C, ot, propname, name, icon, r_opptr);
|
||||
}
|
||||
|
||||
void uiItemMenuEnumO(uiLayout *layout,
|
||||
const bContext *C,
|
||||
const StringRefNull opname,
|
||||
const StringRefNull propname,
|
||||
StringRefNull name,
|
||||
int icon)
|
||||
{
|
||||
uiItemMenuEnumFullO(layout, C, opname, propname, name, icon, nullptr);
|
||||
return this->op_menu_enum(C, ot, propname, name, icon);
|
||||
}
|
||||
|
||||
static void menu_item_enum_rna_menu(bContext * /*C*/, uiLayout *layout, void *arg)
|
||||
|
||||
@@ -235,8 +235,7 @@ static void screen_user_menu_draw(const bContext *C, Menu *menu)
|
||||
else {
|
||||
/* umi_op->prop could be used to set other properties but it's currently unsupported.
|
||||
*/
|
||||
uiItemMenuEnumFullO_ptr(
|
||||
menu->layout, C, ot, umi_op->op_prop_enum, ui_name, ICON_NONE, nullptr);
|
||||
menu->layout->op_menu_enum(C, ot, umi_op->op_prop_enum, ui_name, ICON_NONE);
|
||||
}
|
||||
is_empty = false;
|
||||
}
|
||||
|
||||
@@ -240,12 +240,11 @@ static void file_panel_asset_catalog_buttons_draw(const bContext *C, Panel *pane
|
||||
bContext *mutable_ctx = CTX_copy(C);
|
||||
if (WM_operator_name_poll(mutable_ctx, "asset.bundle_install")) {
|
||||
col->separator();
|
||||
uiItemMenuEnumO(col,
|
||||
C,
|
||||
"asset.bundle_install",
|
||||
"asset_library_reference",
|
||||
IFACE_("Copy Bundle to Asset Library..."),
|
||||
ICON_IMPORT);
|
||||
col->op_menu_enum(C,
|
||||
"asset.bundle_install",
|
||||
"asset_library_reference",
|
||||
IFACE_("Copy Bundle to Asset Library..."),
|
||||
ICON_IMPORT);
|
||||
}
|
||||
CTX_free(mutable_ctx);
|
||||
}
|
||||
|
||||
@@ -1423,7 +1423,7 @@ static void graph_panel_modifiers(const bContext *C, Panel *panel)
|
||||
/* this is an operator button which calls a 'add modifier' operator...
|
||||
* a menu might be nicer but would be tricky as we need some custom filtering
|
||||
*/
|
||||
uiItemMenuEnumO(row, C, "GRAPH_OT_fmodifier_add", "type", IFACE_("Add Modifier"), ICON_NONE);
|
||||
row->op_menu_enum(C, "GRAPH_OT_fmodifier_add", "type", IFACE_("Add Modifier"), ICON_NONE);
|
||||
|
||||
/* copy/paste (as sub-row) */
|
||||
row = &row->row(true);
|
||||
|
||||
@@ -637,7 +637,7 @@ static void nla_panel_modifiers(const bContext *C, Panel *panel)
|
||||
|
||||
/* FIXME: we need to set the only-active property so that this
|
||||
* will only add modifiers for the active strip (not all selected). */
|
||||
uiItemMenuEnumO(row, C, "NLA_OT_fmodifier_add", "type", IFACE_("Add Modifier"), ICON_NONE);
|
||||
row->op_menu_enum(C, "NLA_OT_fmodifier_add", "type", IFACE_("Add Modifier"), ICON_NONE);
|
||||
|
||||
/* copy/paste (as sub-row) */
|
||||
row = &row->row(true);
|
||||
|
||||
@@ -455,9 +455,7 @@ static PointerRNA rna_uiItemMenuEnumO(uiLayout *layout,
|
||||
std::optional<StringRefNull> text = rna_translate_ui_text(
|
||||
name, text_ctxt, ot->srna, nullptr, translate);
|
||||
|
||||
PointerRNA opptr;
|
||||
uiItemMenuEnumFullO_ptr(layout, C, ot, propname, text, icon, &opptr);
|
||||
return opptr;
|
||||
return layout->op_menu_enum(C, ot, propname, text, icon);
|
||||
}
|
||||
|
||||
static void rna_uiItemL(uiLayout *layout,
|
||||
|
||||
Reference in New Issue
Block a user