From f0467b4615b366f34f0daae81ef717c342e8f520 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 11 Aug 2023 19:11:27 +0200 Subject: [PATCH] Cleanup: Return std::string from operator name and description callbacks With the end goal of simplifying ownership and memory management, and allowing the use of `get_name` in contexts without statically allocated strings, use `std::string` for the return values of these two operator type callbacks instead of `const char *` and `char *`. In the meantime things get uglier in some places. I'd expect `std::string` to be used more in the future elsewhere in Blender though. Pull Request: https://projects.blender.org/blender/blender/pulls/110823 --- .../blender/editors/animation/keyframing.cc | 3 +- source/blender/editors/armature/pose_edit.cc | 10 ++-- .../blender/editors/asset/intern/asset_ops.cc | 15 +++--- .../editors/geometry/node_group_operator.cc | 13 ++--- .../editors/include/ED_select_utils.hh | 4 +- source/blender/editors/interface/interface.cc | 16 +++--- .../interface/interface_context_menu.cc | 2 +- .../editors/interface/interface_layout.cc | 8 ++- .../editors/interface/interface_region_hud.cc | 2 +- .../interface/interface_region_tooltip.cc | 11 ++-- .../interface_template_search_menu.cc | 4 +- .../editors/interface/interface_templates.cc | 2 +- .../blender/editors/mesh/editmesh_select.cc | 21 ++++---- .../editors/object/object_data_transfer.cc | 12 ++--- source/blender/editors/object/object_edit.cc | 10 ++-- .../blender/editors/object/object_modifier.cc | 11 ++-- .../blender/editors/object/object_shapekey.cc | 12 ++--- .../blender/editors/object/object_vgroup.cc | 40 +++++++------- .../blender/editors/render/render_opengl.cc | 14 ++--- source/blender/editors/screen/screen_ops.cc | 6 +-- .../sculpt_paint/paint_vertex_weight_ops.cc | 3 +- .../sculpt_paint/sculpt_filter_color.cc | 2 +- .../editors/space_action/action_edit.cc | 6 ++- .../editors/space_clip/tracking_ops_track.cc | 12 ++--- source/blender/editors/space_file/file_ops.cc | 8 +-- .../blender/editors/space_file/file_panels.cc | 2 +- source/blender/editors/space_file/filesel.cc | 2 +- .../blender/editors/space_graph/graph_edit.cc | 10 ++-- .../editors/space_graph/graph_slider_ops.cc | 8 +-- source/blender/editors/space_node/node_add.cc | 12 ++--- .../editors/space_outliner/outliner_tools.cc | 2 +- .../editors/space_sequencer/sequencer_add.cc | 44 ++++++++-------- source/blender/editors/util/select_utils.cc | 4 +- source/blender/makesrna/intern/rna_wm.cc | 14 ++--- source/blender/makesrna/intern/rna_xr.cc | 4 +- source/blender/windowmanager/CMakeLists.txt | 1 + source/blender/windowmanager/WM_api.hh | 8 +-- source/blender/windowmanager/WM_types.hh | 6 ++- .../windowmanager/intern/wm_dragdrop.cc | 2 +- .../windowmanager/intern/wm_event_system.cc | 3 +- .../blender/windowmanager/intern/wm_files.cc | 52 ++++++++++--------- .../windowmanager/intern/wm_operator_type.cc | 37 ++++++------- .../windowmanager/intern/wm_operators.cc | 7 +-- 43 files changed, 238 insertions(+), 227 deletions(-) diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index 1c3afd72a26..e980f3e6179 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -2118,7 +2118,8 @@ static int insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent * / * to assign shortcuts to arbitrarily named keying sets. See #89560. * These menu items perform the key-frame insertion (not this operator) * hence the #OPERATOR_INTERFACE return. */ - uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); + uiPopupMenu *pup = UI_popup_menu_begin( + C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE); uiLayout *layout = UI_popup_menu_layout(pup); /* Even though `ANIM_OT_keyframe_insert_menu` can show a menu in one line, diff --git a/source/blender/editors/armature/pose_edit.cc b/source/blender/editors/armature/pose_edit.cc index f4171f557bf..2b08f4246fd 100644 --- a/source/blender/editors/armature/pose_edit.cc +++ b/source/blender/editors/armature/pose_edit.cc @@ -432,15 +432,15 @@ static int pose_clear_paths_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static char *pose_clear_paths_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string pose_clear_paths_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { const bool only_selected = RNA_boolean_get(ptr, "only_selected"); if (only_selected) { - return BLI_strdup(TIP_("Clear motion paths of selected bones")); + return TIP_("Clear motion paths of selected bones"); } - return BLI_strdup(TIP_("Clear motion paths of all bones")); + return TIP_("Clear motion paths of all bones"); } void POSE_OT_paths_clear(wmOperatorType *ot) diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc index 02698af3fe4..4cb6ad2eac8 100644 --- a/source/blender/editors/asset/intern/asset_ops.cc +++ b/source/blender/editors/asset/intern/asset_ops.cc @@ -352,18 +352,17 @@ static bool asset_clear_poll(bContext *C) return true; } -static char *asset_clear_get_description(bContext * /*C*/, - wmOperatorType * /*op*/, - PointerRNA *values) +static std::string asset_clear_get_description(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *values) { const bool set_fake_user = RNA_boolean_get(values, "set_fake_user"); if (!set_fake_user) { - return nullptr; + return ""; } - - return BLI_strdup( - TIP_("Delete all asset metadata, turning the selected asset data-blocks back into normal " - "data-blocks, and set Fake User to ensure the data-blocks will still be saved")); + return TIP_( + "Delete all asset metadata, turning the selected asset data-blocks back into normal " + "data-blocks, and set Fake User to ensure the data-blocks will still be saved"); } static void ASSET_OT_clear(wmOperatorType *ot) diff --git a/source/blender/editors/geometry/node_group_operator.cc b/source/blender/editors/geometry/node_group_operator.cc index 09684bf528f..65e096be602 100644 --- a/source/blender/editors/geometry/node_group_operator.cc +++ b/source/blender/editors/geometry/node_group_operator.cc @@ -370,17 +370,18 @@ static int run_node_group_invoke(bContext *C, wmOperator *op, const wmEvent * /* return run_node_group_exec(C, op); } -static char *run_node_group_get_description(bContext *C, wmOperatorType * /*ot*/, PointerRNA *ptr) +static std::string run_node_group_get_description(bContext *C, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { const asset_system::AssetRepresentation *asset = get_asset(*C, *ptr, nullptr); if (!asset) { - return nullptr; + return ""; } - const char *description = asset->get_metadata().description; - if (!description) { - return nullptr; + if (!asset->get_metadata().description) { + return ""; } - return BLI_strdup(description); + return asset->get_metadata().description; } static void add_attribute_search_or_value_buttons(uiLayout *layout, diff --git a/source/blender/editors/include/ED_select_utils.hh b/source/blender/editors/include/ED_select_utils.hh index cbf380e736e..55c214b367e 100644 --- a/source/blender/editors/include/ED_select_utils.hh +++ b/source/blender/editors/include/ED_select_utils.hh @@ -108,5 +108,5 @@ void ED_select_pick_params_from_operator(PointerRNA *ptr, SelectPick_Params *par * Get-name callback for #wmOperatorType.get_name, this is mainly useful so the selection * action is shown in the status-bar. */ -const char *ED_select_pick_get_name(wmOperatorType *ot, PointerRNA *ptr); -const char *ED_select_circle_get_name(wmOperatorType *ot, PointerRNA *ptr); +std::string ED_select_pick_get_name(wmOperatorType *ot, PointerRNA *ptr); +std::string ED_select_circle_get_name(wmOperatorType *ot, PointerRNA *ptr); diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc index 7980a6deed9..b56c59cb8a1 100644 --- a/source/blender/editors/interface/interface.cc +++ b/source/blender/editors/interface/interface.cc @@ -4811,9 +4811,11 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block, short height, const char *tip) { + std::string operator_name; if (!str) { if (ot && ot->srna) { - str = WM_operatortype_name(ot, nullptr); + operator_name = WM_operatortype_name(ot, nullptr); + str = operator_name.c_str(); } else { str = ""; @@ -6661,12 +6663,12 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...) } else if (but->optype) { if (type == BUT_GET_RNA_LABEL) { - tmp = BLI_strdup(WM_operatortype_name(but->optype, opptr)); + tmp = BLI_strdup(WM_operatortype_name(but->optype, opptr).c_str()); } else { bContextStore *previous_ctx = CTX_store_get(C); CTX_store_set(C, but->context); - tmp = WM_operatortype_description(C, but->optype, opptr); + tmp = BLI_strdup(WM_operatortype_description(C, but->optype, opptr).c_str()); CTX_store_set(C, previous_ctx); } } @@ -6693,10 +6695,10 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...) wmOperatorType *ot = UI_but_operatortype_get_from_enum_menu(but, nullptr); if (ot) { if (type == BUT_GET_RNA_LABEL) { - tmp = BLI_strdup(WM_operatortype_name(ot, nullptr)); + tmp = BLI_strdup(WM_operatortype_name(ot, nullptr).c_str()); } else { - tmp = WM_operatortype_description(C, ot, nullptr); + tmp = BLI_strdup(WM_operatortype_description(C, ot, nullptr).c_str()); } } } @@ -6833,10 +6835,10 @@ void UI_but_extra_icon_string_info_get(bContext *C, uiButExtraOpIcon *extra_icon switch (si->type) { case BUT_GET_LABEL: - tmp = BLI_strdup(WM_operatortype_name(optype, opptr)); + tmp = BLI_strdup(WM_operatortype_name(optype, opptr).c_str()); break; case BUT_GET_TIP: - tmp = WM_operatortype_description(C, optype, opptr); + tmp = BLI_strdup(WM_operatortype_description(C, optype, opptr).c_str()); break; case BUT_GET_OP_KEYMAP: { char buf[128]; diff --git a/source/blender/editors/interface/interface_context_menu.cc b/source/blender/editors/interface/interface_context_menu.cc index be6bf010419..40a180ff43d 100644 --- a/source/blender/editors/interface/interface_context_menu.cc +++ b/source/blender/editors/interface/interface_context_menu.cc @@ -423,7 +423,7 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um) } else if ((ot = UI_but_operatortype_get_from_enum_menu(but, &prop))) { ED_screen_user_menu_item_add_operator(&um->items, - WM_operatortype_name(ot, nullptr), + WM_operatortype_name(ot, nullptr).c_str(), ot, nullptr, RNA_property_identifier(prop), diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index b5edfc495f1..75bf5b275d8 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -1219,9 +1219,11 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout, /* Take care to fill 'r_opptr' whatever happens. */ uiBlock *block = layout->root->block; + std::string operator_name; if (!name) { if (ot && ot->srna && (flag & UI_ITEM_R_ICON_ONLY) == 0) { - name = WM_operatortype_name(ot, nullptr); + operator_name = WM_operatortype_name(ot, nullptr); + name = operator_name.c_str(); } else { name = ""; @@ -3608,8 +3610,10 @@ void uiItemMenuEnumFullO_ptr(uiLayout *layout, /* Caller must check */ BLI_assert(ot->srna != nullptr); + std::string operator_name; if (name == nullptr) { - name = WM_operatortype_name(ot, nullptr); + operator_name = WM_operatortype_name(ot, nullptr); + name = operator_name.c_str(); } if (layout->root->type == UI_LAYOUT_MENU && !icon) { diff --git a/source/blender/editors/interface/interface_region_hud.cc b/source/blender/editors/interface/interface_region_hud.cc index 710d7d3f9a1..f6d9334f0e8 100644 --- a/source/blender/editors/interface/interface_region_hud.cc +++ b/source/blender/editors/interface/interface_region_hud.cc @@ -104,7 +104,7 @@ static bool hud_panel_operator_redo_poll(const bContext *C, PanelType * /*pt*/) static void hud_panel_operator_redo_draw_header(const bContext *C, Panel *panel) { wmOperator *op = WM_operator_last_redo(C); - STRNCPY(panel->drawname, WM_operatortype_name(op->type, op->ptr)); + STRNCPY(panel->drawname, WM_operatortype_name(op->type, op->ptr).c_str()); } static void hud_panel_operator_redo_draw(const bContext *C, Panel *panel) diff --git a/source/blender/editors/interface/interface_region_tooltip.cc b/source/blender/editors/interface/interface_region_tooltip.cc index b75661efc85..058e78889f4 100644 --- a/source/blender/editors/interface/interface_region_tooltip.cc +++ b/source/blender/editors/interface/interface_region_tooltip.cc @@ -1052,20 +1052,19 @@ static uiTooltipData *ui_tooltip_data_from_gizmo(bContext *C, wmGizmo *gz) nullptr; if (gzop != nullptr) { /* Description */ - char *info = WM_operatortype_description_or_name(C, gzop->type, &gzop->ptr); + std::string info = WM_operatortype_description_or_name(C, gzop->type, &gzop->ptr); - if (info != nullptr) { - char *text = info; + if (!info.empty()) { + const char *text = info.c_str(); if (gzop_actions[i].prefix != nullptr) { - text = BLI_sprintfN("%s: %s", gzop_actions[i].prefix, info); - MEM_freeN(info); + text = BLI_sprintfN("%s: %s", gzop_actions[i].prefix, info.c_str()); } if (text != nullptr) { uiTooltipField *field = text_field_add( data, uiTooltipFormat::Style::Header, uiTooltipFormat::ColorID::Value, true); - field->text = text; + field->text = BLI_strdup(text); } } diff --git a/source/blender/editors/interface/interface_template_search_menu.cc b/source/blender/editors/interface/interface_template_search_menu.cc index 19f7055c7bb..6950cc0794b 100644 --- a/source/blender/editors/interface/interface_template_search_menu.cc +++ b/source/blender/editors/interface/interface_template_search_menu.cc @@ -168,7 +168,7 @@ static bool menu_items_from_ui_create_item_from_button(MenuSearch_Data *data, MenuSearch_Item *item = nullptr; /* Use override if the name is empty, this can happen with popovers. */ - const char *drawstr_override = nullptr; + std::string drawstr_override = nullptr; const char *drawstr_sep = (but->flag & UI_BUT_HAS_SEP_CHAR) ? strrchr(but->drawstr, UI_SEP_CHAR) : nullptr; @@ -237,7 +237,7 @@ static bool menu_items_from_ui_create_item_from_button(MenuSearch_Data *data, if (item != nullptr) { /* Handle shared settings. */ - if (drawstr_override != nullptr) { + if (!drawstr_override.empty()) { const char *drawstr_suffix = drawstr_sep ? drawstr_sep : ""; std::string drawstr = std::string("(") + drawstr_override + ")" + drawstr_suffix; item->drawstr = strdup_memarena(memarena, drawstr.c_str()); diff --git a/source/blender/editors/interface/interface_templates.cc b/source/blender/editors/interface/interface_templates.cc index 52489051dd0..433826c30f3 100644 --- a/source/blender/editors/interface/interface_templates.cc +++ b/source/blender/editors/interface/interface_templates.cc @@ -2718,7 +2718,7 @@ static eAutoPropButsReturn template_operator_property_buts_draw_single( UI_block_lock_clear(block); if (layout_flags & UI_TEMPLATE_OP_PROPS_SHOW_TITLE) { - uiItemL(layout, WM_operatortype_name(op->type, op->ptr), ICON_NONE); + uiItemL(layout, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE); } /* menu */ diff --git a/source/blender/editors/mesh/editmesh_select.cc b/source/blender/editors/mesh/editmesh_select.cc index 80b0be1163d..866db30e475 100644 --- a/source/blender/editors/mesh/editmesh_select.cc +++ b/source/blender/editors/mesh/editmesh_select.cc @@ -1395,9 +1395,9 @@ static int edbm_select_mode_invoke(bContext *C, wmOperator *op, const wmEvent *e return edbm_select_mode_exec(C, op); } -static char *edbm_select_mode_get_description(bContext * /*C*/, - wmOperatorType * /*op*/, - PointerRNA *values) +static std::string edbm_select_mode_get_description(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *values) { const int type = RNA_enum_get(values, "type"); @@ -1412,19 +1412,18 @@ static char *edbm_select_mode_get_description(bContext * /*C*/, { switch (type) { case SCE_SELECT_VERTEX: - return BLI_strdup(TIP_( - "Vertex select - Shift-Click for multiple modes, Ctrl-Click contracts selection")); + return TIP_( + "Vertex select - Shift-Click for multiple modes, Ctrl-Click contracts selection"); case SCE_SELECT_EDGE: - return BLI_strdup( - TIP_("Edge select - Shift-Click for multiple modes, " - "Ctrl-Click expands/contracts selection depending on the current mode")); + return TIP_( + "Edge select - Shift-Click for multiple modes, " + "Ctrl-Click expands/contracts selection depending on the current mode"); case SCE_SELECT_FACE: - return BLI_strdup( - TIP_("Face select - Shift-Click for multiple modes, Ctrl-Click expands selection")); + return TIP_("Face select - Shift-Click for multiple modes, Ctrl-Click expands selection"); } } - return nullptr; + return ""; } void MESH_OT_select_mode(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_data_transfer.cc b/source/blender/editors/object/object_data_transfer.cc index ace59bdd576..ee62d9e62f6 100644 --- a/source/blender/editors/object/object_data_transfer.cc +++ b/source/blender/editors/object/object_data_transfer.cc @@ -640,18 +640,18 @@ static bool data_transfer_poll_property(const bContext * /*C*/, return true; } -static char *data_transfer_get_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string data_transfer_get_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { const bool reverse_transfer = RNA_boolean_get(ptr, "use_reverse_transfer"); if (reverse_transfer) { - return BLI_strdup(TIP_( - "Transfer data layer(s) (weights, edge sharp, etc.) from selected meshes to active one")); + return TIP_( + "Transfer data layer(s) (weights, edge sharp, etc.) from selected meshes to active one"); } - return nullptr; + return ""; } void OBJECT_OT_data_transfer(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_edit.cc b/source/blender/editors/object/object_edit.cc index c309a238a62..c3771fcd943 100644 --- a/source/blender/editors/object/object_edit.cc +++ b/source/blender/editors/object/object_edit.cc @@ -1513,15 +1513,15 @@ static int object_clear_paths_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static char *object_clear_paths_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string object_clear_paths_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { const bool only_selected = RNA_boolean_get(ptr, "only_selected"); if (only_selected) { - return BLI_strdup(TIP_("Clear motion paths of selected objects")); + return TIP_("Clear motion paths of selected objects"); } - return BLI_strdup(TIP_("Clear motion paths of all objects")); + return TIP_("Clear motion paths of all objects"); } void OBJECT_OT_paths_clear(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index 7ab9f19c754..b86c37c1401 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -1878,17 +1878,16 @@ static int modifier_apply_as_shapekey_invoke(bContext *C, wmOperator *op, const return retval; } -static char *modifier_apply_as_shapekey_get_description(bContext * /*C*/, - wmOperatorType * /*op*/, - PointerRNA *values) +static std::string modifier_apply_as_shapekey_get_description(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *values) { bool keep = RNA_boolean_get(values, "keep_modifier"); - if (keep) { - return BLI_strdup(TIP_("Apply modifier as a new shapekey and keep it in the stack")); + return TIP_("Apply modifier as a new shapekey and keep it in the stack"); } - return nullptr; + return ""; } void OBJECT_OT_modifier_apply_as_shapekey(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_shapekey.cc b/source/blender/editors/object/object_shapekey.cc index 2177829d37d..b81b585d946 100644 --- a/source/blender/editors/object/object_shapekey.cc +++ b/source/blender/editors/object/object_shapekey.cc @@ -339,18 +339,16 @@ static bool shape_key_remove_poll_property(const bContext * /*C*/, return true; } -static char *shape_key_remove_get_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string shape_key_remove_get_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { const bool do_apply_mix = RNA_boolean_get(ptr, "apply_mix"); - if (do_apply_mix) { - return BLI_strdup( - TIP_("Apply current visible shape to the object data, and delete all shape keys")); + return TIP_("Apply current visible shape to the object data, and delete all shape keys"); } - return nullptr; + return ""; } void OBJECT_OT_shape_key_remove(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 75158a568bd..a13de47b151 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -2965,9 +2965,9 @@ static int vertex_group_lock_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static char *vertex_group_lock_description(bContext * /*C*/, - wmOperatorType * /*op*/, - PointerRNA *params) +static std::string vertex_group_lock_description(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *params) { int action = RNA_enum_get(params, "action"); int mask = RNA_enum_get(params, "mask"); @@ -2978,51 +2978,49 @@ static char *vertex_group_lock_description(bContext * /*C*/, case VGROUP_LOCK: switch (mask) { case VGROUP_MASK_ALL: - return BLI_strdup(TIP_("Lock all vertex groups of the active object")); + return TIP_("Lock all vertex groups of the active object"); case VGROUP_MASK_SELECTED: - return BLI_strdup(TIP_("Lock selected vertex groups of the active object")); + return TIP_("Lock selected vertex groups of the active object"); case VGROUP_MASK_UNSELECTED: - return BLI_strdup(TIP_("Lock unselected vertex groups of the active object")); + return TIP_("Lock unselected vertex groups of the active object"); case VGROUP_MASK_INVERT_UNSELECTED: - return BLI_strdup( - TIP_("Lock selected and unlock unselected vertex groups of the active object")); + return TIP_("Lock selected and unlock unselected vertex groups of the active object"); } break; case VGROUP_UNLOCK: switch (mask) { case VGROUP_MASK_ALL: - return BLI_strdup(TIP_("Unlock all vertex groups of the active object")); + return TIP_("Unlock all vertex groups of the active object"); case VGROUP_MASK_SELECTED: - return BLI_strdup(TIP_("Unlock selected vertex groups of the active object")); + return TIP_("Unlock selected vertex groups of the active object"); case VGROUP_MASK_UNSELECTED: - return BLI_strdup(TIP_("Unlock unselected vertex groups of the active object")); + return TIP_("Unlock unselected vertex groups of the active object"); case VGROUP_MASK_INVERT_UNSELECTED: - return BLI_strdup( - TIP_("Unlock selected and lock unselected vertex groups of the active object")); + return TIP_("Unlock selected and lock unselected vertex groups of the active object"); } break; case VGROUP_TOGGLE: switch (mask) { case VGROUP_MASK_ALL: - return BLI_strdup(TIP_("Toggle locks of all vertex groups of the active object")); + return TIP_("Toggle locks of all vertex groups of the active object"); case VGROUP_MASK_SELECTED: - return BLI_strdup(TIP_("Toggle locks of selected vertex groups of the active object")); + return TIP_("Toggle locks of selected vertex groups of the active object"); case VGROUP_MASK_UNSELECTED: - return BLI_strdup(TIP_("Toggle locks of unselected vertex groups of the active object")); + return TIP_("Toggle locks of unselected vertex groups of the active object"); case VGROUP_MASK_INVERT_UNSELECTED: - return BLI_strdup(TIP_( - "Toggle locks of all and invert unselected vertex groups of the active object")); + return TIP_( + "Toggle locks of all and invert unselected vertex groups of the active object"); } break; case VGROUP_INVERT: switch (mask) { case VGROUP_MASK_ALL: - return BLI_strdup(TIP_("Invert locks of all vertex groups of the active object")); + return TIP_("Invert locks of all vertex groups of the active object"); case VGROUP_MASK_SELECTED: case VGROUP_MASK_INVERT_UNSELECTED: - return BLI_strdup(TIP_("Invert locks of selected vertex groups of the active object")); + return TIP_("Invert locks of selected vertex groups of the active object"); case VGROUP_MASK_UNSELECTED: - return BLI_strdup(TIP_("Invert locks of unselected vertex groups of the active object")); + return TIP_("Invert locks of unselected vertex groups of the active object"); } break; default: diff --git a/source/blender/editors/render/render_opengl.cc b/source/blender/editors/render/render_opengl.cc index 5d476702ee0..d51b3afc875 100644 --- a/source/blender/editors/render/render_opengl.cc +++ b/source/blender/editors/render/render_opengl.cc @@ -1302,21 +1302,21 @@ static int screen_opengl_render_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static char *screen_opengl_render_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string screen_opengl_render_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { if (!RNA_boolean_get(ptr, "animation")) { - return nullptr; + return ""; } if (RNA_boolean_get(ptr, "render_keyed_only")) { - return BLI_strdup(TIP_( + return TIP_( "Render the viewport for the animation range of this scene, but only render keyframes of " - "selected objects")); + "selected objects"); } - return BLI_strdup(TIP_("Render the viewport for the animation range of this scene")); + return TIP_("Render the viewport for the animation range of this scene"); } void RENDER_OT_opengl(wmOperatorType *ot) diff --git a/source/blender/editors/screen/screen_ops.cc b/source/blender/editors/screen/screen_ops.cc index b2bedbf2ca5..bbbd02e1c39 100644 --- a/source/blender/editors/screen/screen_ops.cc +++ b/source/blender/editors/screen/screen_ops.cc @@ -3704,7 +3704,7 @@ static int screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent return OPERATOR_CANCELLED; } - uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); + uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE); uiLayout *layout = UI_popup_menu_layout(pup); /* Vertical Split */ @@ -3889,7 +3889,7 @@ static int repeat_history_invoke(bContext *C, wmOperator *op, const wmEvent * /* return OPERATOR_CANCELLED; } - uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); + uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE); uiLayout *layout = UI_popup_menu_layout(pup); wmOperator *lastop; @@ -3899,7 +3899,7 @@ static int repeat_history_invoke(bContext *C, wmOperator *op, const wmEvent * /* { if ((lastop->type->flag & OPTYPE_REGISTER) && WM_operator_repeat_check(C, lastop)) { uiItemIntO(layout, - WM_operatortype_name(lastop->type, lastop->ptr), + WM_operatortype_name(lastop->type, lastop->ptr).c_str(), ICON_NONE, op->type->idname, "index", diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc index 13f75fba998..c1207cbfb19 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc @@ -362,7 +362,8 @@ static int weight_sample_group_invoke(bContext *C, wmOperator *op, const wmEvent return OPERATOR_CANCELLED; } - uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); + uiPopupMenu *pup = UI_popup_menu_begin( + C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE); uiLayout *layout = UI_popup_menu_layout(pup); wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_vertex_group_set_active", false); wmOperatorCallContext opcontext = WM_OP_EXEC_DEFAULT; diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc index 5a4e430bf69..7063105a880 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc @@ -418,7 +418,7 @@ static int sculpt_color_filter_invoke(bContext *C, wmOperator *op, const wmEvent return OPERATOR_RUNNING_MODAL; } -static const char *sculpt_color_filter_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr) +static std::string sculpt_color_filter_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr) { PropertyRNA *prop = RNA_struct_find_property(ptr, "type"); const int value = RNA_property_enum_get(ptr, prop); diff --git a/source/blender/editors/space_action/action_edit.cc b/source/blender/editors/space_action/action_edit.cc index 596dfea8892..fa6ea93f2bf 100644 --- a/source/blender/editors/space_action/action_edit.cc +++ b/source/blender/editors/space_action/action_edit.cc @@ -682,7 +682,9 @@ static int actkeys_paste_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static char *actkeys_paste_description(bContext * /*C*/, wmOperatorType * /*op*/, PointerRNA *ptr) +static std::string actkeys_paste_description(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *ptr) { /* Custom description if the 'flipped' option is used. */ if (RNA_boolean_get(ptr, "flipped")) { @@ -690,7 +692,7 @@ static char *actkeys_paste_description(bContext * /*C*/, wmOperatorType * /*op*/ } /* Use the default description in the other cases. */ - return nullptr; + return ""; } void ACTION_OT_paste(wmOperatorType *ot) diff --git a/source/blender/editors/space_clip/tracking_ops_track.cc b/source/blender/editors/space_clip/tracking_ops_track.cc index 9eefd8b87de..c275e72039a 100644 --- a/source/blender/editors/space_clip/tracking_ops_track.cc +++ b/source/blender/editors/space_clip/tracking_ops_track.cc @@ -390,26 +390,26 @@ static int track_markers_modal(bContext *C, wmOperator * /*op*/, const wmEvent * return OPERATOR_PASS_THROUGH; } -static char *track_markers_desc(bContext * /*C*/, wmOperatorType * /*op*/, PointerRNA *ptr) +static std::string track_markers_desc(bContext * /*C*/, wmOperatorType * /*op*/, PointerRNA *ptr) { const bool backwards = RNA_boolean_get(ptr, "backwards"); const bool sequence = RNA_boolean_get(ptr, "sequence"); if (backwards && sequence) { - return BLI_strdup(TIP_("Track the selected markers backward for the entire clip")); + return TIP_("Track the selected markers backward for the entire clip"); } if (backwards && !sequence) { - return BLI_strdup(TIP_("Track the selected markers backward by one frame")); + return TIP_("Track the selected markers backward by one frame"); } if (!backwards && sequence) { - return BLI_strdup(TIP_("Track the selected markers forward for the entire clip")); + return TIP_("Track the selected markers forward for the entire clip"); } if (!backwards && !sequence) { - return BLI_strdup(TIP_("Track the selected markers forward by one frame")); + return TIP_("Track the selected markers forward by one frame"); } /* Use default description. */ - return nullptr; + return ""; } void CLIP_OT_track_markers(wmOperatorType *ot) diff --git a/source/blender/editors/space_file/file_ops.cc b/source/blender/editors/space_file/file_ops.cc index 751e7c31392..cbe3c787360 100644 --- a/source/blender/editors/space_file/file_ops.cc +++ b/source/blender/editors/space_file/file_ops.cc @@ -1849,13 +1849,13 @@ static int file_external_operation_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } -static char *file_external_operation_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string file_external_operation_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { const char *description = ""; RNA_enum_description(file_external_operation, RNA_enum_get(ptr, "operation"), &description); - return BLI_strdup(description); + return description; } void FILE_OT_external_operation(wmOperatorType *ot) diff --git a/source/blender/editors/space_file/file_panels.cc b/source/blender/editors/space_file/file_panels.cc index 784c2725423..3ab804596d2 100644 --- a/source/blender/editors/space_file/file_panels.cc +++ b/source/blender/editors/space_file/file_panels.cc @@ -56,7 +56,7 @@ static void file_panel_operator_header(const bContext *C, Panel *panel) SpaceFile *sfile = CTX_wm_space_file(C); wmOperator *op = sfile->op; - STRNCPY(panel->drawname, WM_operatortype_name(op->type, op->ptr)); + STRNCPY(panel->drawname, WM_operatortype_name(op->type, op->ptr).c_str()); } static void file_panel_operator(const bContext *C, Panel *panel) diff --git a/source/blender/editors/space_file/filesel.cc b/source/blender/editors/space_file/filesel.cc index 89187f1ab49..89587659160 100644 --- a/source/blender/editors/space_file/filesel.cc +++ b/source/blender/editors/space_file/filesel.cc @@ -172,7 +172,7 @@ static FileSelectParams *fileselect_ensure_updated_file_params(SpaceFile *sfile) const bool is_relative_path = (RNA_struct_find_property(op->ptr, "relative_path") != nullptr); BLI_strncpy_utf8( - params->title, WM_operatortype_name(op->type, op->ptr), sizeof(params->title)); + params->title, WM_operatortype_name(op->type, op->ptr).c_str(), sizeof(params->title)); if ((prop = RNA_struct_find_property(op->ptr, "filemode"))) { params->type = RNA_property_int_get(op->ptr, prop); diff --git a/source/blender/editors/space_graph/graph_edit.cc b/source/blender/editors/space_graph/graph_edit.cc index b59275b2ab6..815d8be57a1 100644 --- a/source/blender/editors/space_graph/graph_edit.cc +++ b/source/blender/editors/space_graph/graph_edit.cc @@ -603,17 +603,17 @@ static int graphkeys_paste_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static char *graphkeys_paste_description(bContext * /*C*/, - wmOperatorType * /*op*/, - PointerRNA *ptr) +static std::string graphkeys_paste_description(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *ptr) { /* Custom description if the 'flipped' option is used. */ if (RNA_boolean_get(ptr, "flipped")) { - return BLI_strdup(TIP_("Paste keyframes from mirrored bones if they exist")); + return TIP_("Paste keyframes from mirrored bones if they exist"); } /* Use the default description in the other cases. */ - return nullptr; + return ""; } void GRAPH_OT_paste(wmOperatorType *ot) diff --git a/source/blender/editors/space_graph/graph_slider_ops.cc b/source/blender/editors/space_graph/graph_slider_ops.cc index cd159751cd5..ee2a2888e63 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.cc +++ b/source/blender/editors/space_graph/graph_slider_ops.cc @@ -539,16 +539,16 @@ static bool decimate_poll_property(const bContext * /*C*/, wmOperator *op, const return true; } -static char *decimate_desc(bContext * /*C*/, wmOperatorType * /*op*/, PointerRNA *ptr) +static std::string decimate_desc(bContext * /*C*/, wmOperatorType * /*op*/, PointerRNA *ptr) { if (RNA_enum_get(ptr, "mode") == DECIM_ERROR) { - return BLI_strdup( - TIP_("Decimate F-Curves by specifying how much they can deviate from the original curve")); + return TIP_( + "Decimate F-Curves by specifying how much they can deviate from the original curve"); } /* Use default description. */ - return nullptr; + return ""; } static const EnumPropertyItem decimate_mode_items[] = { diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc index 229ccee3b71..f77ed99403c 100644 --- a/source/blender/editors/space_node/node_add.cc +++ b/source/blender/editors/space_node/node_add.cc @@ -454,19 +454,19 @@ static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEven return OPERATOR_FINISHED; } -static char *node_add_group_asset_get_description(bContext *C, - wmOperatorType * /*op*/, - PointerRNA * /*values*/) +static std::string node_add_group_asset_get_description(bContext *C, + wmOperatorType * /*op*/, + PointerRNA * /*values*/) { const asset_system::AssetRepresentation *asset = CTX_wm_asset(C); if (!asset) { - return nullptr; + return ""; } const AssetMetaData &asset_data = asset->get_metadata(); if (!asset_data.description) { - return nullptr; + return ""; } - return BLI_strdup(DATA_(asset_data.description)); + return TIP_(asset_data.description); } void NODE_OT_add_group_asset(wmOperatorType *ot) diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc index 03654ccecc3..a03fa14b0dc 100644 --- a/source/blender/editors/space_outliner/outliner_tools.cc +++ b/source/blender/editors/space_outliner/outliner_tools.cc @@ -3611,7 +3611,7 @@ void OUTLINER_OT_data_operation(wmOperatorType *ot) static int outliner_operator_menu(bContext *C, const char *opname) { wmOperatorType *ot = WM_operatortype_find(opname, false); - uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(ot, nullptr), ICON_NONE); + uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(ot, nullptr).c_str(), ICON_NONE); uiLayout *layout = UI_popup_menu_layout(pup); /* set this so the default execution context is the same as submenus */ diff --git a/source/blender/editors/space_sequencer/sequencer_add.cc b/source/blender/editors/space_sequencer/sequencer_add.cc index dd5772d294e..2eee94a85d0 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.cc +++ b/source/blender/editors/space_sequencer/sequencer_add.cc @@ -1482,55 +1482,55 @@ static int sequencer_add_effect_strip_invoke(bContext *C, return sequencer_add_effect_strip_exec(C, op); } -static char *sequencer_add_effect_strip_desc(bContext * /*C*/, - wmOperatorType * /*op*/, - PointerRNA *ptr) +static std::string sequencer_add_effect_strip_desc(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *ptr) { const int type = RNA_enum_get(ptr, "type"); switch (type) { case SEQ_TYPE_CROSS: - return BLI_strdup(TIP_("Add a crossfade transition to the sequencer")); + return TIP_("Add a crossfade transition to the sequencer"); case SEQ_TYPE_ADD: - return BLI_strdup(TIP_("Add an add effect strip to the sequencer")); + return TIP_("Add an add effect strip to the sequencer"); case SEQ_TYPE_SUB: - return BLI_strdup(TIP_("Add a subtract effect strip to the sequencer")); + return TIP_("Add a subtract effect strip to the sequencer"); case SEQ_TYPE_ALPHAOVER: - return BLI_strdup(TIP_("Add an alpha over effect strip to the sequencer")); + return TIP_("Add an alpha over effect strip to the sequencer"); case SEQ_TYPE_ALPHAUNDER: - return BLI_strdup(TIP_("Add an alpha under effect strip to the sequencer")); + return TIP_("Add an alpha under effect strip to the sequencer"); case SEQ_TYPE_GAMCROSS: - return BLI_strdup(TIP_("Add a gamma cross transition to the sequencer")); + return TIP_("Add a gamma cross transition to the sequencer"); case SEQ_TYPE_MUL: - return BLI_strdup(TIP_("Add a multiply effect strip to the sequencer")); + return TIP_("Add a multiply effect strip to the sequencer"); case SEQ_TYPE_OVERDROP: - return BLI_strdup(TIP_("Add an alpha over drop effect strip to the sequencer")); + return TIP_("Add an alpha over drop effect strip to the sequencer"); case SEQ_TYPE_WIPE: - return BLI_strdup(TIP_("Add a wipe transition to the sequencer")); + return TIP_("Add a wipe transition to the sequencer"); case SEQ_TYPE_GLOW: - return BLI_strdup(TIP_("Add a glow effect strip to the sequencer")); + return TIP_("Add a glow effect strip to the sequencer"); case SEQ_TYPE_TRANSFORM: - return BLI_strdup(TIP_("Add a transform effect strip to the sequencer")); + return TIP_("Add a transform effect strip to the sequencer"); case SEQ_TYPE_COLOR: - return BLI_strdup(TIP_("Add a color strip to the sequencer")); + return TIP_("Add a color strip to the sequencer"); case SEQ_TYPE_SPEED: - return BLI_strdup(TIP_("Add a speed effect strip to the sequencer")); + return TIP_("Add a speed effect strip to the sequencer"); case SEQ_TYPE_MULTICAM: - return BLI_strdup(TIP_("Add a multicam selector effect strip to the sequencer")); + return TIP_("Add a multicam selector effect strip to the sequencer"); case SEQ_TYPE_ADJUSTMENT: - return BLI_strdup(TIP_("Add an adjustment layer effect strip to the sequencer")); + return TIP_("Add an adjustment layer effect strip to the sequencer"); case SEQ_TYPE_GAUSSIAN_BLUR: - return BLI_strdup(TIP_("Add a gaussian blur effect strip to the sequencer")); + return TIP_("Add a gaussian blur effect strip to the sequencer"); case SEQ_TYPE_TEXT: - return BLI_strdup(TIP_("Add a text strip to the sequencer")); + return TIP_("Add a text strip to the sequencer"); case SEQ_TYPE_COLORMIX: - return BLI_strdup(TIP_("Add a color mix effect strip to the sequencer")); + return TIP_("Add a color mix effect strip to the sequencer"); default: break; } /* Use default description. */ - return nullptr; + return ""; } void SEQUENCER_OT_effect_strip_add(wmOperatorType *ot) diff --git a/source/blender/editors/util/select_utils.cc b/source/blender/editors/util/select_utils.cc index 75f32cc4053..7deed8f105e 100644 --- a/source/blender/editors/util/select_utils.cc +++ b/source/blender/editors/util/select_utils.cc @@ -160,7 +160,7 @@ void ED_select_pick_params_from_operator(PointerRNA *ptr, SelectPick_Params *par /** \name Operator Naming Callbacks * \{ */ -const char *ED_select_pick_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr) +std::string ED_select_pick_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr) { SelectPick_Params params = {eSelectOp(0)}; ED_select_pick_params_from_operator(ptr, ¶ms); @@ -180,7 +180,7 @@ const char *ED_select_pick_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr) return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select"); } -const char *ED_select_circle_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr) +std::string ED_select_circle_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr) { /* Matches options in #WM_operator_properties_select_operation_simple */ const eSelectOp sel_op = eSelectOp(RNA_enum_get(ptr, "mode")); diff --git a/source/blender/makesrna/intern/rna_wm.cc b/source/blender/makesrna/intern/rna_wm.cc index 2aad425b30b..db266d4ff15 100644 --- a/source/blender/makesrna/intern/rna_wm.cc +++ b/source/blender/makesrna/intern/rna_wm.cc @@ -1267,14 +1267,14 @@ static void rna_wmKeyMapItem_name_get(PointerRNA *ptr, char *value) { wmKeyMapItem *kmi = static_cast(ptr->data); wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1); - strcpy(value, ot ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname); + strcpy(value, ot ? WM_operatortype_name(ot, kmi->ptr).c_str() : kmi->idname); } static int rna_wmKeyMapItem_name_length(PointerRNA *ptr) { wmKeyMapItem *kmi = static_cast(ptr->data); wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1); - return strlen(ot ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname); + return strlen(ot ? WM_operatortype_name(ot, kmi->ptr).c_str() : kmi->idname); } static bool rna_KeyMapItem_userdefined_get(PointerRNA *ptr) @@ -1465,7 +1465,9 @@ static void rna_operator_cancel_cb(bContext *C, wmOperator *op) RNA_parameter_list_free(&list); } -static char *rna_operator_description_cb(bContext *C, wmOperatorType *ot, PointerRNA *prop_ptr) +static std::string rna_operator_description_cb(bContext *C, + wmOperatorType *ot, + PointerRNA *prop_ptr) { extern FunctionRNA rna_Operator_description_func; @@ -1486,11 +1488,11 @@ static char *rna_operator_description_cb(bContext *C, wmOperatorType *ot, Pointe RNA_parameter_get_lookup(&list, "result", &ret); result = (char *)ret; - if (result && result[0]) { - result = BLI_strdup(result); + if (result) { + result = result; } else { - result = nullptr; + result = ""; } RNA_parameter_list_free(&list); diff --git a/source/blender/makesrna/intern/rna_xr.cc b/source/blender/makesrna/intern/rna_xr.cc index 4f9da34918a..eac3fe88fa4 100644 --- a/source/blender/makesrna/intern/rna_xr.cc +++ b/source/blender/makesrna/intern/rna_xr.cc @@ -355,7 +355,7 @@ static void rna_XrActionMapItem_op_name_get(PointerRNA *ptr, char *value) if (ami->op_properties_ptr) { wmOperatorType *ot = WM_operatortype_find(ami->op, 1); if (ot) { - strcpy(value, WM_operatortype_name(ot, ami->op_properties_ptr)); + strcpy(value, WM_operatortype_name(ot, ami->op_properties_ptr).c_str()); return; } } @@ -376,7 +376,7 @@ static int rna_XrActionMapItem_op_name_length(PointerRNA *ptr) if (ami->op_properties_ptr) { wmOperatorType *ot = WM_operatortype_find(ami->op, 1); if (ot) { - return strlen(WM_operatortype_name(ot, ami->op_properties_ptr)); + return strlen(WM_operatortype_name(ot, ami->op_properties_ptr).c_str()); } } return strlen(ami->op); diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index c3c52bcf18a..6a4f29c75af 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -24,6 +24,7 @@ set(INC ../../../intern/clog ../../../intern/ghost ../../../intern/memutil + ../../../extern/fmtlib/include ../bmesh # RNA_prototypes.h diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index d3dda5cda6f..85dd151f221 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -1112,12 +1112,14 @@ wmOperatorType *WM_operatortype_append_macro(const char *idname, int flag); wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char *idname); -const char *WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties); -char *WM_operatortype_description(bContext *C, wmOperatorType *ot, PointerRNA *properties); +std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties); +std::string WM_operatortype_description(bContext *C, wmOperatorType *ot, PointerRNA *properties); /** * Use when we want a label, preferring the description. */ -char *WM_operatortype_description_or_name(bContext *C, wmOperatorType *ot, PointerRNA *properties); +std::string WM_operatortype_description_or_name(bContext *C, + wmOperatorType *ot, + PointerRNA *properties); /* `wm_operator_utils.cc` */ diff --git a/source/blender/windowmanager/WM_types.hh b/source/blender/windowmanager/WM_types.hh index b5898dbc204..76fb2fc246a 100644 --- a/source/blender/windowmanager/WM_types.hh +++ b/source/blender/windowmanager/WM_types.hh @@ -104,6 +104,8 @@ struct wmEvent; struct wmOperator; struct wmWindowManager; +#include + #include "BLI_compiler_attrs.h" #include "BLI_utildefines.h" #include "DNA_listBase.h" @@ -984,14 +986,14 @@ struct wmOperatorType { * The returned string does not need to be freed. * The returned string is expected to be translated if needed. */ - const char *(*get_name)(wmOperatorType *, PointerRNA *); + std::string (*get_name)(wmOperatorType *, PointerRNA *); /** * Return a different description to use in the user interface, based on property values. * The returned string must be freed by the caller, unless NULL. * The returned string is expected to be translated if needed. */ - char *(*get_description)(bContext *C, wmOperatorType *, PointerRNA *); + std::string (*get_description)(bContext *C, wmOperatorType *, PointerRNA *); /** rna for properties */ StructRNA *srna; diff --git a/source/blender/windowmanager/intern/wm_dragdrop.cc b/source/blender/windowmanager/intern/wm_dragdrop.cc index fed0eae88fb..049db0a5cec 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.cc +++ b/source/blender/windowmanager/intern/wm_dragdrop.cc @@ -355,7 +355,7 @@ static char *dropbox_tooltip(bContext *C, wmDrag *drag, const int xy[2], wmDropB tooltip = drop->tooltip(C, drag, xy, drop); } if (!tooltip) { - tooltip = BLI_strdup(WM_operatortype_name(drop->ot, drop->ptr)); + tooltip = BLI_strdup(WM_operatortype_name(drop->ot, drop->ptr).c_str()); } /* XXX Doing translation here might not be ideal, but later we have no more * access to ot (and hence op context)... */ diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index bd3e3815de0..98f3c1a211e 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -6248,7 +6248,8 @@ void WM_window_cursor_keymap_status_refresh(bContext *C, wmWindow *win) } if (kmi) { wmOperatorType *ot = WM_operatortype_find(kmi->idname, false); - const char *name = (ot) ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname; + const std::string operator_name = WM_operatortype_name(ot, kmi->ptr); + const char *name = (ot) ? operator_name.c_str() : kmi->idname; STRNCPY(cd->text[button_index][type_index], name); } } diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index a007b8cb821..15359e1f286 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -28,6 +28,8 @@ # include #endif +#include + #include "MEM_CacheLimiterC-Api.h" #include "MEM_guardedalloc.h" @@ -2873,12 +2875,12 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op) return wm_open_mainfile__open(C, op); } -static char *wm_open_mainfile_description(bContext * /*C*/, - wmOperatorType * /*op*/, - PointerRNA *params) +static std::string wm_open_mainfile_description(bContext * /*C*/, + wmOperatorType * /*op*/, + PointerRNA *params) { if (!RNA_struct_property_is_set(params, "filepath")) { - return nullptr; + return ""; } char filepath[FILE_MAX]; @@ -2886,7 +2888,7 @@ static char *wm_open_mainfile_description(bContext * /*C*/, BLI_stat_t stats; if (BLI_stat(filepath, &stats) == -1) { - return BLI_sprintfN("%s\n\n%s", filepath, TIP_("File Not Found")); + return fmt::format("{}\n\n{}", filepath, TIP_("File Not Found")); } /* Date. */ @@ -2903,13 +2905,13 @@ static char *wm_open_mainfile_description(bContext * /*C*/, char size_str[FILELIST_DIRENTRY_SIZE_LEN]; BLI_filelist_entry_size_to_string(nullptr, uint64_t(stats.st_size), false, size_str); - return BLI_sprintfN("%s\n\n%s: %s %s\n%s: %s", - filepath, - TIP_("Modified"), - date_st, - time_st, - TIP_("Size"), - size_str); + return fmt::format("{}\n\n{}: {} {}\n{}: {}", + filepath, + TIP_("Modified"), + date_st, + time_st, + TIP_("Size"), + size_str); } /* currently fits in a pointer */ @@ -3362,23 +3364,23 @@ static bool wm_save_mainfile_check(bContext * /*C*/, wmOperator *op) return false; } -static const char *wm_save_as_mainfile_get_name(wmOperatorType *ot, PointerRNA *ptr) +static std::string wm_save_as_mainfile_get_name(wmOperatorType *ot, PointerRNA *ptr) { if (RNA_boolean_get(ptr, "copy")) { return CTX_IFACE_(ot->translation_context, "Save Copy"); } - return nullptr; + return ""; } -static char *wm_save_as_mainfile_get_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string wm_save_as_mainfile_get_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { if (RNA_boolean_get(ptr, "copy")) { return BLI_strdup(TIP_( "Save the current file in the desired location but do not make the saved file active")); } - return nullptr; + return ""; } void WM_OT_save_as_mainfile(wmOperatorType *ot) @@ -3458,16 +3460,16 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent * return ret; } -static char *wm_save_mainfile_get_description(bContext * /*C*/, - wmOperatorType * /*ot*/, - PointerRNA *ptr) +static std::string wm_save_mainfile_get_description(bContext * /*C*/, + wmOperatorType * /*ot*/, + PointerRNA *ptr) { if (RNA_boolean_get(ptr, "incremental")) { - return BLI_strdup( - TIP_("Save the current Blender file with a numerically incremented name that does not " - "overwrite any existing files")); + return TIP_( + "Save the current Blender file with a numerically incremented name that does not " + "overwrite any existing files"); } - return nullptr; + return ""; } void WM_OT_save_mainfile(wmOperatorType *ot) diff --git a/source/blender/windowmanager/intern/wm_operator_type.cc b/source/blender/windowmanager/intern/wm_operator_type.cc index 9117ab9d5eb..78d2b51d3de 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.cc +++ b/source/blender/windowmanager/intern/wm_operator_type.cc @@ -573,44 +573,41 @@ static void wm_operatortype_free_macro(wmOperatorType *ot) BLI_freelistN(&ot->macro); } -const char *WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties) +std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties) { - const char *name = nullptr; - + std::string name; if (ot->get_name && properties) { name = ot->get_name(ot, properties); } - return (name && name[0]) ? name : RNA_struct_ui_name(ot->srna); + return name.empty() ? std::string(RNA_struct_ui_name(ot->srna)) : name; } -char *WM_operatortype_description(bContext *C, wmOperatorType *ot, PointerRNA *properties) +std::string WM_operatortype_description(bContext *C, wmOperatorType *ot, PointerRNA *properties) { if (ot->get_description && properties) { - char *description = ot->get_description(C, ot, properties); - - if (description) { - if (description[0]) { - return description; - } - MEM_freeN(description); + std::string description = ot->get_description(C, ot, properties); + if (!description.empty()) { + return description; } } const char *info = RNA_struct_ui_description(ot->srna); if (info && info[0]) { - return BLI_strdup(info); + return info; } - return nullptr; + return ""; } -char *WM_operatortype_description_or_name(bContext *C, wmOperatorType *ot, PointerRNA *properties) +std::string WM_operatortype_description_or_name(bContext *C, + wmOperatorType *ot, + PointerRNA *properties) { - char *text = WM_operatortype_description(C, ot, properties); - if (text == nullptr) { - const char *text_orig = WM_operatortype_name(ot, properties); - if (text_orig != nullptr) { - text = BLI_strdup(text_orig); + std::string text = WM_operatortype_description(C, ot, properties); + if (text.empty()) { + const std::string text_orig = WM_operatortype_name(ot, properties); + if (!text_orig.empty()) { + text = BLI_strdup(text_orig.c_str()); } } return text; diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index faba703de44..0eb2aee932e 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -1048,7 +1048,8 @@ int WM_menu_invoke_ex(bContext *C, wmOperator *op, wmOperatorCallContext opconte return retval; } else { - uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); + uiPopupMenu *pup = UI_popup_menu_begin( + C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE); uiLayout *layout = UI_popup_menu_layout(pup); /* set this so the default execution context is the same as submenus */ uiLayoutSetOperatorContext(layout, opcontext); @@ -1883,7 +1884,7 @@ static int wm_call_menu_exec(bContext *C, wmOperator *op) return UI_popup_menu_invoke(C, idname, op->reports); } -static const char *wm_call_menu_get_name(wmOperatorType *ot, PointerRNA *ptr) +static std::string wm_call_menu_get_name(wmOperatorType *ot, PointerRNA *ptr) { char idname[BKE_ST_MAXNAME]; RNA_string_get(ptr, "name", idname); @@ -1962,7 +1963,7 @@ static int wm_call_panel_exec(bContext *C, wmOperator *op) return UI_popover_panel_invoke(C, idname, keep_open, op->reports); } -static const char *wm_call_panel_get_name(wmOperatorType *ot, PointerRNA *ptr) +static std::string wm_call_panel_get_name(wmOperatorType *ot, PointerRNA *ptr) { char idname[BKE_ST_MAXNAME]; RNA_string_get(ptr, "name", idname);